X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=types%2Ftypes.c;h=a8ead299d2cad665135671a6bc9110c262c4a06e;hb=8fdba45b901de93c40077bf23466f702f2b15bf5;hp=1f93da4e245dba471d27ae5a5b314f905b05079c;hpb=41253107837c6698a01af3133d11762302d8f9e5;p=babeltrace.git diff --git a/types/types.c b/types/types.c index 1f93da4e..a8ead299 100644 --- a/types/types.c +++ b/types/types.c @@ -19,6 +19,7 @@ */ #include +#include #include #include @@ -445,11 +446,50 @@ struct definition_scope * return scope; } -void set_dynamic_definition_scope(struct definition_scope *scope, - GQuark root_name) +/* + * 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, + 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. + */ + definition->index = INT_MAX; } void free_definition_scope(struct definition_scope *scope)