Do not use g_quark_from_static_string in unloadable code
authorNathan Lynch <nathan_lynch@mentor.com>
Fri, 5 Aug 2016 19:59:42 +0000 (14:59 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 19 Aug 2016 16:27:55 +0000 (12:27 -0400)
The GLib Quark documentation says that g_quark_from_static_string:

   "... can only be used if the string will continue to exist until the
    program terminates. It can be used with statically allocated
    strings in the main program, but not with statically allocated
    memory in dynamically loaded modules."

https://developer.gnome.org/glib/stable/glib-Quarks.html#g-quark-from-static-string

Convert call sites of g_quark_from_static_string to
g_quark_from_string in code that is potentially unloadable. Call
sites in the babeltrace main program remain unchanged.

Signed-off-by: Nathan Lynch <nathan_lynch@mentor.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/bt-dummy/bt-dummy.c
formats/ctf-metadata/ctf-metadata.c
formats/ctf-text/ctf-text.c
formats/ctf/ctf.c
formats/ctf/metadata/ctf-visitor-generate-io-struct.c
formats/lttng-live/lttng-live-comm.c
formats/lttng-live/lttng-live-plugin.c
lib/debug-info.c
types/enum.c
types/float.c

index 6192e88807570602fe31813f8a3303fa8c8858e4..2f866dc95e3a6cd04e08043fd3576ff8763d56da 100644 (file)
@@ -79,7 +79,7 @@ void __attribute__((constructor)) bt_dummy_init(void)
 {
        int ret;
 
-       bt_dummy_format.name = g_quark_from_static_string("dummy");
+       bt_dummy_format.name = g_quark_from_string("dummy");
        ret = bt_register_format(&bt_dummy_format);
        assert(!ret);
 }
index a5a74c3178db8d8a3c0a7f709563719a5505203b..ff65306f764aed49b3b1d614b0ebf3f30505d693 100644 (file)
@@ -132,7 +132,7 @@ void __attribute__((constructor)) ctf_metadata_init(void)
 {
        int ret;
 
-       ctf_metadata_format.name = g_quark_from_static_string("ctf-metadata");
+       ctf_metadata_format.name = g_quark_from_string("ctf-metadata");
        ret = bt_register_format(&ctf_metadata_format);
        assert(!ret);
 }
index 883a10a8745a551767256d74b57fa87242abe87b..a0b423c2254d4793b5298131a262d4d458b5e478 100644 (file)
@@ -123,12 +123,12 @@ static GQuark Q_STREAM_PACKET_CONTEXT_TIMESTAMP_BEGIN,
 static
 void __attribute__((constructor)) init_quarks(void)
 {
-       Q_STREAM_PACKET_CONTEXT_TIMESTAMP_BEGIN = g_quark_from_static_string("stream.packet.context.timestamp_begin");
-       Q_STREAM_PACKET_CONTEXT_TIMESTAMP_END = g_quark_from_static_string("stream.packet.context.timestamp_end");
-       Q_STREAM_PACKET_CONTEXT_EVENTS_DISCARDED = g_quark_from_static_string("stream.packet.context.events_discarded");
-       Q_STREAM_PACKET_CONTEXT_CONTENT_SIZE = g_quark_from_static_string("stream.packet.context.content_size");
-       Q_STREAM_PACKET_CONTEXT_PACKET_SIZE = g_quark_from_static_string("stream.packet.context.packet_size");
-       Q_STREAM_PACKET_CONTEXT_PACKET_SEQ_NUM = g_quark_from_static_string("stream.packet.context.packet_seq_num");
+       Q_STREAM_PACKET_CONTEXT_TIMESTAMP_BEGIN = g_quark_from_string("stream.packet.context.timestamp_begin");
+       Q_STREAM_PACKET_CONTEXT_TIMESTAMP_END = g_quark_from_string("stream.packet.context.timestamp_end");
+       Q_STREAM_PACKET_CONTEXT_EVENTS_DISCARDED = g_quark_from_string("stream.packet.context.events_discarded");
+       Q_STREAM_PACKET_CONTEXT_CONTENT_SIZE = g_quark_from_string("stream.packet.context.content_size");
+       Q_STREAM_PACKET_CONTEXT_PACKET_SIZE = g_quark_from_string("stream.packet.context.packet_size");
+       Q_STREAM_PACKET_CONTEXT_PACKET_SEQ_NUM = g_quark_from_string("stream.packet.context.packet_seq_num");
 }
 
 static
@@ -605,7 +605,7 @@ void __attribute__((constructor)) ctf_text_init(void)
 {
        int ret;
 
-       ctf_text_format.name = g_quark_from_static_string("text");
+       ctf_text_format.name = g_quark_from_string("text");
        ret = bt_register_format(&ctf_text_format);
        assert(!ret);
 }
index 5578e68d49b52c815465315edf536f716b78c645..9b5302199e17391e0ec73b90d078f44bf0680e27 100644 (file)
@@ -1789,7 +1789,7 @@ begin:
                        fprintf(stderr, "[error] Unable to read packet header: %s\n", strerror(-ret));
                        return ret;
                }
