From: Jérémie Galarneau Date: Fri, 25 Nov 2016 17:24:42 +0000 (-0500) Subject: Allow NULL (unset) packet, stream and event headers, contexts X-Git-Tag: v2.0.0-pre1~658 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=835b2d10c5c80ebad6427ba3794d712dd44ef145 Allow NULL (unset) packet, stream and event headers, contexts Signed-off-by: Jérémie Galarneau --- diff --git a/formats/ctf/ir/event-class.c b/formats/ctf/ir/event-class.c index fa5756d6..03f20a7e 100644 --- a/formats/ctf/ir/event-class.c +++ b/formats/ctf/ir/event-class.c @@ -355,16 +355,19 @@ int bt_ctf_event_class_set_payload_type(struct bt_ctf_event_class *event_class, { int ret = 0; - if (!event_class || !payload || - bt_ctf_field_type_get_type_id(payload) != - BT_CTF_TYPE_ID_STRUCT) { + if (!event_class) { + ret = -1; + goto end; + } + + if (payload && bt_ctf_field_type_get_type_id(payload) != + BT_CTF_TYPE_ID_STRUCT) { ret = -1; goto end; } - bt_get(payload); bt_put(event_class->fields); - event_class->fields = payload; + event_class->fields = bt_get(payload); end: return ret; } @@ -488,19 +491,19 @@ int bt_ctf_event_class_set_context_type( { int ret = 0; - if (!event_class || !context || event_class->frozen) { + if (!event_class || event_class->frozen) { ret = -1; goto end; } - if (bt_ctf_field_type_get_type_id(context) != BT_CTF_TYPE_ID_STRUCT) { + if (context && bt_ctf_field_type_get_type_id(context) != + BT_CTF_TYPE_ID_STRUCT) { ret = -1; goto end; } - bt_get(context); bt_put(event_class->context); - event_class->context = context; + event_class->context = bt_get(context); end: return ret; diff --git a/formats/ctf/ir/event.c b/formats/ctf/ir/event.c index 01468650..c2178cdb 100644 --- a/formats/ctf/ir/event.c +++ b/formats/ctf/ir/event.c @@ -337,7 +337,7 @@ int bt_ctf_event_set_payload_field(struct bt_ctf_event *event, int ret = 0; struct bt_ctf_field_type *payload_type = NULL; - if (!event || !payload || event->frozen) { + if (!event || event->frozen) { ret = -1; goto end; } @@ -354,10 +354,8 @@ int bt_ctf_event_set_payload_field(struct bt_ctf_event *event, goto end; } - bt_get(payload); bt_put(event->fields_payload); - event->fields_payload = payload; - + event->fields_payload = bt_get(payload); end: bt_put(payload_type); return ret; @@ -420,13 +418,13 @@ int bt_ctf_event_set_header(struct bt_ctf_event *event, struct bt_ctf_field_type *field_type = NULL; struct bt_ctf_stream_class *stream_class = NULL; - if (!event || !header || event->frozen) { + if (!event || event->frozen) { ret = -1; goto end; } stream_class = (struct bt_ctf_stream_class *) bt_object_get_parent( - event->event_class); + event->event_class); /* * Ensure the provided header's type matches the one registered to the * stream class. @@ -438,9 +436,8 @@ int bt_ctf_event_set_header(struct bt_ctf_event *event, goto end; } - bt_get(header); bt_put(event->event_header); - event->event_header = header; + event->event_header = bt_get(header); end: bt_put(stream_class); bt_put(field_type); @@ -468,7 +465,7 @@ int bt_ctf_event_set_event_context(struct bt_ctf_event *event, int ret = 0; struct bt_ctf_field_type *field_type = NULL; - if (!event || !context || event->frozen) { + if (!event || event->frozen) { ret = -1; goto end; } @@ -480,9 +477,8 @@ int bt_ctf_event_set_event_context(struct bt_ctf_event *event, goto end; } - bt_get(context); bt_put(event->context_payload); - event->context_payload = context; + event->context_payload = bt_get(context); end: bt_put(field_type); return ret; @@ -509,7 +505,7 @@ int bt_ctf_event_set_stream_event_context(struct bt_ctf_event *event, struct bt_ctf_field_type *field_type = NULL; struct bt_ctf_stream_class *stream_class = NULL; - if (!event || !stream_event_context || event->frozen) { + if (!event || event->frozen) { ret = -1; goto end; } diff --git a/formats/ctf/ir/stream-class.c b/formats/ctf/ir/stream-class.c index 7bc88223..cf9e58e5 100644 --- a/formats/ctf/ir/stream-class.c +++ b/formats/ctf/ir/stream-class.c @@ -594,18 +594,15 @@ int bt_ctf_stream_class_set_packet_context_type( { int ret = 0; - if (!stream_class || !packet_context_type || stream_class->frozen) { + if (!stream_class || stream_class->frozen) { ret = -1; goto end; } - assert(stream_class->packet_context_type); - if (stream_class->packet_context_type == packet_context_type) { - goto end; - } - if (bt_ctf_field_type_get_type_id(packet_context_type) != - BT_CTF_TYPE_ID_STRUCT) { - /* A packet context must be a structure */ + if (packet_context_type && + bt_ctf_field_type_get_type_id(packet_context_type) != + BT_CTF_TYPE_ID_STRUCT) { + /* A packet context must be a structure. */ ret = -1; goto end; } @@ -639,25 +636,21 @@ int bt_ctf_stream_class_set_event_header_type( { int ret = 0; - if (!stream_class || !event_header_type || stream_class->frozen) { + if (!stream_class || stream_class->frozen) { ret = -1; goto end; } - assert(stream_class->event_header_type); - if (stream_class->event_header_type == event_header_type) { - goto end; - } - if (bt_ctf_field_type_get_type_id(event_header_type) != - BT_CTF_TYPE_ID_STRUCT) { - /* An event header must be a structure */ + if (event_header_type && + bt_ctf_field_type_get_type_id(event_header_type) != + BT_CTF_TYPE_ID_STRUCT) { + /* An event header must be a structure. */ ret = -1; goto end; } bt_put(stream_class->event_header_type); - bt_get(event_header_type); - stream_class->event_header_type = event_header_type; + stream_class->event_header_type = bt_get(event_header_type); end: return ret; } @@ -671,7 +664,6 @@ struct bt_ctf_field_type *bt_ctf_stream_class_get_event_context_type( goto end; } - assert(stream_class->event_context_type); bt_get(stream_class->event_context_type); ret = stream_class->event_context_type; end: @@ -684,21 +676,21 @@ int bt_ctf_stream_class_set_event_context_type( { int ret = 0; - if (!stream_class || !event_context_type || stream_class->frozen) { + if (!stream_class || stream_class->frozen) { ret = -1; goto end; } - if (bt_ctf_field_type_get_type_id(event_context_type) != - BT_CTF_TYPE_ID_STRUCT) { - /* A packet context must be a structure */ + if (event_context_type && + bt_ctf_field_type_get_type_id(event_context_type) != + BT_CTF_TYPE_ID_STRUCT) { + /* A packet context must be a structure. */ ret = -1; goto end; } bt_put(stream_class->event_context_type); - bt_get(event_context_type); - stream_class->event_context_type = event_context_type; + stream_class->event_context_type = bt_get(event_context_type); end: return ret; } diff --git a/formats/ctf/ir/stream.c b/formats/ctf/ir/stream.c index 2f852373..d4dbc447 100644 --- a/formats/ctf/ir/stream.c +++ b/formats/ctf/ir/stream.c @@ -636,7 +636,7 @@ int bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream, int ret = 0; struct bt_ctf_field_type *field_type; - if (!stream || !field || stream->pos.fd < 0) { + if (!stream || stream->pos.fd < 0) { ret = -1; goto end; } @@ -649,9 +649,8 @@ int bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream, } bt_put(field_type); - bt_get(field); bt_put(stream->packet_context); - stream->packet_context = field; + stream->packet_context = bt_get(field); end: return ret; } @@ -680,7 +679,7 @@ int bt_ctf_stream_set_packet_header(struct bt_ctf_stream *stream, struct bt_ctf_trace *trace = NULL; struct bt_ctf_field_type *field_type = NULL; - if (!stream || !field || stream->pos.fd < 0) { + if (!stream || stream->pos.fd < 0) { ret = -1; goto end; } @@ -692,9 +691,8 @@ int bt_ctf_stream_set_packet_header(struct bt_ctf_stream *stream, goto end; } - bt_get(field); bt_put(stream->packet_header); - stream->packet_header = field; + stream->packet_header = bt_get(field); end: BT_PUT(trace); bt_put(field_type); diff --git a/formats/ctf/ir/trace.c b/formats/ctf/ir/trace.c index ee50df6d..dfb81551 100644 --- a/formats/ctf/ir/trace.c +++ b/formats/ctf/ir/trace.c @@ -1073,21 +1073,21 @@ int bt_ctf_trace_set_packet_header_type(struct bt_ctf_trace *trace, { int ret = 0; - if (!trace || !packet_header_type || trace->frozen) { + if (!trace || trace->frozen) { ret = -1; goto end; } - /* packet_header_type must be a structure */ - if (bt_ctf_field_type_get_type_id(packet_header_type) != - BT_CTF_TYPE_ID_STRUCT) { + /* packet_header_type must be a structure. */ + if (packet_header_type && + bt_ctf_field_type_get_type_id(packet_header_type) != + BT_CTF_TYPE_ID_STRUCT) { ret = -1; goto end; } - bt_get(packet_header_type); bt_put(trace->packet_header_type); - trace->packet_header_type = packet_header_type; + trace->packet_header_type = bt_get(packet_header_type); end: return ret; } diff --git a/plugins/ctf/common/metadata/visitor-generate-ir.c b/plugins/ctf/common/metadata/visitor-generate-ir.c index ec406bab..6fcf5754 100644 --- a/plugins/ctf/common/metadata/visitor-generate-ir.c +++ b/plugins/ctf/common/metadata/visitor-generate-ir.c @@ -3163,43 +3163,21 @@ int reset_event_decl_types(struct ctx *ctx, struct bt_ctf_event_class *event_class) { int ret = 0; - _BT_CTF_FIELD_TYPE_INIT(decl); - - /* Event context */ - decl = bt_ctf_field_type_structure_create(); - if (!decl) { - _PERROR("%s", "cannot create initial, empty event context structure"); - ret = -ENOMEM; - goto error; - } - ret = bt_ctf_event_class_set_context_type(event_class, decl); - BT_PUT(decl); + /* Context type. */ + ret = bt_ctf_event_class_set_context_type(event_class, NULL); if (ret) { - _PERROR("%s", "cannot set initial, empty event context structure"); - goto error; - } - - /* Event payload */ - decl = bt_ctf_field_type_structure_create(); - if (!decl) { - _PERROR("%s", "cannot create initial, empty event payload structure"); - ret = -ENOMEM; - goto error; + _PERROR("%s", "cannot set initial NULL event context"); + goto end; } - ret = bt_ctf_event_class_set_payload_type(event_class, decl); - BT_PUT(decl); + /* Event payload. */ + ret = bt_ctf_event_class_set_payload_type(event_class, NULL); if (ret) { - _PERROR("%s", "cannot set initial, empty event payload structure"); - goto error; + _PERROR("%s", "cannot set initial NULL event payload"); + goto end; } - - return 0; - -error: - BT_PUT(decl); - +end: return ret; } @@ -3208,58 +3186,28 @@ int reset_stream_decl_types(struct ctx *ctx, struct bt_ctf_stream_class *stream_class) { int ret = 0; - _BT_CTF_FIELD_TYPE_INIT(decl); - /* Packet context */ - decl = bt_ctf_field_type_structure_create(); - if (!decl) { - _PERROR("%s", "cannot create initial, empty packet context structure"); - ret = -ENOMEM; - goto error; - } - - ret = bt_ctf_stream_class_set_packet_context_type(stream_class, decl); - BT_PUT(decl); + /* Packet context. */ + ret = bt_ctf_stream_class_set_packet_context_type(stream_class, NULL); if (ret) { - _PERROR("%s", "cannot set initial, empty packet context structure"); - goto error; - } - - /* Event header */ - decl = bt_ctf_field_type_structure_create(); - if (!decl) { - _PERROR("%s", "cannot create initial, empty event header structure"); - ret = -ENOMEM; - goto error; + _PERROR("%s", "cannot set initial empty packet context"); + goto end; } - ret = bt_ctf_stream_class_set_event_header_type(stream_class, decl); - BT_PUT(decl); + /* Event header. */ + ret = bt_ctf_stream_class_set_event_header_type(stream_class, NULL); if (ret) { - _PERROR("%s", "cannot set initial, empty event header structure"); - goto error; - } - - /* Event context */ - decl = bt_ctf_field_type_structure_create(); - if (!decl) { - _PERROR("%s", "cannot create initial, empty stream event context structure"); - ret = -ENOMEM; - goto error; + _PERROR("%s", "cannot set initial empty event header"); + goto end; } - ret = bt_ctf_stream_class_set_event_context_type(stream_class, decl); - BT_PUT(decl); + /* Event context. */ + ret = bt_ctf_stream_class_set_event_context_type(stream_class, NULL); if (ret) { - _PERROR("%s", "cannot set initial, empty stream event context structure"); - goto error; + _PERROR("%s", "cannot set initial empty stream event context"); + goto end; } - - return 0; - -error: - BT_PUT(decl); - +end: return ret; } @@ -3276,8 +3224,8 @@ struct bt_ctf_stream_class *create_reset_stream_class(struct ctx *ctx) } /* - * Set packet context, event header, and event context to empty - * structures to override the default ones. + * Set packet context, event header, and event context to NULL to + * override the default ones. */ ret = reset_stream_decl_types(ctx, stream_class); if (ret) { @@ -3322,8 +3270,7 @@ int visit_event_decl(struct ctx *ctx, struct ctf_node *node) event_class = bt_ctf_event_class_create(event_name); /* - * Set context and fields to empty structures to override the - * default ones. + * Unset context and fields to override the default ones. */ ret = reset_event_decl_types(ctx, event_class); if (ret) { @@ -4489,7 +4436,6 @@ int ctf_visitor_generate_ir(FILE *efd, struct ctf_node *node, { int ret = 0; struct ctx *ctx = NULL; - _BT_CTF_FIELD_TYPE_INIT(packet_header_decl); printf_verbose("CTF visitor: AST -> CTF IR...\n"); @@ -4500,19 +4446,8 @@ int ctf_visitor_generate_ir(FILE *efd, struct ctf_node *node, goto error; } - /* Set packet header to an empty struct tu override the default one */ - packet_header_decl = bt_ctf_field_type_structure_create(); - - if (!packet_header_decl) { - _FPERROR(efd, - "%s", - "cannot create initial, empty packet header structure"); - ret = -ENOMEM; - goto error; - } - - ret = bt_ctf_trace_set_packet_header_type(*trace, packet_header_decl); - BT_PUT(packet_header_decl); + /* Set packet header to NULL to override the default one */ + ret = bt_ctf_trace_set_packet_header_type(*trace, NULL); if (ret) { _FPERROR(efd, "%s", @@ -4654,7 +4589,6 @@ int ctf_visitor_generate_ir(FILE *efd, struct ctf_node *node, return ret; error: - BT_PUT(packet_header_decl); ctx_destroy(ctx); BT_PUT(*trace); diff --git a/plugins/ctf/common/notif-iter/notif-iter.c b/plugins/ctf/common/notif-iter/notif-iter.c index 260d15ee..6411dd1f 100644 --- a/plugins/ctf/common/notif-iter/notif-iter.c +++ b/plugins/ctf/common/notif-iter/notif-iter.c @@ -499,8 +499,7 @@ enum bt_ctf_notif_iter_status read_packet_header_begin_state( packet_header_type = bt_ctf_trace_get_packet_header_type( notit->meta.trace); if (!packet_header_type) { - PERR("Failed to retrieve trace's packet header type\n"); - ret = BT_CTF_NOTIF_ITER_STATUS_ERROR; + notit->state = STATE_AFTER_TRACE_PACKET_HEADER; goto end; } @@ -536,7 +535,8 @@ bool is_variant_type(struct bt_ctf_field_type *field_type) } static inline -enum bt_ctf_notif_iter_status set_current_stream_class(struct bt_ctf_notif_iter *notit) +enum bt_ctf_notif_iter_status set_current_stream_class( + struct bt_ctf_notif_iter *notit) { enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK; struct bt_ctf_field_type *packet_header_type; @@ -622,8 +622,7 @@ enum bt_ctf_notif_iter_status read_packet_context_begin_state( packet_context_type = bt_ctf_stream_class_get_packet_context_type( notit->meta.stream_class); if (!packet_context_type) { - PERR("Failed to retrieve stream class's packet context\n"); - status = BT_CTF_NOTIF_ITER_STATUS_ERROR; + notit->state = STATE_AFTER_STREAM_PACKET_CONTEXT; goto end; } @@ -734,8 +733,7 @@ enum bt_ctf_notif_iter_status read_event_header_begin_state( event_header_type = bt_ctf_stream_class_get_event_header_type( notit->meta.stream_class); if (!event_header_type) { - PERR("Failed to retrieve stream class's event header type\n"); - status = BT_CTF_NOTIF_ITER_STATUS_ERROR; + notit->state = STATE_AFTER_STREAM_EVENT_HEADER; goto end; } @@ -913,8 +911,7 @@ enum bt_ctf_notif_iter_status read_stream_event_context_begin_state( stream_event_context_type = bt_ctf_stream_class_get_event_context_type( notit->meta.stream_class); if (!stream_event_context_type) { - PERR("Failed to retrieve stream class's event context type\n"); - status = BT_CTF_NOTIF_ITER_STATUS_ERROR; + notit->state = STATE_DSCOPE_EVENT_CONTEXT_BEGIN; goto end; } @@ -947,11 +944,9 @@ enum bt_ctf_notif_iter_status read_event_context_begin_state( event_context_type = bt_ctf_event_class_get_context_type( notit->meta.event_class); if (!event_context_type) { - PERR("Failed to retrieve event class's context type\n"); - status = BT_CTF_NOTIF_ITER_STATUS_ERROR; + notit->state = STATE_DSCOPE_EVENT_PAYLOAD_BEGIN; goto end; } - status = read_dscope_begin_state(notit, event_context_type, STATE_DSCOPE_EVENT_PAYLOAD_BEGIN, STATE_DSCOPE_EVENT_CONTEXT_CONTINUE, @@ -981,8 +976,7 @@ enum bt_ctf_notif_iter_status read_event_payload_begin_state( event_payload_type = bt_ctf_event_class_get_payload_type( notit->meta.event_class); if (!event_payload_type) { - PERR("Failed to retrieve event class's payload type\n"); - status = BT_CTF_NOTIF_ITER_STATUS_ERROR; + notit->state = STATE_EMIT_NOTIF_EVENT; goto end; }