diff options
author | Wim Taymans <wtaymans@redhat.com> | 2017-10-17 12:16:53 +0200 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2017-10-17 12:16:53 +0200 |
commit | b589b7062d1feb5ade581d5a8bd5f161eba9a00e (patch) | |
tree | 299f852e659137efebf9591b44ec4e7740c8cd0a | |
parent | 323c6440843d806c55f2a6942087bdb1a108b0c5 (diff) |
Add support for NULL strings
-rw-r--r-- | spa/include/spa/pod-builder.h | 10 | ||||
-rw-r--r-- | spa/include/spa/pod-parser.h | 6 | ||||
-rw-r--r-- | src/pipewire/introspect.c | 2 | ||||
-rw-r--r-- | src/tools/pipewire-monitor.c | 5 |
4 files changed, 16 insertions, 7 deletions
diff --git a/spa/include/spa/pod-builder.h b/spa/include/spa/pod-builder.h index ce18a631..433b3a67 100644 --- a/spa/include/spa/pod-builder.h +++ b/spa/include/spa/pod-builder.h @@ -401,9 +401,13 @@ do { \ break; \ case 's': \ { \ - char *strval = va_arg(args, char *) ? : ""; \ - size_t len = strlen(strval); \ - spa_pod_builder_string_len(builder, strval, len); \ + char *strval = va_arg(args, char *); \ + if (strval != NULL) { \ + size_t len = strlen(strval); \ + spa_pod_builder_string_len(builder, strval, len); \ + } \ + else \ + spa_pod_builder_none(builder); \ break; \ } \ case 'S': \ diff --git a/spa/include/spa/pod-parser.h b/spa/include/spa/pod-parser.h index 9da39059..a4608876 100644 --- a/spa/include/spa/pod-parser.h +++ b/spa/include/spa/pod-parser.h @@ -56,7 +56,7 @@ static inline bool spa_pod_parser_can_collect(struct spa_pod *pod, char type) switch (SPA_POD_TYPE(pod)) { case SPA_POD_TYPE_NONE: - return type == 'T' || type == 'O' || type == 'V'; + return type == 'T' || type == 'O' || type == 'V' || type == 's'; case SPA_POD_TYPE_BOOL: return type == 'b'; case SPA_POD_TYPE_ID: @@ -116,7 +116,9 @@ do { \ *va_arg(args, double*) = SPA_POD_VALUE(struct spa_pod_double, pod); \ break; \ case 's': \ - *va_arg(args, char**) = SPA_POD_CONTENTS(struct spa_pod_string, pod); \ + *va_arg(args, char**) = \ + (pod == NULL || (SPA_POD_TYPE(pod) == SPA_POD_TYPE_NONE) \ + ? NULL : SPA_POD_CONTENTS(struct spa_pod_string, pod)); \ break; \ case 'S': \ { \ diff --git a/src/pipewire/introspect.c b/src/pipewire/introspect.c index 3877af89..d69d2961 100644 --- a/src/pipewire/introspect.c +++ b/src/pipewire/introspect.c @@ -105,7 +105,7 @@ static struct spa_dict *pw_spa_dict_copy(struct spa_dict *dict) for (i = 0; i < dict->n_items; i++) { items[i].key = strdup(dict->items[i].key); - items[i].value = strdup(dict->items[i].value); + items[i].value = dict->items[i].value ? strdup(dict->items[i].value) : NULL; } return copy; diff --git a/src/tools/pipewire-monitor.c b/src/tools/pipewire-monitor.c index c11bbfe4..3f3a8828 100644 --- a/src/tools/pipewire-monitor.c +++ b/src/tools/pipewire-monitor.c @@ -64,7 +64,10 @@ static void print_properties(struct spa_dict *props, char mark) } spa_dict_for_each(item, props) { - printf("%c\t\t%s = \"%s\"\n", mark, item->key, item->value); + if (item->value) + printf("%c\t\t%s = \"%s\"\n", mark, item->key, item->value); + else + printf("%c\t\t%s = (null)\n", mark, item->key); } } |