- /*
- * Freed when type is unregistered.
- */
- float_class = g_new(struct type_class_float, 1);
- float_class->p.name = g_quark_from_string(name);
- float_class->p.alignment = alignment;
- float_class->mantissa_len = mantissa_len;
- float_class->exp_len = exp_len;
- float_class->byte_order = byte_order;
- if (float_class->p.name) {
- ret = ctf_register_type(&float_class->p);
- if (ret) {
- g_free(float_class);
- return NULL;
- }
- }
- return float_class;
+ type_unref(&float_type->exp->p);
+ type_unref(&float_type->mantissa->p);
+ type_unref(&float_type->sign->p);
+ g_free(float_type);
+}
+
+struct type_float *
+ float_type_new(const char *name, size_t mantissa_len,
+ size_t exp_len, int byte_order, size_t alignment)
+{
+ struct type_float *float_type;
+ struct type *type;
+
+ float_type = g_new(struct type_float, 1);
+ type = &float_type->p;
+ type->id = CTF_TYPE_FLOAT;
+ type->name = g_quark_from_string(name);
+ type->alignment = alignment;
+ type->copy = float_copy;
+ type->type_free = _float_type_free;
+ type->definition_new = _float_definition_new;
+ type->definition_free = _float_definition_free;
+ type->ref = 1;
+ float_type->byte_order = byte_order;
+
+ float_type->sign = integer_type_new(NULL, 1,
+ byte_order, false, 1);
+ float_type->mantissa = integer_type_new(NULL, mantissa_len - 1,
+ byte_order, false, 1);
+ float_type->exp = integer_type_new(NULL, exp_len,
+ byte_order, true, 1);
+ return float_type;