Duplicate variant field name check
authorSimon Marchi <simon.marchi@polymtl.ca>
Thu, 14 Jul 2011 13:40:28 +0000 (09:40 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 14 Jul 2011 13:40:28 +0000 (09:40 -0400)
Check that no field with the same name has been defined in the variant.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/metadata/ctf-visitor-generate-io-struct.c
types/variant.c

index 640b8fdff7c1ae6dc5095735328b2224972a1c79..bdb5c68d6cfaa45ec3395fc7ad408eb23ff9792a 100644 (file)
@@ -468,6 +468,13 @@ int ctf_variant_type_declarators_visit(FILE *fd, int depth,
                        fprintf(fd, "[error] %s: unable to find variant field declaration type\n", __func__);
                        return -EINVAL;
                }
+
+               if (untagged_variant_declaration_get_field_from_tag(untagged_variant_declaration, field_name) != NULL) {
+                       fprintf(fd, "[error] %s: duplicate field %s in variant\n", __func__, g_quark_to_string(field_name));
+                       return -EINVAL;
+               }
+
+
                untagged_variant_declaration_add_field(untagged_variant_declaration,
                                              g_quark_to_string(field_name),
                                              field_declaration);
index bb4faa17093a87ec0266f7f08349922037105e1b..1229f582e9f9dd0227826c7690b9aae8b4244e0e 100644 (file)
@@ -273,11 +273,18 @@ void untagged_variant_declaration_add_field(struct declaration_untagged_variant
 struct declaration_field *
 untagged_variant_declaration_get_field_from_tag(struct declaration_untagged_variant *untagged_variant_declaration, GQuark tag)
 {
-       unsigned long index;
+       gpointer index;
+       gboolean found;
 
-       index = (unsigned long) g_hash_table_lookup(untagged_variant_declaration->fields_by_tag,
-                                                   (gconstpointer) (unsigned long) tag);
-       return &g_array_index(untagged_variant_declaration->fields, struct declaration_field, index);
+       found = g_hash_table_lookup_extended(
+                               untagged_variant_declaration->fields_by_tag,
+                               (gconstpointer) (unsigned long) tag, NULL, &index);
+
+       if (!found) {
+               return NULL;
+       }
+
+       return &g_array_index(untagged_variant_declaration->fields, struct declaration_field, (unsigned long)index);
 }
 
 /*
This page took 0.038452 seconds and 4 git commands to generate.