summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
d3006d9)
Check that no field with the same name has been defined in the variant.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
fprintf(fd, "[error] %s: unable to find variant field declaration type\n", __func__);
return -EINVAL;
}
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);
untagged_variant_declaration_add_field(untagged_variant_declaration,
g_quark_to_string(field_name),
field_declaration);
struct declaration_field *
untagged_variant_declaration_get_field_from_tag(struct declaration_untagged_variant *untagged_variant_declaration, GQuark tag)
{
struct declaration_field *
untagged_variant_declaration_get_field_from_tag(struct declaration_untagged_variant *untagged_variant_declaration, GQuark tag)
{
+ 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);