-               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_static_string("magic"));
+               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_string("magic"));
                if (len_index >= 0) {
                        struct bt_definition *field;
                        uint64_t magic;
@@ -1806,7 +1806,7 @@ begin:
                }
 
                /* check uuid */
-               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_static_string("uuid"));
+               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_string("uuid"));
                if (len_index >= 0) {
                        struct definition_array *defarray;
                        struct bt_definition *field;
@@ -1831,7 +1831,7 @@ begin:
                        }
                }
 
-               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_static_string("stream_id"));
+               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.trace_packet_header->declaration, g_quark_from_string("stream_id"));
                if (len_index >= 0) {
                        struct bt_definition *field;
 
@@ -1862,7 +1862,7 @@ begin:
                        return ret;
                }
                /* read packet size from header */
-               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("packet_size"));
+               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_string("packet_size"));
                if (len_index >= 0) {
                        struct bt_definition *field;
 
@@ -1874,7 +1874,7 @@ begin:
                }
 
                /* read content size from header */
-               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("content_size"));
+               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_string("content_size"));
                if (len_index >= 0) {
                        struct bt_definition *field;
 
@@ -1886,7 +1886,7 @@ begin:
                }
 
                /* read timestamp begin from header */
-               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("timestamp_begin"));
+               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_string("timestamp_begin"));
                if (len_index >= 0) {
                        struct bt_definition *field;
 
@@ -1901,7 +1901,7 @@ begin:
                }
 
                /* read timestamp end from header */
-               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("timestamp_end"));
+               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_string("timestamp_end"));
                if (len_index >= 0) {
                        struct bt_definition *field;
 
@@ -1916,7 +1916,7 @@ begin:
                }
 
                /* read events discarded from header */
