void bt_ctf_field_type_init(struct bt_ctf_field_type *type)
{
enum ctf_type_id type_id = type->declaration->id;
+ int ret;
assert(type && (type_id > CTF_TYPE_UNKNOWN) &&
(type_id < NR_CTF_TYPES));
bt_ctf_ref_init(&type->ref_count);
type->freeze = type_freeze_funcs[type_id];
type->serialize = type_serialize_funcs[type_id];
- bt_ctf_field_type_set_byte_order(type, BT_CTF_BYTE_ORDER_NATIVE);
+ ret = bt_ctf_field_type_set_byte_order(type, BT_CTF_BYTE_ORDER_NATIVE);
+ assert(!ret);
type->declaration->alignment = 1;
}
struct structure_field *field;
/* Make sure structure does not contain a field of the same name */
- if (g_hash_table_contains(field_name_to_index,
- GUINT_TO_POINTER(name_quark))) {
+ if (g_hash_table_lookup_extended(field_name_to_index,
+ GUINT_TO_POINTER(name_quark), NULL, NULL)) {
ret = -1;
goto end;
}
return ret;
}
+BT_HIDDEN
+int bt_ctf_field_type_validate(struct bt_ctf_field_type *type)
+{
+ int ret = 0;
+
+ if (!type) {
+ ret = -1;
+ goto end;
+ }
+
+ if (type->declaration->id == CTF_TYPE_ENUM) {
+ struct bt_ctf_field_type_enumeration *enumeration =
+ container_of(type, struct bt_ctf_field_type_enumeration,
+ parent);
+
+ ret = enumeration->entries->len ? 0 : -1;
+ }
+end:
+ return ret;
+}
+
struct bt_ctf_field_type *bt_ctf_field_type_integer_create(unsigned int size)
{
struct bt_ctf_field_type_integer *integer =
if (!type || !field_type || type->frozen ||
validate_identifier(field_name) ||
- (type->declaration->id != CTF_TYPE_STRUCT)) {
+ (type->declaration->id != CTF_TYPE_STRUCT) ||
+ bt_ctf_field_type_validate(field_type)) {
goto end;
}
if (!type || !field_type || type->frozen ||
validate_identifier(field_name) ||
- (type->declaration->id != CTF_TYPE_VARIANT)) {
+ (type->declaration->id != CTF_TYPE_VARIANT) ||
+ bt_ctf_field_type_validate(field_type)) {
ret = -1;
goto end;
}
{
struct bt_ctf_field_type_array *array = NULL;
- if (!element_type || length == 0) {
+ if (!element_type || length == 0 ||
+ bt_ctf_field_type_validate(element_type)) {
goto error;
}
{
struct bt_ctf_field_type_sequence *sequence = NULL;
- if (!element_type || validate_identifier(length_field_name)) {
+ if (!element_type || validate_identifier(length_field_name) ||
+ bt_ctf_field_type_validate(element_type)) {
goto error;
}
struct metadata_context *context)
{
size_t entry;
- int ret = 0;
+ int ret;
struct bt_ctf_field_type_enumeration *enumeration = container_of(type,
struct bt_ctf_field_type_enumeration, parent);
+ ret = bt_ctf_field_type_validate(type);
+ if (ret) {
+ goto end;
+ }
+
g_string_append(context->string, "enum : ");
ret = bt_ctf_field_type_serialize(enumeration->container, context);
if (ret) {