+ enum_unsigned_insert_range_to_quark(enum_type, start, end, q);
+ }
+
+ array = g_hash_table_lookup(enum_type->table.quark_to_range_set,
+ (gconstpointer) (unsigned long) q);
+ if (!array) {
+ array = g_array_sized_new(FALSE, TRUE,
+ sizeof(struct enum_range), 1);
+ g_hash_table_insert(enum_type->table.quark_to_range_set,
+ (gpointer) (unsigned long) q,
+ array);
+ }
+ g_array_set_size(array, array->len + 1);
+ range = &g_array_index(array, struct enum_range, array->len - 1);
+ range->start._unsigned = start;
+ range->end._unsigned = end;
+}
+
+size_t enum_get_nr_enumerators(struct type_enum *enum_type)
+{
+ return g_hash_table_size(enum_type->table.quark_to_range_set);
+}
+
+void enum_copy(struct stream_pos *dest, const struct format *fdest,
+ struct stream_pos *src, const struct format *fsrc,
+ struct declaration *declaration)
+{
+ struct declaration_enum *_enum =
+ container_of(declaration, struct declaration_enum, p);
+ struct type_enum *enum_type= _enum->type;
+ GArray *array;
+ GQuark v;
+
+ array = fsrc->enum_read(src, enum_type);
+ assert(array);
+ /* unref previous array */
+ if (_enum->value)
+ g_array_unref(_enum->value);
+ _enum->value = array;
+ /*
+ * Arbitrarily choose the first one.
+ * TODO: use direct underlying type read/write intead. Not doing it for
+ * now to test enum read and write code.
+ */
+ v = g_array_index(array, GQuark, 0);
+ return fdest->enum_write(dest, enum_type, v);
+}
+
+static
+void _enum_type_free(struct type *type)
+{
+ struct type_enum *enum_type =
+ container_of(type, struct type_enum, p);
+ struct enum_range_to_quark *iter, *tmp;
+
+ g_hash_table_destroy(enum_type->table.value_to_quark_set);
+ cds_list_for_each_entry_safe(iter, tmp, &enum_type->table.range_to_quark, node) {
+ cds_list_del(&iter->node);
+ g_free(iter);