-               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_static_string("events_discarded"));
+               len_index = bt_struct_declaration_lookup_field_index(file_stream->parent.stream_packet_context->declaration, g_quark_from_string("events_discarded"));
                if (len_index >= 0) {
                        struct bt_definition *field;
 
@@ -1928,7 +1928,7 @@ begin:
                /* read packet_seq_num from header */
                len_index = bt_struct_declaration_lookup_field_index(
                                file_stream->parent.stream_packet_context->declaration,
-                               g_quark_from_static_string("packet_seq_num"));
+                               g_quark_from_string("packet_seq_num"));
                if (len_index >= 0) {
                        struct bt_definition *field;
 
@@ -2848,7 +2848,7 @@ void __attribute__((constructor)) ctf_init(void)
 {
        int ret;
 
-       ctf_format.name = g_quark_from_static_string("ctf");
+       ctf_format.name = g_quark_from_string("ctf");
        ret = bt_register_format(&ctf_format);
        assert(!ret);
 }
index 223d7d07d02f1d7c2c010a0a2724b176dd9c6869..097a482e171891d42f7f0c07aa864fa16a189fd3 100644 (file)
@@ -1114,7 +1114,7 @@ struct bt_declaration *ctf_declaration_enum_visit(FILE *fd, int depth,
                        }
                }
                if (!container_type) {
-                       declaration = bt_lookup_declaration(g_quark_from_static_string("int"),
+                       declaration = bt_lookup_declaration(g_quark_from_string("int"),
                                                         declaration_scope);
                        if (!declaration) {
                                fprintf(fd, "[error] %s: \"int\" type declaration missing for enumeration\n", __func__);
@@ -2075,7 +2075,7 @@ int ctf_stream_visit(FILE *fd, int depth, struct ctf_node *node,
        if (CTF_STREAM_FIELD_IS_SET(stream, stream_id)) {
                /* check that packet header has stream_id field. */
                if (!trace->packet_header_decl
-                   || bt_struct_declaration_lookup_field_index(trace->packet_header_decl, g_quark_from_static_string("stream_id")) < 0) {
+                   || bt_struct_declaration_lookup_field_index(trace->packet_header_decl, g_quark_from_string("stream_id")) < 0) {
                        ret = -EPERM;
                        fprintf(fd, "[error] %s: missing stream_id field in packet header declaration, but stream_id attribute is declared for stream.\n", __func__);
                        goto error;
@@ -2293,7 +2293,7 @@ int ctf_trace_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_trace
        if (!CTF_TRACE_FIELD_IS_SET(trace, byte_order)) {
                /* check that the packet header contains a "magic" field */
                if (!trace->packet_header_decl
-                   || bt_struct_declaration_lookup_field_index(trace->packet_header_decl, g_quark_from_static_string("magic")) < 0) {
+                   || bt_struct_declaration_lookup_field_index(trace->packet_header_decl, g_quark_from_string("magic")) < 0) {
                        ret = -EPERM;
                        fprintf(fd, "[error] %s: missing both byte_order and packet header magic number in trace declaration\n", __func__);
                        goto error;
index 1912b57f5795b2bdbe475f6ff4dcb374b11085e4..cd146d764886d21032dbe4e0dfe8e0e01fc7c385 100644 (file)
@@ -1646,7 +1646,7 @@ int lttng_live_read(struct lttng_live_ctx *ctx)
                goto end;
        }
 
-       fmt_write = bt_lookup_format(g_quark_from_static_string("text"));
+       fmt_write = bt_lookup_format(g_quark_from_string("text"));
        if (!fmt_write) {
                fprintf(stderr, "[error] ctf-text error\n");
                goto end;
index a1fbb9e826efc903009e777a70dc0fd7522004c4..35f0f48a428854412f19fdd68a34bf5c44bec25a 100644 (file)
@@ -332,7 +332,7 @@ void __attribute__((constructor)) lttng_live_init(void)
 {
        int ret;
 
-       lttng_live_format.name = g_quark_from_static_string("lttng-live");
+       lttng_live_format.name = g_quark_from_string("lttng-live");
        ret = bt_register_format(&lttng_live_format);
        assert(!ret);
 }
index 4e1be1e3d6d3b9dad8fe8e9aa1d720e0c0c1e111..eff5134b13e890d8f17c420aedca7fab492d0755 100644 (file)
@@ -66,17 +66,17 @@ struct debug_info {
 static
 int debug_info_init(struct debug_info *info)
 {
-       info->q_statedump_bin_info = g_quark_from_static_string(
+       info->q_statedump_bin_info = g_quark_from_string(
                        "lttng_ust_statedump:bin_info");
-       info->q_statedump_debug_link = g_quark_from_static_string(
+       info->q_statedump_debug_link = g_quark_from_string(
                        "lttng_ust_statedump:debug_link)");
-       info->q_statedump_build_id = g_quark_from_static_string(
+       info->q_statedump_build_id = g_quark_from_string(
                        "lttng_ust_statedump:build_id");
-       info->q_statedump_start = g_quark_from_static_string(
+       info->q_statedump_start = g_quark_from_string(
                        "lttng_ust_statedump:start");
-       info->q_dl_open = g_quark_from_static_string("lttng_ust_dl:dlopen");
-       info->q_lib_load = g_quark_from_static_string("lttng_ust_lib:load");
-       info->q_lib_unload = g_quark_from_static_string("lttng_ust_lib:unload");
+       info->q_dl_open = g_quark_from_string("lttng_ust_dl:dlopen");
+       info->q_lib_load = g_quark_from_string("lttng_ust_lib:load");
+       info->q_lib_unload = g_quark_from_string("lttng_ust_lib:unload");
 
        return bin_info_init();
 }
index 8394e1b35b70b4e2c58b2a9d9ed97d1293eb2c3c..ec10a1695550ed6d5af6ebe32dc6c3b1d1dc7ae6 100644 (file)
@@ -449,7 +449,7 @@ struct bt_definition *
        definition_integer_parent =
                enum_declaration->integer_declaration->p.definition_new(&enum_declaration->integer_declaration->p,
                                _enum->p.scope,
-                               g_quark_from_static_string("container"), 0, NULL);
+                               g_quark_from_string("container"), 0, NULL);
        _enum->integer = container_of(definition_integer_parent,
                                      struct definition_integer, p);
        return &_enum->p;
index 3b61f8faf0a3ec16b0b95b6544cd058cdabd008e..99c2acc7c7d7fdddec96bf1073dc02516b8bf0e8 100644 (file)
@@ -100,23 +100,23 @@ struct bt_definition *
        _float->p.path = bt_new_definition_path(parent_scope, field_name, root_name);
        if (float_declaration->byte_order == LITTLE_ENDIAN) {
                tmp = float_declaration->mantissa->p.definition_new(&float_declaration->mantissa->p,
-                       _float->p.scope, g_quark_from_static_string("mantissa"), 0, NULL);
+                       _float->p.scope, g_quark_from_string("mantissa"), 0, NULL);
                _float->mantissa = container_of(tmp, struct definition_integer, p);
                tmp = float_declaration->exp->p.definition_new(&float_declaration->exp->p,
-                       _float->p.scope, g_quark_from_static_string("exp"), 1, NULL);
+                       _float->p.scope, g_quark_from_string("exp"), 1, NULL);
                _float->exp = container_of(tmp, struct definition_integer, p);
                tmp = float_declaration->sign->p.definition_new(&float_declaration->sign->p,
-                       _float->p.scope, g_quark_from_static_string("sign"), 2, NULL);
+                       _float->p.scope, g_quark_from_string("sign"), 2, NULL);
                _float->sign = container_of(tmp, struct definition_integer, p);
        } else {
                tmp = float_declaration->sign->p.definition_new(&float_declaration->sign->p,
-                       _float->p.scope, g_quark_from_static_string("sign"), 0, NULL);
+                       _float->p.scope, g_quark_from_string("sign"), 0, NULL);
                _float->sign = container_of(tmp, struct definition_integer, p);
                tmp = float_declaration->exp->p.definition_new(&float_declaration->exp->p,
-                       _float->p.scope, g_quark_from_static_string("exp"), 1, NULL);
+                       _float->p.scope, g_quark_from_string("exp"), 1, NULL);
                _float->exp = container_of(tmp, struct definition_integer, p);
                tmp = float_declaration->mantissa->p.definition_new(&float_declaration->mantissa->p,
-                       _float->p.scope, g_quark_from_static_string("mantissa"), 2, NULL);
+                       _float->p.scope, g_quark_from_string("mantissa"), 2, NULL);
                _float->mantissa = container_of(tmp, struct definition_integer, p);
        }
        _float->p.ref = 1;
This page took 0.03185 seconds and 4 git commands to generate.