- struct type_class_variant *variant_class;
- struct type_class *type_class;
- int ret;
-
- variant_class = g_new(struct type_class_variant, 1);
- type_class = &variant_class->p;
- variant_class->fields_by_tag = g_hash_table_new(g_direct_hash,
- g_direct_equal);
- variant_class->fields = g_array_sized_new(FALSE, TRUE,
- sizeof(struct type_class_field),
- DEFAULT_NR_STRUCT_FIELDS);
- type_class->name = g_quark_from_string(name);
- type_class->alignment = 1;
- type_class->copy = variant_copy;
- type_class->class_free = _variant_type_class_free;
- type_class->type_new = _variant_type_new;
- type_class->type_free = _variant_type_free;
- type_class->ref = 1;
-
- if (type_class->name) {
- ret = register_type(type_class);
- if (ret)
- goto error_register;
- }
- return struct_class;
-
-error_register:
- g_hash_table_destroy(variant_class->fields_by_tag);
- g_array_free(variant_class->fields, true);
- g_free(variant_class);
- return NULL;
+ struct type_variant *variant_type;
+ struct type *type;
+
+ variant_type = g_new(struct type_variant, 1);
+ type = &variant_type->p;
+ variant_type->fields_by_tag = g_hash_table_new(g_direct_hash,
+ g_direct_equal);
+ variant_type->fields = g_array_sized_new(FALSE, TRUE,
+ sizeof(struct type_field),
+ DEFAULT_NR_STRUCT_FIELDS);
+ variant_type->scope = new_type_scope(parent_scope);
+ type->id = CTF_TYPE_VARIANT;
+ type->name = g_quark_from_string(name);
+ type->alignment = 1;
+ type->copy = variant_copy;
+ type->type_free = _variant_type_free;
+ type->declaration_new = _variant_declaration_new;
+ type->declaration_free = _variant_declaration_free;
+ type->ref = 1;
+ return variant_type;