X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=types%2Fstruct.c;h=ea2e28c14c29884e5b1faf8551504913d15bbb06;hp=21465c732ba0075af41dce513187bae386a262ee;hb=0f980a3595f61930659e392b1248c59490dd5a22;hpb=05c749e538ebc3a4f6735f62d022655cf92fc17e diff --git a/types/struct.c b/types/struct.c index 21465c73..ea2e28c1 100644 --- a/types/struct.c +++ b/types/struct.c @@ -40,7 +40,8 @@ void struct_copy(struct stream_pos *dest, const struct format *fdest, unsigned long i; fsrc->struct_begin(src, struct_declaration); - fdest->struct_begin(dest, struct_declaration); + if (fdest) + fdest->struct_begin(dest, struct_declaration); for (i = 0; i < _struct->fields->len; i++) { struct field *field = &g_array_index(_struct->fields, @@ -51,7 +52,8 @@ void struct_copy(struct stream_pos *dest, const struct format *fdest, } fsrc->struct_end(src, struct_declaration); - fdest->struct_end(dest, struct_declaration); + if (fdest) + fdest->struct_end(dest, struct_declaration); } static @@ -74,8 +76,8 @@ void _struct_declaration_free(struct declaration *declaration) g_free(struct_declaration); } -struct declaration_struct *struct_declaration_new(const char *name, - struct declaration_scope *parent_scope) +struct declaration_struct * + struct_declaration_new(struct declaration_scope *parent_scope) { struct declaration_struct *struct_declaration; struct declaration *declaration; @@ -89,7 +91,6 @@ struct declaration_struct *struct_declaration_new(const char *name, DEFAULT_NR_STRUCT_FIELDS); struct_declaration->scope = new_declaration_scope(parent_scope); declaration->id = CTF_TYPE_STRUCT; - declaration->name = g_quark_from_string(name); declaration->alignment = 1; declaration->copy = struct_copy; declaration->declaration_free = _struct_declaration_free; @@ -185,15 +186,24 @@ void struct_declaration_add_field(struct declaration_struct *struct_declaration, field_declaration->alignment); } -unsigned long - struct_declaration_lookup_field_index(struct declaration_struct *struct_declaration, +/* + * struct_declaration_lookup_field_index - returns field index + * + * Returns the index of a field in a structure, or -1 if it does not + * exist. + */ +int struct_declaration_lookup_field_index(struct declaration_struct *struct_declaration, GQuark field_name) { - unsigned long index; - - index = (unsigned long) g_hash_table_lookup(struct_declaration->fields_by_name, - (gconstpointer) (unsigned long) field_name); - return index; + gpointer index; + gboolean found; + + found = g_hash_table_lookup_extended(struct_declaration->fields_by_name, + (gconstpointer) (unsigned long) field_name, + NULL, &index); + if (!found) + return -1; + return (int) (unsigned long) index; } /* @@ -201,8 +211,10 @@ unsigned long */ struct declaration_field * struct_declaration_get_field_from_index(struct declaration_struct *struct_declaration, - unsigned long index) + int index) { + if (index < 0) + return NULL; return &g_array_index(struct_declaration->fields, struct declaration_field, index); } @@ -211,7 +223,9 @@ struct declaration_field * */ struct field * struct_definition_get_field_from_index(struct definition_struct *_struct, - unsigned long index) + int index) { + if (index < 0) + return NULL; return &g_array_index(_struct->fields, struct field, index); }