X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=types%2Ftypes.c;h=a8ead299d2cad665135671a6bc9110c262c4a06e;hp=fe1538f0102c6a1824bac0485eef3e2cb8125fed;hb=d60cb676b003e5eb83566f9a2707b4dfea005020;hpb=6a36ddcab611cb253bc589c61a2ef87a6d033867 diff --git a/types/types.c b/types/types.c index fe1538f0..a8ead299 100644 --- a/types/types.c +++ b/types/types.c @@ -446,12 +446,45 @@ struct definition_scope * return scope; } +/* + * in: path (dot separated), out: q (GArray of GQuark) + */ +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.