}
bt_ctf_field_type_init(&variant->parent);
+ /* A variant's alignment is undefined */
+ variant->parent.declaration->alignment = 0;
return &variant->parent;
error:
return NULL;
unsigned int alignment)
{
int ret = 0;
+ enum ctf_type_id type_id;
/* Alignment must be bit-aligned (1) or byte aligned */
if (!type || type->frozen || (alignment != 1 && (alignment & 0x7))) {
goto end;
}
+ type_id = bt_ctf_field_type_get_type_id(type);
+ if (type_id == CTF_TYPE_UNKNOWN) {
+ ret = -1;
+ goto end;
+ }
+
if (type->declaration->id == CTF_TYPE_STRING &&
alignment != CHAR_BIT) {
ret = -1;
goto end;
}
+ if (type_id == CTF_TYPE_STRUCT || type_id == CTF_TYPE_VARIANT ||
+ type_id == CTF_TYPE_SEQUENCE || type_id == CTF_TYPE_ARRAY) {
+ /* Setting an alignment on these types makes no sense */
+ ret = -1;
+ goto end;
+ }
+
type->declaration->alignment = alignment;
ret = 0;
end:
return ret;
}
+BT_HIDDEN
+int bt_ctf_field_type_structure_set_field_index(struct bt_ctf_field_type *type,
+ struct bt_ctf_field_type *field, int index)
+{
+ int ret = 0;
+ struct bt_ctf_field_type_structure *structure;
+
+ if (!type || !field || type->frozen ||
+ bt_ctf_field_type_get_type_id(type) != CTF_TYPE_STRUCT) {
+ ret = -1;
+ goto end;
+ }
+
+ structure = container_of(type, struct bt_ctf_field_type_structure,
+ parent);
+ if (index < 0 || index >= structure->fields->len) {
+ ret = -1;
+ goto end;
+ }
+
+ bt_ctf_field_type_get(field);
+ bt_ctf_field_type_put(((struct structure_field *)
+ g_ptr_array_index(structure->fields, index))->type);
+ ((struct structure_field *) structure->fields->pdata[index])->type =
+ field;
+end:
+ return ret;
+}
+
BT_HIDDEN
int bt_ctf_field_type_variant_get_field_name_index(
struct bt_ctf_field_type *type, const char *name)
return ret;
}
+BT_HIDDEN
+int bt_ctf_field_type_variant_set_field_index(struct bt_ctf_field_type *type,
+ struct bt_ctf_field_type *field, int index)
+{
+ int ret = 0;
+ struct bt_ctf_field_type_variant *variant;
+
+ if (!type || !field || type->frozen ||
+ bt_ctf_field_type_get_type_id(type) != CTF_TYPE_VARIANT) {
+ ret = -1;
+ goto end;
+ }
+
+ variant = container_of(type, struct bt_ctf_field_type_variant,
+ parent);
+ if (index < 0 || index >= variant->fields->len) {
+ ret = -1;
+ goto end;
+ }
+
+ bt_ctf_field_type_get(field);
+ bt_ctf_field_type_put(((struct structure_field *)
+ g_ptr_array_index(variant->fields, index))->type);
+ ((struct structure_field *) variant->fields->pdata[index])->type =
+ field;
+end:
+ return ret;
+}
+
static
void bt_ctf_field_type_integer_destroy(struct bt_ctf_ref *ref)
{