[lttng-dev] [RFC PATCH babeltrace] Use glib portable macros to convert gpointer to int
Jérémie Galarneau
jeremie.galarneau at efficios.com
Fri May 26 13:56:35 UTC 2017
Merged in master, thanks!
Jérémie
On 14 September 2016 at 20:52, Michael Jeanson <mjeanson at efficios.com> wrote:
> ---
> formats/ctf-text/ctf-text.c | 2 +-
> formats/ctf/callbacks.c | 4 ++--
> formats/ctf/events.c | 2 +-
> formats/ctf/ir/field-types.c | 4 ++--
> formats/ctf/metadata/ctf-parser.y | 2 +-
> .../ctf/metadata/ctf-visitor-generate-io-struct.c | 12 ++++++------
> lib/context.c | 4 ++--
> lib/registry.c | 8 ++++----
> lib/trace-collection.c | 8 ++++----
> lib/trace-handle.c | 6 +++---
> lib/values.c | 6 +++---
> types/enum.c | 10 +++++-----
> types/struct.c | 8 ++++----
> types/types.c | 20 ++++++++++----------
> types/variant.c | 12 ++++++------
> 15 files changed, 54 insertions(+), 54 deletions(-)
>
> diff --git a/formats/ctf-text/ctf-text.c b/formats/ctf-text/ctf-text.c
> index f615161..b5da014 100644
> --- a/formats/ctf-text/ctf-text.c
> +++ b/formats/ctf-text/ctf-text.c
> @@ -136,7 +136,7 @@ struct ctf_callsite_dups *ctf_trace_callsite_lookup(struct ctf_trace *trace,
> GQuark callsite_name)
> {
> return g_hash_table_lookup(trace->callsites,
> - (gpointer) (unsigned long) callsite_name);
> + GUINT_TO_POINTER(callsite_name));
> }
>
> void bt_ctf_text_hook(void)
> diff --git a/formats/ctf/callbacks.c b/formats/ctf/callbacks.c
> index 9242a2b..a8c376f 100644
> --- a/formats/ctf/callbacks.c
> +++ b/formats/ctf/callbacks.c
> @@ -115,13 +115,13 @@ int bt_ctf_iter_add_callback(struct bt_ctf_iter *iter,
> if (event) {
> /* find the event id */
> event_id_ptr = g_hash_table_lookup(stream->event_quark_to_id,
> - (gconstpointer) (unsigned long) event);
> + (gconstpointer) GUINT_TO_POINTER(event));
> /* event not found in this stream class */
> if (!event_id_ptr) {
> fprintf(stderr, "[error] Event ID not found in stream class\n");
> continue;
> }
> - event_id = (uint64_t)(unsigned long) *event_id_ptr;
> + event_id = GPOINTER_TO_UINT(*event_id_ptr);
>
> /* find or create the bt_callback_chain for this event */
> if (event_id >= bt_stream_cb->per_id_callbacks->len) {
> diff --git a/formats/ctf/events.c b/formats/ctf/events.c
> index d8e8d5d..0eb688a 100644
> --- a/formats/ctf/events.c
> +++ b/formats/ctf/events.c
> @@ -690,7 +690,7 @@ int bt_ctf_get_event_decl_list(int handle_id, struct bt_context *ctx,
> goto error;
>
> handle = g_hash_table_lookup(ctx->trace_handles,
> - (gpointer) (unsigned long) handle_id);
> + GUINT_TO_POINTER(handle_id));
> if (!handle)
> goto error;
>
> diff --git a/formats/ctf/ir/field-types.c b/formats/ctf/ir/field-types.c
> index f898d5a..4f2bc03 100644
> --- a/formats/ctf/ir/field-types.c
> +++ b/formats/ctf/ir/field-types.c
> @@ -404,8 +404,8 @@ int add_structure_field(GPtrArray *fields,
> field->name = name_quark;
> field->type = field_type;
> g_hash_table_insert(field_name_to_index,
> - (gpointer) (unsigned long) name_quark,
> - (gpointer) (unsigned long) fields->len);
> + GUINT_TO_POINTER(name_quark),
> + GUINT_TO_POINTER(fields->len));
> g_ptr_array_add(fields, field);
> end:
> return ret;
> diff --git a/formats/ctf/metadata/ctf-parser.y b/formats/ctf/metadata/ctf-parser.y
> index 821f0f7..d0866ff 100644
> --- a/formats/ctf/metadata/ctf-parser.y
> +++ b/formats/ctf/metadata/ctf-parser.y
> @@ -330,7 +330,7 @@ static int lookup_type(struct ctf_scanner_scope *s, const char *id)
> {
> int ret;
>
> - ret = (int) (long) g_hash_table_lookup(s->types, id);
> + ret = GPOINTER_TO_INT(g_hash_table_lookup(s->types, id));
> printf_debug("lookup %p %s %d\n", s, id, ret);
> return ret;
> }
> diff --git a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c
> index 097a482..13b79f0 100644
> --- a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c
> +++ b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c
> @@ -278,7 +278,7 @@ struct ctf_event_declaration *stream_event_lookup(struct ctf_stream_declaration
> static
> struct ctf_clock *trace_clock_lookup(struct ctf_trace *trace, GQuark clock_name)
> {
> - return g_hash_table_lookup(trace->parent.clocks, (gpointer) (unsigned long) clock_name);
> + return g_hash_table_lookup(trace->parent.clocks, GUINT_TO_POINTER(clock_name));
> }
>
> static
> @@ -1907,7 +1907,7 @@ int ctf_event_visit(FILE *fd, int depth, struct ctf_node *node,
> g_ptr_array_set_size(event->stream->events_by_id, event->id + 1);
> g_ptr_array_index(event->stream->events_by_id, event->id) = event;
> g_hash_table_insert(event->stream->event_quark_to_id,
> - (gpointer) (unsigned long) event->name,
> + GUINT_TO_POINTER(event->name),
> &event->id);
> g_ptr_array_add(trace->event_declarations, event_decl);
> return 0;
> @@ -2491,7 +2491,7 @@ int ctf_clock_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_trace
> goto error;
> }
> trace->parent.single_clock = clock;
> - g_hash_table_insert(trace->parent.clocks, (gpointer) (unsigned long) clock->name, clock);
> + g_hash_table_insert(trace->parent.clocks, GUINT_TO_POINTER(clock->name), clock);
> return 0;
>
> error:
> @@ -2526,7 +2526,7 @@ void ctf_clock_default(FILE *fd, int depth, struct ctf_trace *trace)
> }
>
> trace->parent.single_clock = clock;
> - g_hash_table_insert(trace->parent.clocks, (gpointer) (unsigned long) clock->name, clock);
> + g_hash_table_insert(trace->parent.clocks, GUINT_TO_POINTER(clock->name), clock);
> }
>
> static
> @@ -2683,12 +2683,12 @@ int ctf_callsite_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_tr
> }
>
> cs_dups = g_hash_table_lookup(trace->callsites,
> - (gpointer) (unsigned long) callsite->name);
> + GUINT_TO_POINTER(callsite->name));
> if (!cs_dups) {
> cs_dups = g_new0(struct ctf_callsite_dups, 1);
> BT_INIT_LIST_HEAD(&cs_dups->head);
> g_hash_table_insert(trace->callsites,
> - (gpointer) (unsigned long) callsite->name, cs_dups);
> + GUINT_TO_POINTER(callsite->name), cs_dups);
> }
> bt_list_add_tail(&callsite->node, &cs_dups->head);
> return 0;
> diff --git a/lib/context.c b/lib/context.c
> index 3617bcd..56ac320 100644
> --- a/lib/context.c
> +++ b/lib/context.c
> @@ -174,7 +174,7 @@ int bt_context_add_trace(struct bt_context *ctx, const char *path,
>
> /* Add new handle to container */
> g_hash_table_insert(ctx->trace_handles,
> - (gpointer) (unsigned long) handle->id,
> + GUINT_TO_POINTER(handle->id),
> handle);
>
> return handle->id;
> @@ -207,7 +207,7 @@ int bt_context_remove_trace(struct bt_context *ctx, int handle_id)
> * automatically.
> */
> if (!g_hash_table_remove(ctx->trace_handles,
> - (gpointer) (unsigned long) handle_id)) {
> + GUINT_TO_POINTER(handle_id))) {
> ret = -ENOENT;
> goto end;
> }
> diff --git a/lib/registry.c b/lib/registry.c
> index bdce0c6..bc2be95 100644
> --- a/lib/registry.c
> +++ b/lib/registry.c
> @@ -73,7 +73,7 @@ struct bt_format *bt_lookup_format(bt_intern_str name)
> return NULL;
>
> return g_hash_table_lookup(format_registry,
> - (gconstpointer) (unsigned long) name);
> + (gconstpointer) GUINT_TO_POINTER(name));
> }
>
> static void show_format(gpointer key, gpointer value, gpointer user_data)
> @@ -81,7 +81,7 @@ static void show_format(gpointer key, gpointer value, gpointer user_data)
> struct walk_data *data = user_data;
>
> fprintf(data->fp, "%s%s", data->iter ? ", " : "",
> - g_quark_to_string((GQuark) (unsigned long) key));
> + g_quark_to_string((GQuark) GPOINTER_TO_UINT(key)));
> data->iter++;
> }
>
> @@ -116,7 +116,7 @@ int bt_register_format(struct bt_format *format)
>
> format_refcount_inc();
> g_hash_table_insert(format_registry,
> - (gpointer) (unsigned long) format->name,
> + GUINT_TO_POINTER(format->name),
> format);
> return 0;
> }
> @@ -125,7 +125,7 @@ void bt_unregister_format(struct bt_format *format)
> {
> assert(bt_lookup_format(format->name));
> g_hash_table_remove(format_registry,
> - (gpointer) (unsigned long) format->name);
> + GUINT_TO_POINTER(format->name));
> format_refcount_dec();
> }
>
> diff --git a/lib/trace-collection.c b/lib/trace-collection.c
> index 035d2dc..213ece5 100644
> --- a/lib/trace-collection.c
> +++ b/lib/trace-collection.c
> @@ -53,7 +53,7 @@ static void check_clock_match(gpointer key, gpointer value, gpointer user_data)
> * by clock name.
> */
> clock_b = g_hash_table_lookup(match->clocks,
> - (gpointer) (unsigned long) clock_a->name);
> + GUINT_TO_POINTER(clock_a->name));
> if (clock_b) {
> match->clock_match = clock_b;
> return;
> @@ -64,7 +64,7 @@ static void check_clock_match(gpointer key, gpointer value, gpointer user_data)
> * clocks.
> */
> clock_b = g_hash_table_lookup(match->clocks,
> - (gpointer) (unsigned long) clock_a->uuid);
> + GUINT_TO_POINTER(clock_a->uuid));
> if (clock_b) {
> match->clock_match = clock_b;
> return;
> @@ -87,7 +87,7 @@ static void clock_add(gpointer key, gpointer value, gpointer user_data)
> struct ctf_clock *tc_clock;
>
> tc_clock = g_hash_table_lookup(tc_clocks,
> - (gpointer) (unsigned long) v);
> + GUINT_TO_POINTER(v));
> if (!tc_clock) {
> /*
> * For now we only support CTF that has one
> @@ -105,7 +105,7 @@ static void clock_add(gpointer key, gpointer value, gpointer user_data)
> clock_match->tc->offset_first;
> }
> g_hash_table_insert(tc_clocks,
> - (gpointer) (unsigned long) v,
> + GUINT_TO_POINTER(v),
> value);
> } else if (!t_clock->absolute) {
> int64_t diff_ns;
> diff --git a/lib/trace-handle.c b/lib/trace-handle.c
> index b768a08..4c41d2f 100644
> --- a/lib/trace-handle.c
> +++ b/lib/trace-handle.c
> @@ -60,7 +60,7 @@ const char *bt_trace_handle_get_path(struct bt_context *ctx, int handle_id)
> return NULL;
>
> handle = g_hash_table_lookup(ctx->trace_handles,
> - (gpointer) (unsigned long) handle_id);
> + GUINT_TO_POINTER(handle_id));
> if (!handle)
> return NULL;
> return handle->path;
> @@ -77,7 +77,7 @@ int bt_trace_handle_get_timestamp_begin(struct bt_context *ctx,
> return -1;
>
> handle = g_hash_table_lookup(ctx->trace_handles,
> - (gpointer) (unsigned long) handle_id);
> + GUINT_TO_POINTER(handle_id));
> if (!handle) {
> ret = -1;
> goto end;
> @@ -105,7 +105,7 @@ int bt_trace_handle_get_timestamp_end(struct bt_context *ctx,
> return -1;
>
> handle = g_hash_table_lookup(ctx->trace_handles,
> - (gpointer) (unsigned long) handle_id);
> + GUINT_TO_POINTER(handle_id));
> if (!handle) {
> ret = -1;
> goto end;
> diff --git a/lib/values.c b/lib/values.c
> index 345ef71..bd217bf 100644
> --- a/lib/values.c
> +++ b/lib/values.c
> @@ -226,7 +226,7 @@ struct bt_value *bt_value_map_copy(const struct bt_value *map_obj)
> g_hash_table_iter_init(&iter, typed_map_obj->ght);
>
> while (g_hash_table_iter_next(&iter, &key, &element_obj)) {
> - const char *key_str = g_quark_to_string((unsigned long) key);
> + const char *key_str = g_quark_to_string(GPOINTER_TO_UINT(key));
>
> element_obj_copy = bt_value_copy(element_obj);
>
> @@ -357,7 +357,7 @@ bool bt_value_map_compare(const struct bt_value *object_a,
>
> while (g_hash_table_iter_next(&iter, &key, &element_obj_a)) {
> struct bt_value *element_obj_b;
> - const char *key_str = g_quark_to_string((unsigned long) key);
> + const char *key_str = g_quark_to_string(GPOINTER_TO_UINT(key));
>
> element_obj_b = bt_value_map_get(object_b, key_str);
>
> @@ -1156,7 +1156,7 @@ enum bt_value_status bt_value_map_foreach(const struct bt_value *map_obj,
> g_hash_table_iter_init(&iter, typed_map_obj->ght);
>
> while (g_hash_table_iter_next(&iter, &key, &element_obj)) {
> - const char *key_str = g_quark_to_string((unsigned long) key);
> + const char *key_str = g_quark_to_string(GPOINTER_TO_UINT(key));
>
> if (!cb(key_str, element_obj, data)) {
> ret = BT_VALUE_STATUS_CANCELLED;
> diff --git a/types/enum.c b/types/enum.c
> index ec10a16..455e60a 100644
> --- a/types/enum.c
> +++ b/types/enum.c
> @@ -270,7 +270,7 @@ GArray *bt_enum_quark_to_range_set(const struct declaration_enum *enum_declarati
> GQuark q)
> {
> return g_hash_table_lookup(enum_declaration->table.quark_to_range_set,
> - (gconstpointer) (unsigned long) q);
> + (gconstpointer) GUINT_TO_POINTER(q));
> }
>
> static
> @@ -319,12 +319,12 @@ void bt_enum_signed_insert(struct declaration_enum *enum_declaration,
> }
>
> array = g_hash_table_lookup(enum_declaration->table.quark_to_range_set,
> - (gconstpointer) (unsigned long) q);
> + (gconstpointer) GUINT_TO_POINTER(q));
> if (!array) {
> array = g_array_sized_new(FALSE, TRUE,
> sizeof(struct enum_range), 1);
> g_hash_table_insert(enum_declaration->table.quark_to_range_set,
> - (gpointer) (unsigned long) q,
> + GUINT_TO_POINTER(q),
> array);
> }
> g_array_set_size(array, array->len + 1);
> @@ -354,12 +354,12 @@ void bt_enum_unsigned_insert(struct declaration_enum *enum_declaration,
> }
>
> array = g_hash_table_lookup(enum_declaration->table.quark_to_range_set,
> - (gconstpointer) (unsigned long) q);
> + (gconstpointer) GUINT_TO_POINTER(q));
> if (!array) {
> array = g_array_sized_new(FALSE, TRUE,
> sizeof(struct enum_range), 1);
> g_hash_table_insert(enum_declaration->table.quark_to_range_set,
> - (gpointer) (unsigned long) q,
> + GUINT_TO_POINTER(q),
> array);
> }
> g_array_set_size(array, array->len + 1);
> diff --git a/types/struct.c b/types/struct.c
> index 7eaa424..e2f6a1e 100644
> --- a/types/struct.c
> +++ b/types/struct.c
> @@ -196,8 +196,8 @@ void bt_struct_declaration_add_field(struct declaration_struct *struct_declarati
> field->declaration = field_declaration;
> /* Keep index in hash rather than pointer, because array can relocate */
> g_hash_table_insert(struct_declaration->fields_by_name,
> - (gpointer) (unsigned long) field->name,
> - (gpointer) index);
> + GUINT_TO_POINTER(field->name),
> + GUINT_TO_POINTER(index));
> /*
> * Alignment of structure is the max alignment of declarations contained
> * therein.
> @@ -219,11 +219,11 @@ int bt_struct_declaration_lookup_field_index(struct declaration_struct *struct_d
> gboolean found;
>
> found = g_hash_table_lookup_extended(struct_declaration->fields_by_name,
> - (gconstpointer) (unsigned long) field_name,
> + (gconstpointer) GUINT_TO_POINTER(field_name),
> NULL, &index);
> if (!found)
> return -1;
> - return (int) (unsigned long) index;
> + return GPOINTER_TO_INT(index);
> }
>
> /*
> diff --git a/types/types.c b/types/types.c
> index 41c6b8e..f58d2e4 100644
> --- a/types/types.c
> +++ b/types/types.c
> @@ -56,7 +56,7 @@ struct bt_declaration *
> struct declaration_scope *scope)
> {
> return g_hash_table_lookup(scope->typedef_declarations,
> - (gconstpointer) (unsigned long) declaration_name);
> + (gconstpointer) GUINT_TO_POINTER(declaration_name));
> }
>
> struct bt_declaration *bt_lookup_declaration(GQuark declaration_name,
> @@ -85,7 +85,7 @@ int bt_register_declaration(GQuark name, struct bt_declaration *declaration,
> return -EEXIST;
>
> g_hash_table_insert(scope->typedef_declarations,
> - (gpointer) (unsigned long) name,
> + GUINT_TO_POINTER(name),
> declaration);
> bt_declaration_ref(declaration);
> return 0;
> @@ -97,7 +97,7 @@ struct bt_definition *
> struct definition_scope *scope)
> {
> return g_hash_table_lookup(scope->definitions,
> - (gconstpointer) (unsigned long) field_name);
> + (gconstpointer) GUINT_TO_POINTER(field_name));
> }
>
> /*
> @@ -273,7 +273,7 @@ int bt_register_field_definition(GQuark field_name, struct bt_definition *defini
> return -EEXIST;
>
> g_hash_table_insert(scope->definitions,
> - (gpointer) (unsigned long) field_name,
> + GUINT_TO_POINTER(field_name),
> definition);
> /* Don't keep reference on definition */
> return 0;
> @@ -340,7 +340,7 @@ struct declaration_struct *bt_lookup_struct_declaration_scope(GQuark struct_name
> struct declaration_scope *scope)
> {
> return g_hash_table_lookup(scope->struct_declarations,
> - (gconstpointer) (unsigned long) struct_name);
> + (gconstpointer) GUINT_TO_POINTER(struct_name));
> }
>
> struct declaration_struct *bt_lookup_struct_declaration(GQuark struct_name,
> @@ -372,7 +372,7 @@ int bt_register_struct_declaration(GQuark struct_name,
> return -EEXIST;
>
> g_hash_table_insert(scope->struct_declarations,
> - (gpointer) (unsigned long) struct_name,
> + GUINT_TO_POINTER(struct_name),
> struct_declaration);
> bt_declaration_ref(&struct_declaration->p);
>
> @@ -389,7 +389,7 @@ struct declaration_untagged_variant *
> struct declaration_scope *scope)
> {
> return g_hash_table_lookup(scope->variant_declarations,
> - (gconstpointer) (unsigned long) variant_name);
> + (gconstpointer) GUINT_TO_POINTER(variant_name));
> }
>
> struct declaration_untagged_variant *
> @@ -422,7 +422,7 @@ int bt_register_variant_declaration(GQuark variant_name,
> return -EEXIST;
>
> g_hash_table_insert(scope->variant_declarations,
> - (gpointer) (unsigned long) variant_name,
> + GUINT_TO_POINTER(variant_name),
> untagged_variant_declaration);
> bt_declaration_ref(&untagged_variant_declaration->p);
>
> @@ -440,7 +440,7 @@ struct declaration_enum *
> struct declaration_scope *scope)
> {
> return g_hash_table_lookup(scope->enum_declarations,
> - (gconstpointer) (unsigned long) enum_name);
> + (gconstpointer) GUINT_TO_POINTER(enum_name));
> }
>
> struct declaration_enum *
> @@ -473,7 +473,7 @@ int bt_register_enum_declaration(GQuark enum_name,
> return -EEXIST;
>
> g_hash_table_insert(scope->enum_declarations,
> - (gpointer) (unsigned long) enum_name,
> + GUINT_TO_POINTER(enum_name),
> enum_declaration);
> bt_declaration_ref(&enum_declaration->p);
>
> diff --git a/types/variant.c b/types/variant.c
> index 3972d78..f660e18 100644
> --- a/types/variant.c
> +++ b/types/variant.c
> @@ -227,8 +227,8 @@ void bt_untagged_variant_declaration_add_field(struct declaration_untagged_varia
> field->declaration = field_declaration;
> /* Keep index in hash rather than pointer, because array can relocate */
> g_hash_table_insert(untagged_variant_declaration->fields_by_tag,
> - (gpointer) (unsigned long) field->name,
> - (gpointer) index);
> + GUINT_TO_POINTER(field->name),
> + GUINT_TO_POINTER(index));
> /*
> * Alignment of variant is based on the alignment of its currently
> * selected choice, so we leave variant alignment as-is (statically
> @@ -244,13 +244,13 @@ bt_untagged_variant_declaration_get_field_from_tag(struct declaration_untagged_v
>
> found = g_hash_table_lookup_extended(
> untagged_variant_declaration->fields_by_tag,
> - (gconstpointer) (unsigned long) tag, NULL, &index);
> + (gconstpointer) GUINT_TO_POINTER(tag), NULL, &index);
>
> if (!found) {
> return NULL;
> }
>
> - return &g_array_index(untagged_variant_declaration->fields, struct declaration_field, (unsigned long)index);
> + return &g_array_index(untagged_variant_declaration->fields, struct declaration_field, GPOINTER_TO_UINT(index));
> }
>
> /*
> @@ -279,7 +279,7 @@ struct bt_definition *bt_variant_get_current_field(struct definition_variant *va
> assert(tag_array->len == 1);
> tag = g_array_index(tag_array, GQuark, 0);
> if (!g_hash_table_lookup_extended(variant_declaration->untagged_variant->fields_by_tag,
> - (gconstpointer) (unsigned long) tag,
> + (gconstpointer) GUINT_TO_POINTER(tag),
> &orig_key,
> &value)) {
> /* Cannot find matching field. */
> @@ -287,7 +287,7 @@ struct bt_definition *bt_variant_get_current_field(struct definition_variant *va
> g_quark_to_string(tag));
> return NULL;
> }
> - index = (unsigned long) value;
> + index = GPOINTER_TO_UINT(value);
> variant->current_field = g_ptr_array_index(variant->fields, index);
> return variant->current_field;
> }
> --
> 2.7.4
>
--
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com
More information about the lttng-dev
mailing list