X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=types%2Ftypes.c;h=e57624fb707b73225b2400d4b8f29d192e828132;hp=fe1538f0102c6a1824bac0485eef3e2cb8125fed;hb=d00d17d1e06065eb31a699ce59e16ceb6b858029;hpb=6a36ddcab611cb253bc589c61a2ef87a6d033867 diff --git a/types/types.c b/types/types.c index fe1538f0..e57624fb 100644 --- a/types/types.c +++ b/types/types.c @@ -446,12 +446,46 @@ struct definition_scope * return scope; } +/* + * in: path, out: q (GArray of GQuark) + */ +static +void append_scope_path(const char *path, GArray *q) +{ + const char *ptrbegin, *ptrend = path; + GQuark quark; + + for (;;) { + char *str; + size_t len; + + ptrbegin = ptrend; + ptrend = strchr(ptrbegin, '.'); + if (!ptrend) + break; + len = ptrend - ptrbegin; + /* Don't accept two consecutive dots */ + assert(len != 0); + str = g_new(char, len + 1); /* include \0 */ + memcpy(str, ptrbegin, len); + str[len] = '\0'; + quark = g_quark_from_string(str); + g_array_append_val(q, quark); + g_free(str); + } + /* last. Check for trailing dot (and discard). */ + if (ptrbegin[0] != '\0') { + quark = g_quark_from_string(ptrbegin); + g_array_append_val(q, quark); + } +} + void set_dynamic_definition_scope(struct definition *definition, struct definition_scope *scope, - GQuark root_name) + const char *root_name) { - g_array_set_size(scope->scope_path, 1); - g_array_index(scope->scope_path, GQuark, 0) = root_name; + g_array_set_size(scope->scope_path, 0); + append_scope_path(root_name, scope->scope_path); /* * Use INT_MAX order to ensure that all fields of the parent * scope are seen as being prior to this scope.