From: Philippe Proulx Date: Mon, 10 Dec 2018 21:19:32 +0000 (-0500) Subject: bt_field_class_*_create(): accept mandatory trace class X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=0e84d7cc68d43956524c6f28d2650349084236f6;p=deliverable%2Fbabeltrace.git bt_field_class_*_create(): accept mandatory trace class This patch makes all the field class creation functions accept a mandatory trace class parameter. This parameter is not used for the moment, but it could serve in the future to control allocation (for example, object pooling), bookkeeping, and validation. Signed-off-by: Philippe Proulx --- diff --git a/include/babeltrace/trace-ir/field-class.h b/include/babeltrace/trace-ir/field-class.h index c770f81ab..df5f87d9c 100644 --- a/include/babeltrace/trace-ir/field-class.h +++ b/include/babeltrace/trace-ir/field-class.h @@ -27,7 +27,7 @@ * http://www.efficios.com/ctf */ -/* For bt_bool, bt_field_class */ +/* For bt_bool, bt_field_class, bt_trace_class */ #include /* @@ -43,9 +43,11 @@ extern "C" { #endif -extern bt_field_class *bt_field_class_unsigned_integer_create(void); +extern bt_field_class *bt_field_class_unsigned_integer_create( + bt_trace_class *trace_class); -extern bt_field_class *bt_field_class_signed_integer_create(void); +extern bt_field_class *bt_field_class_signed_integer_create( + bt_trace_class *trace_class); extern void bt_field_class_integer_set_field_value_range( bt_field_class *field_class, uint64_t size); @@ -54,15 +56,17 @@ extern void bt_field_class_integer_set_preferred_display_base( bt_field_class *field_class, bt_field_class_integer_preferred_display_base base); -extern bt_field_class *bt_field_class_real_create(void); +extern bt_field_class *bt_field_class_real_create(bt_trace_class *trace_class); extern void bt_field_class_real_set_is_single_precision( bt_field_class *field_class, bt_bool is_single_precision); -extern bt_field_class *bt_field_class_unsigned_enumeration_create(void); +extern bt_field_class *bt_field_class_unsigned_enumeration_create( + bt_trace_class *trace_class); -extern bt_field_class *bt_field_class_signed_enumeration_create(void); +extern bt_field_class *bt_field_class_signed_enumeration_create( + bt_trace_class *trace_class); extern bt_field_class_status bt_field_class_unsigned_enumeration_map_range( bt_field_class *field_class, const char *label, @@ -72,18 +76,22 @@ extern bt_field_class_status bt_field_class_signed_enumeration_map_range( bt_field_class *field_class, const char *label, int64_t range_lower, int64_t range_upper); -extern bt_field_class *bt_field_class_string_create(void); +extern bt_field_class *bt_field_class_string_create( + bt_trace_class *trace_class); -extern bt_field_class *bt_field_class_structure_create(void); +extern bt_field_class *bt_field_class_structure_create( + bt_trace_class *trace_class); extern bt_field_class_status bt_field_class_structure_append_member( bt_field_class *struct_field_class, const char *name, bt_field_class *field_class); extern bt_field_class *bt_field_class_static_array_create( + bt_trace_class *trace_class, bt_field_class *elem_field_class, uint64_t length); extern bt_field_class *bt_field_class_dynamic_array_create( + bt_trace_class *trace_class, bt_field_class *elem_field_class); extern bt_field_class_status @@ -91,7 +99,8 @@ bt_field_class_dynamic_array_set_length_field_class( bt_field_class *field_class, bt_field_class *length_field_class); -extern bt_field_class *bt_field_class_variant_create(void); +extern bt_field_class *bt_field_class_variant_create( + bt_trace_class *trace_class); extern bt_field_class_status bt_field_class_variant_set_selector_field_class(bt_field_class *field_class, diff --git a/lib/trace-ir/field-class.c b/lib/trace-ir/field-class.c index eb949bbcb..e0a543402 100644 --- a/lib/trace-ir/field-class.c +++ b/lib/trace-ir/field-class.c @@ -81,10 +81,12 @@ void destroy_integer_field_class(struct bt_object *obj) } static inline -struct bt_field_class *create_integer_field_class(enum bt_field_class_type type) +struct bt_field_class *create_integer_field_class(bt_trace_class *trace_class, + enum bt_field_class_type type) { struct bt_field_class_integer *int_fc = NULL; + BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); BT_LOGD("Creating default integer field class object: type=%s", bt_common_field_class_type_string(type)); int_fc = g_new0(struct bt_field_class_integer, 1); @@ -104,16 +106,17 @@ end: return (void *) int_fc; } -struct bt_field_class * -bt_field_class_unsigned_integer_create(void) +struct bt_field_class *bt_field_class_unsigned_integer_create( + bt_trace_class *trace_class) { - return create_integer_field_class( + return create_integer_field_class(trace_class, BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER); } -struct bt_field_class *bt_field_class_signed_integer_create(void) +struct bt_field_class *bt_field_class_signed_integer_create( + bt_trace_class *trace_class) { - return create_integer_field_class( + return create_integer_field_class(trace_class, BT_FIELD_CLASS_TYPE_SIGNED_INTEGER); } @@ -226,10 +229,11 @@ void destroy_enumeration_field_class(struct bt_object *obj) static struct bt_field_class *create_enumeration_field_class( - enum bt_field_class_type type) + bt_trace_class *trace_class, enum bt_field_class_type type) { struct bt_field_class_enumeration *enum_fc = NULL; + BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); BT_LOGD("Creating default enumeration field class object: type=%s", bt_common_field_class_type_string(type)); enum_fc = g_new0(struct bt_field_class_enumeration, 1); @@ -263,15 +267,17 @@ end: return (void *) enum_fc; } -struct bt_field_class *bt_field_class_unsigned_enumeration_create(void) +struct bt_field_class *bt_field_class_unsigned_enumeration_create( + bt_trace_class *trace_class) { - return create_enumeration_field_class( + return create_enumeration_field_class(trace_class, BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION); } -struct bt_field_class *bt_field_class_signed_enumeration_create(void) +struct bt_field_class *bt_field_class_signed_enumeration_create( + bt_trace_class *trace_class) { - return create_enumeration_field_class( + return create_enumeration_field_class(trace_class, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION); } @@ -583,10 +589,11 @@ void destroy_real_field_class(struct bt_object *obj) g_free(obj); } -struct bt_field_class *bt_field_class_real_create(void) +struct bt_field_class *bt_field_class_real_create(bt_trace_class *trace_class) { struct bt_field_class_real *real_fc = NULL; + BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); BT_LOGD_STR("Creating default real field class object."); real_fc = g_new0(struct bt_field_class_real, 1); if (!real_fc) { @@ -705,11 +712,13 @@ void destroy_structure_field_class(struct bt_object *obj) g_free(obj); } -struct bt_field_class *bt_field_class_structure_create(void) +struct bt_field_class *bt_field_class_structure_create( + bt_trace_class *trace_class) { int ret; struct bt_field_class_structure *struct_fc = NULL; + BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); BT_LOGD_STR("Creating default structure field class object."); struct_fc = g_new0(struct bt_field_class_structure, 1); if (!struct_fc) { @@ -871,11 +880,13 @@ void destroy_variant_field_class(struct bt_object *obj) g_free(fc); } -struct bt_field_class *bt_field_class_variant_create(void) +struct bt_field_class *bt_field_class_variant_create( + bt_trace_class *trace_class) { int ret; struct bt_field_class_variant *var_fc = NULL; + BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); BT_LOGD_STR("Creating default variant field class object."); var_fc = g_new0(struct bt_field_class_variant, 1); if (!var_fc) { @@ -998,11 +1009,12 @@ void destroy_static_array_field_class(struct bt_object *obj) } struct bt_field_class * -bt_field_class_static_array_create(struct bt_field_class *element_fc, - uint64_t length) +bt_field_class_static_array_create(bt_trace_class *trace_class, + struct bt_field_class *element_fc, uint64_t length) { struct bt_field_class_static_array *array_fc = NULL; + BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); BT_ASSERT_PRE_NON_NULL(element_fc, "Element field class"); BT_LOGD_STR("Creating default static array field class object."); array_fc = g_new0(struct bt_field_class_static_array, 1); @@ -1061,10 +1073,12 @@ void destroy_dynamic_array_field_class(struct bt_object *obj) } struct bt_field_class *bt_field_class_dynamic_array_create( + bt_trace_class *trace_class, struct bt_field_class *element_fc) { struct bt_field_class_dynamic_array *array_fc = NULL; + BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); BT_ASSERT_PRE_NON_NULL(element_fc, "Element field class"); BT_LOGD_STR("Creating default dynamic array field class object."); array_fc = g_new0(struct bt_field_class_dynamic_array, 1); @@ -1124,10 +1138,11 @@ void destroy_string_field_class(struct bt_object *obj) g_free(obj); } -struct bt_field_class *bt_field_class_string_create(void) +struct bt_field_class *bt_field_class_string_create(bt_trace_class *trace_class) { struct bt_field_class_string *string_fc = NULL; + BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); BT_LOGD_STR("Creating default string field class object."); string_fc = g_new0(struct bt_field_class_string, 1); if (!string_fc) { diff --git a/plugins/ctf/common/metadata/ctf-meta-translate.c b/plugins/ctf/common/metadata/ctf-meta-translate.c index e16f5be25..e3da926f1 100644 --- a/plugins/ctf/common/metadata/ctf-meta-translate.c +++ b/plugins/ctf/common/metadata/ctf-meta-translate.c @@ -26,7 +26,8 @@ #include "ctf-meta-visitors.h" static inline -bt_field_class *ctf_field_class_to_ir(struct ctf_field_class *fc, +bt_field_class *ctf_field_class_to_ir(bt_trace_class *ir_tc, + struct ctf_field_class *fc, struct ctf_trace_class *tc, struct ctf_stream_class *sc, struct ctf_event_class *ec); @@ -42,15 +43,15 @@ void ctf_field_class_int_set_props(struct ctf_field_class_int *fc, } static inline -bt_field_class *ctf_field_class_int_to_ir( +bt_field_class *ctf_field_class_int_to_ir(bt_trace_class *ir_tc, struct ctf_field_class_int *fc) { bt_field_class *ir_fc; if (fc->is_signed) { - ir_fc = bt_field_class_signed_integer_create(); + ir_fc = bt_field_class_signed_integer_create(ir_tc); } else { - ir_fc = bt_field_class_unsigned_integer_create(); + ir_fc = bt_field_class_unsigned_integer_create(ir_tc); } BT_ASSERT(ir_fc); @@ -59,7 +60,7 @@ bt_field_class *ctf_field_class_int_to_ir( } static inline -bt_field_class *ctf_field_class_enum_to_ir( +bt_field_class *ctf_field_class_enum_to_ir(bt_trace_class *ir_tc, struct ctf_field_class_enum *fc) { int ret; @@ -67,9 +68,9 @@ bt_field_class *ctf_field_class_enum_to_ir( uint64_t i; if (fc->base.is_signed) { - ir_fc = bt_field_class_signed_enumeration_create(); + ir_fc = bt_field_class_signed_enumeration_create(ir_tc); } else { - ir_fc = bt_field_class_unsigned_enumeration_create(); + ir_fc = bt_field_class_unsigned_enumeration_create(ir_tc); } BT_ASSERT(ir_fc); @@ -96,12 +97,12 @@ bt_field_class *ctf_field_class_enum_to_ir( } static inline -bt_field_class *ctf_field_class_float_to_ir( +bt_field_class *ctf_field_class_float_to_ir(bt_trace_class *ir_tc, struct ctf_field_class_float *fc) { bt_field_class *ir_fc; - ir_fc = bt_field_class_real_create(); + ir_fc = bt_field_class_real_create(ir_tc); BT_ASSERT(ir_fc); if (fc->base.size == 32) { @@ -113,26 +114,24 @@ bt_field_class *ctf_field_class_float_to_ir( } static inline -bt_field_class *ctf_field_class_string_to_ir( +bt_field_class *ctf_field_class_string_to_ir(bt_trace_class *ir_tc, struct ctf_field_class_string *fc) { - bt_field_class *ir_fc = - bt_field_class_string_create(); + bt_field_class *ir_fc = bt_field_class_string_create(ir_tc); BT_ASSERT(ir_fc); return ir_fc; } static inline -bt_field_class *ctf_field_class_struct_to_ir( +bt_field_class *ctf_field_class_struct_to_ir(bt_trace_class *ir_tc, struct ctf_field_class_struct *fc, struct ctf_trace_class *tc, struct ctf_stream_class *sc, struct ctf_event_class *ec) { int ret; - bt_field_class *ir_fc = - bt_field_class_structure_create(); + bt_field_class *ir_fc = bt_field_class_structure_create(ir_tc); uint64_t i; BT_ASSERT(ir_fc); @@ -146,7 +145,8 @@ bt_field_class *ctf_field_class_struct_to_ir( continue; } - member_ir_fc = ctf_field_class_to_ir(named_fc->fc, tc, sc, ec); + member_ir_fc = ctf_field_class_to_ir(ir_tc, named_fc->fc, + tc, sc, ec); BT_ASSERT(member_ir_fc); ret = bt_field_class_structure_append_member( ir_fc, named_fc->name->str, member_ir_fc); @@ -158,8 +158,7 @@ bt_field_class *ctf_field_class_struct_to_ir( } static inline -bt_field_class *borrow_ir_ft_from_field_path( - struct ctf_field_path *field_path, +bt_field_class *borrow_ir_ft_from_field_path(struct ctf_field_path *field_path, struct ctf_trace_class *tc, struct ctf_stream_class *sc, struct ctf_event_class *ec) @@ -178,15 +177,14 @@ bt_field_class *borrow_ir_ft_from_field_path( } static inline -bt_field_class *ctf_field_class_variant_to_ir( +bt_field_class *ctf_field_class_variant_to_ir(bt_trace_class *ir_tc, struct ctf_field_class_variant *fc, struct ctf_trace_class *tc, struct ctf_stream_class *sc, struct ctf_event_class *ec) { int ret; - bt_field_class *ir_fc = - bt_field_class_variant_create(); + bt_field_class *ir_fc = bt_field_class_variant_create(ir_tc); uint64_t i; BT_ASSERT(ir_fc); @@ -200,7 +198,8 @@ bt_field_class *ctf_field_class_variant_to_ir( bt_field_class *option_ir_fc; BT_ASSERT(named_fc->fc->in_ir); - option_ir_fc = ctf_field_class_to_ir(named_fc->fc, tc, sc, ec); + option_ir_fc = ctf_field_class_to_ir(ir_tc, named_fc->fc, + tc, sc, ec); BT_ASSERT(option_ir_fc); ret = bt_field_class_variant_append_option( ir_fc, named_fc->name->str, option_ir_fc); @@ -212,7 +211,7 @@ bt_field_class *ctf_field_class_variant_to_ir( } static inline -bt_field_class *ctf_field_class_array_to_ir( +bt_field_class *ctf_field_class_array_to_ir(bt_trace_class *ir_tc, struct ctf_field_class_array *fc, struct ctf_trace_class *tc, struct ctf_stream_class *sc, @@ -222,14 +221,14 @@ bt_field_class *ctf_field_class_array_to_ir( bt_field_class *elem_ir_fc; if (fc->base.is_text) { - ir_fc = bt_field_class_string_create(); + ir_fc = bt_field_class_string_create(ir_tc); BT_ASSERT(ir_fc); goto end; } - elem_ir_fc = ctf_field_class_to_ir(fc->base.elem_fc, tc, sc, ec); + elem_ir_fc = ctf_field_class_to_ir(ir_tc, fc->base.elem_fc, tc, sc, ec); BT_ASSERT(elem_ir_fc); - ir_fc = bt_field_class_static_array_create(elem_ir_fc, + ir_fc = bt_field_class_static_array_create(ir_tc, elem_ir_fc, fc->length); BT_ASSERT(ir_fc); bt_field_class_put_ref(elem_ir_fc); @@ -239,7 +238,7 @@ end: } static inline -bt_field_class *ctf_field_class_sequence_to_ir( +bt_field_class *ctf_field_class_sequence_to_ir(bt_trace_class *ir_tc, struct ctf_field_class_sequence *fc, struct ctf_trace_class *tc, struct ctf_stream_class *sc, @@ -250,14 +249,14 @@ bt_field_class *ctf_field_class_sequence_to_ir( bt_field_class *elem_ir_fc; if (fc->base.is_text) { - ir_fc = bt_field_class_string_create(); + ir_fc = bt_field_class_string_create(ir_tc); BT_ASSERT(ir_fc); goto end; } - elem_ir_fc = ctf_field_class_to_ir(fc->base.elem_fc, tc, sc, ec); + elem_ir_fc = ctf_field_class_to_ir(ir_tc, fc->base.elem_fc, tc, sc, ec); BT_ASSERT(elem_ir_fc); - ir_fc = bt_field_class_dynamic_array_create(elem_ir_fc); + ir_fc = bt_field_class_dynamic_array_create(ir_tc, elem_ir_fc); BT_ASSERT(ir_fc); bt_field_class_put_ref(elem_ir_fc); BT_ASSERT(ir_fc); @@ -271,7 +270,8 @@ end: } static inline -bt_field_class *ctf_field_class_to_ir(struct ctf_field_class *fc, +bt_field_class *ctf_field_class_to_ir(bt_trace_class *ir_tc, + struct ctf_field_class *fc, struct ctf_trace_class *tc, struct ctf_stream_class *sc, struct ctf_event_class *ec) @@ -283,28 +283,32 @@ bt_field_class *ctf_field_class_to_ir(struct ctf_field_class *fc, switch (fc->type) { case CTF_FIELD_CLASS_TYPE_INT: - ir_fc = ctf_field_class_int_to_ir((void *) fc); + ir_fc = ctf_field_class_int_to_ir(ir_tc, (void *) fc); break; case CTF_FIELD_CLASS_TYPE_ENUM: - ir_fc = ctf_field_class_enum_to_ir((void *) fc); + ir_fc = ctf_field_class_enum_to_ir(ir_tc, (void *) fc); break; case CTF_FIELD_CLASS_TYPE_FLOAT: - ir_fc = ctf_field_class_float_to_ir((void *) fc); + ir_fc = ctf_field_class_float_to_ir(ir_tc, (void *) fc); break; case CTF_FIELD_CLASS_TYPE_STRING: - ir_fc = ctf_field_class_string_to_ir((void *) fc); + ir_fc = ctf_field_class_string_to_ir(ir_tc, (void *) fc); break; case CTF_FIELD_CLASS_TYPE_STRUCT: - ir_fc = ctf_field_class_struct_to_ir((void *) fc, tc, sc, ec); + ir_fc = ctf_field_class_struct_to_ir(ir_tc, (void *) fc, + tc, sc, ec); break; case CTF_FIELD_CLASS_TYPE_ARRAY: - ir_fc = ctf_field_class_array_to_ir((void *) fc, tc, sc, ec); + ir_fc = ctf_field_class_array_to_ir(ir_tc, (void *) fc, + tc, sc, ec); break; case CTF_FIELD_CLASS_TYPE_SEQUENCE: - ir_fc = ctf_field_class_sequence_to_ir((void *) fc, tc, sc, ec); + ir_fc = ctf_field_class_sequence_to_ir(ir_tc, (void *) fc, + tc, sc, ec); break; case CTF_FIELD_CLASS_TYPE_VARIANT: - ir_fc = ctf_field_class_variant_to_ir((void *) fc, tc, sc, ec); + ir_fc = ctf_field_class_variant_to_ir(ir_tc, (void *) fc, + tc, sc, ec); break; default: abort(); @@ -336,10 +340,11 @@ end: } static inline -bt_field_class *scope_ctf_field_class_to_ir(struct ctf_field_class *fc, - struct ctf_trace_class *tc, - struct ctf_stream_class *sc, - struct ctf_event_class *ec) +bt_field_class *scope_ctf_field_class_to_ir(bt_trace_class *ir_tc, + struct ctf_field_class *fc, + struct ctf_trace_class *tc, + struct ctf_stream_class *sc, + struct ctf_event_class *ec) { bt_field_class *ir_fc = NULL; @@ -357,7 +362,7 @@ bt_field_class *scope_ctf_field_class_to_ir(struct ctf_field_class *fc, goto end; } - ir_fc = ctf_field_class_to_ir(fc, tc, sc, ec); + ir_fc = ctf_field_class_to_ir(ir_tc, fc, tc, sc, ec); end: return ir_fc; @@ -397,6 +402,7 @@ bt_event_class *ctf_event_class_to_ir(struct ctf_event_class *ec, { int ret; bt_event_class *ir_ec = NULL; + bt_trace_class *ir_tc = bt_stream_class_borrow_trace_class(ir_sc); if (ec->is_translated) { ir_ec = bt_stream_class_borrow_event_class_by_id( @@ -410,7 +416,7 @@ bt_event_class *ctf_event_class_to_ir(struct ctf_event_class *ec, bt_event_class_put_ref(ir_ec); if (ec->spec_context_fc) { - bt_field_class *ir_fc = scope_ctf_field_class_to_ir( + bt_field_class *ir_fc = scope_ctf_field_class_to_ir(ir_tc, ec->spec_context_fc, tc, sc, ec); if (ir_fc) { @@ -422,7 +428,7 @@ bt_event_class *ctf_event_class_to_ir(struct ctf_event_class *ec, } if (ec->payload_fc) { - bt_field_class *ir_fc = scope_ctf_field_class_to_ir( + bt_field_class *ir_fc = scope_ctf_field_class_to_ir(ir_tc, ec->payload_fc, tc, sc, ec); if (ir_fc) { @@ -474,7 +480,7 @@ bt_stream_class *ctf_stream_class_to_ir(struct ctf_stream_class *sc, bt_stream_class_put_ref(ir_sc); if (sc->packet_context_fc) { - bt_field_class *ir_fc = scope_ctf_field_class_to_ir( + bt_field_class *ir_fc = scope_ctf_field_class_to_ir(ir_tc, sc->packet_context_fc, tc, sc, NULL); if (ir_fc) { @@ -486,7 +492,7 @@ bt_stream_class *ctf_stream_class_to_ir(struct ctf_stream_class *sc, } if (sc->event_header_fc) { - bt_field_class *ir_fc = scope_ctf_field_class_to_ir( + bt_field_class *ir_fc = scope_ctf_field_class_to_ir(ir_tc, sc->event_header_fc, tc, sc, NULL); if (ir_fc) { @@ -498,7 +504,7 @@ bt_stream_class *ctf_stream_class_to_ir(struct ctf_stream_class *sc, } if (sc->event_common_context_fc) { - bt_field_class *ir_fc = scope_ctf_field_class_to_ir( + bt_field_class *ir_fc = scope_ctf_field_class_to_ir(ir_tc, sc->event_common_context_fc, tc, sc, NULL); if (ir_fc) { @@ -600,7 +606,7 @@ int ctf_trace_class_to_ir(bt_trace_class *ir_tc, struct ctf_trace_class *tc) } if (tc->packet_header_fc) { - bt_field_class *ir_fc = scope_ctf_field_class_to_ir( + bt_field_class *ir_fc = scope_ctf_field_class_to_ir(ir_tc, tc->packet_header_fc, tc, NULL, NULL); if (ir_fc) { diff --git a/plugins/text/dmesg/dmesg.c b/plugins/text/dmesg/dmesg.c index 332322b83..1ec86744b 100644 --- a/plugins/text/dmesg/dmesg.c +++ b/plugins/text/dmesg/dmesg.c @@ -79,19 +79,19 @@ struct dmesg_component { }; static -bt_field_class *create_event_payload_fc(void) +bt_field_class *create_event_payload_fc(bt_trace_class *trace_class) { bt_field_class *root_fc = NULL; bt_field_class *fc = NULL; int ret; - root_fc = bt_field_class_structure_create(); + root_fc = bt_field_class_structure_create(trace_class); if (!root_fc) { BT_LOGE_STR("Cannot create an empty structure field class object."); goto error; } - fc = bt_field_class_string_create(); + fc = bt_field_class_string_create(trace_class); if (!fc) { BT_LOGE_STR("Cannot create a string field class object."); goto error; @@ -165,7 +165,7 @@ int create_meta(struct dmesg_component *dmesg_comp, bool has_ts) goto error; } - fc = create_event_payload_fc(); + fc = create_event_payload_fc(dmesg_comp->trace_class); if (!fc) { BT_LOGE_STR("Cannot create event payload field class."); goto error; diff --git a/tests/lib/test_trace_ir_ref.c b/tests/lib/test_trace_ir_ref.c index 71b833b4e..166cddad5 100644 --- a/tests/lib/test_trace_ir_ref.c +++ b/tests/lib/test_trace_ir_ref.c @@ -63,27 +63,27 @@ static const size_t WRITER_USER_NR_ELEMENTS = * - uint16_t payload_16; * - uint32_t payload_32; */ -static bt_field_class *create_integer_struct(void) +static bt_field_class *create_integer_struct(bt_trace_class *trace_class) { int ret; bt_field_class *structure = NULL; bt_field_class *ui8 = NULL, *ui16 = NULL, *ui32 = NULL; - structure = bt_field_class_structure_create(); + structure = bt_field_class_structure_create(trace_class); BT_ASSERT(structure); - ui8 = bt_field_class_unsigned_integer_create(); + ui8 = bt_field_class_unsigned_integer_create(trace_class); BT_ASSERT(ui8); bt_field_class_integer_set_field_value_range(ui8, 8); ret = bt_field_class_structure_append_member(structure, "payload_8", ui8); BT_ASSERT(ret == 0); - ui16 = bt_field_class_unsigned_integer_create(); + ui16 = bt_field_class_unsigned_integer_create(trace_class); BT_ASSERT(ui16); bt_field_class_integer_set_field_value_range(ui16, 16); ret = bt_field_class_structure_append_member(structure, "payload_16", ui16); BT_ASSERT(ret == 0); - ui32 = bt_field_class_unsigned_integer_create(); + ui32 = bt_field_class_unsigned_integer_create(trace_class); BT_ASSERT(ui32); bt_field_class_integer_set_field_value_range(ui32, 32); ret = bt_field_class_structure_append_member(structure, @@ -142,7 +142,7 @@ static bt_event_class *create_simple_event( BT_ASSERT(event); ret = bt_event_class_set_name(event, name); BT_ASSERT(ret == 0); - payload = create_integer_struct(); + payload = create_integer_struct(bt_stream_class_borrow_trace_class(sc)); BT_ASSERT(payload); ret = bt_event_class_set_payload_field_class(event, payload); BT_ASSERT(ret == 0); @@ -160,22 +160,22 @@ static bt_event_class *create_simple_event( * - uint16_t payload_16; * - uint32_t payload_32; */ -static bt_event_class *create_complex_event( - bt_stream_class *sc, +static bt_event_class *create_complex_event(bt_stream_class *sc, const char *name) { int ret; bt_event_class *event = NULL; bt_field_class *inner = NULL, *outer = NULL; + bt_trace_class *trace_class = bt_stream_class_borrow_trace_class(sc); BT_ASSERT(name); event = bt_event_class_create(sc); BT_ASSERT(event); ret = bt_event_class_set_name(event, name); BT_ASSERT(ret == 0); - outer = create_integer_struct(); + outer = create_integer_struct(trace_class); BT_ASSERT(outer); - inner = create_integer_struct(); + inner = create_integer_struct(trace_class); BT_ASSERT(inner); ret = bt_field_class_structure_append_member(outer, "payload_struct", inner); @@ -190,30 +190,32 @@ static bt_event_class *create_complex_event( static void set_stream_class_field_classes( bt_stream_class *stream_class) { + bt_trace_class *trace_class = + bt_stream_class_borrow_trace_class(stream_class); bt_field_class *packet_context_type; bt_field_class *event_header_type; bt_field_class *fc; int ret; - packet_context_type = bt_field_class_structure_create(); + packet_context_type = bt_field_class_structure_create(trace_class); BT_ASSERT(packet_context_type); - fc = bt_field_class_unsigned_integer_create(); + fc = bt_field_class_unsigned_integer_create(trace_class); BT_ASSERT(fc); bt_field_class_integer_set_field_value_range(fc, 32); ret = bt_field_class_structure_append_member(packet_context_type, "packet_size", fc); BT_ASSERT(ret == 0); bt_field_class_put_ref(fc); - fc = bt_field_class_unsigned_integer_create(); + fc = bt_field_class_unsigned_integer_create(trace_class); BT_ASSERT(fc); bt_field_class_integer_set_field_value_range(fc, 32); ret = bt_field_class_structure_append_member(packet_context_type, "content_size", fc); BT_ASSERT(ret == 0); bt_field_class_put_ref(fc); - event_header_type = bt_field_class_structure_create(); + event_header_type = bt_field_class_structure_create(trace_class); BT_ASSERT(event_header_type); - fc = bt_field_class_unsigned_integer_create(); + fc = bt_field_class_unsigned_integer_create(trace_class); BT_ASSERT(fc); bt_field_class_integer_set_field_value_range(fc, 32); ret = bt_field_class_structure_append_member(event_header_type, @@ -278,9 +280,9 @@ static void set_trace_packet_header(bt_trace_class *trace_class) bt_field_class *fc; int ret; - packet_header_type = bt_field_class_structure_create(); + packet_header_type = bt_field_class_structure_create(trace_class); BT_ASSERT(packet_header_type); - fc = bt_field_class_unsigned_integer_create(); + fc = bt_field_class_unsigned_integer_create(trace_class); BT_ASSERT(fc); bt_field_class_integer_set_field_value_range(fc, 32); ret = bt_field_class_structure_append_member(packet_header_type,