X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=formats%2Fctf%2Fwriter%2Fevent-types.c;h=4ed9fed9942920bff28b6617d6f377d88a0aed93;hb=9ce21c306d5365173e3b138ae35cbe36584462cd;hp=091b3209eff8261d4526de6042ce08f8b933086e;hpb=c4e511dfb2a168ee45764b6f6e6190c400b76b4b;p=babeltrace.git diff --git a/formats/ctf/writer/event-types.c b/formats/ctf/writer/event-types.c index 091b3209..4ed9fed9 100644 --- a/formats/ctf/writer/event-types.c +++ b/formats/ctf/writer/event-types.c @@ -214,8 +214,8 @@ int add_structure_field(GPtrArray *fields, struct structure_field *field; /* Make sure structure does not contain a field of the same name */ - if (g_hash_table_contains(field_name_to_index, - GUINT_TO_POINTER(name_quark))) { + if (g_hash_table_lookup_extended(field_name_to_index, + GUINT_TO_POINTER(name_quark), NULL, NULL)) { ret = -1; goto end; } @@ -238,6 +238,27 @@ end: return ret; } +BT_HIDDEN +int bt_ctf_field_type_validate(struct bt_ctf_field_type *type) +{ + int ret = 0; + + if (!type) { + ret = -1; + goto end; + } + + if (type->declaration->id == CTF_TYPE_ENUM) { + struct bt_ctf_field_type_enumeration *enumeration = + container_of(type, struct bt_ctf_field_type_enumeration, + parent); + + ret = enumeration->entries->len ? 0 : -1; + } +end: + return ret; +} + struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size) { struct bt_ctf_field_type_integer *integer = @@ -517,7 +538,8 @@ int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type *type, if (!type || !field_type || type->frozen || validate_identifier(field_name) || - (type->declaration->id != CTF_TYPE_STRUCT)) { + (type->declaration->id != CTF_TYPE_STRUCT) || + bt_ctf_field_type_validate(field_type)) { goto end; } @@ -579,7 +601,8 @@ int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type *type, if (!type || !field_type || type->frozen || validate_identifier(field_name) || - (type->declaration->id != CTF_TYPE_VARIANT)) { + (type->declaration->id != CTF_TYPE_VARIANT) || + bt_ctf_field_type_validate(field_type)) { ret = -1; goto end; } @@ -611,7 +634,8 @@ struct bt_ctf_field_type *bt_ctf_field_type_array_create( { struct bt_ctf_field_type_array *array = NULL; - if (!element_type || length == 0) { + if (!element_type || length == 0 || + bt_ctf_field_type_validate(element_type)) { goto error; } @@ -639,7 +663,8 @@ struct bt_ctf_field_type *bt_ctf_field_type_sequence_create( { struct bt_ctf_field_type_sequence *sequence = NULL; - if (!element_type || validate_identifier(length_field_name)) { + if (!element_type || validate_identifier(length_field_name) || + bt_ctf_field_type_validate(element_type)) { goto error; } @@ -1154,10 +1179,15 @@ int bt_ctf_field_type_enumeration_serialize(struct bt_ctf_field_type *type, struct metadata_context *context) { size_t entry; - int ret = 0; + int ret; struct bt_ctf_field_type_enumeration *enumeration = container_of(type, struct bt_ctf_field_type_enumeration, parent); + ret = bt_ctf_field_type_validate(type); + if (ret) { + goto end; + } + g_string_append(context->string, "enum : "); ret = bt_ctf_field_type_serialize(enumeration->container, context); if (ret) {