On Thursday 10,February,2011 02:16 AM, Thomas Martitz wrote:
> Am 09.02.2011 17:57, schrieb Chow Loong Jin:
>
>> gint compare_func(gconstpointer a, gconstpointer b, gpointer user_data)
>> {
>> - if (a == b)
>> + gint ia = GPOINTER_TO_INT(a);
>> + gint ib = GPOINTER_TO_INT(b);
>> + if (ia == ib)
>> return 0;
>> else
>> - return a> b ? 1 : -1;
>> + return ia> ib ? 1 : -1;
>> }
>
> FWIW, this can be replaced with "return ia - ib".Ooh cool, I didn't think of that. Thanks for the tip! Here's a revised patch. -- Kind regards, Loong Jin
From 0109c2b7e046490778e15834b311616ce59d7e0b Mon Sep 17 00:00:00 2001 From: Chow Loong Jin <[email protected]> Date: Thu, 10 Feb 2011 00:34:03 +0800 Subject: [PATCH 1/3] Fix integer size mismatch while casting * Use GPOINTER_TO_INT and GINT_TO_POINTER for handling pointer/int conversion * Use the trinary operator (condition ? true : false) for checking null value of a pointer --- debugger/src/breakpoints.c | 14 +++++++------- debugger/src/dbm_gdb.c | 4 ++-- debugger/src/stree.c | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/debugger/src/breakpoints.c b/debugger/src/breakpoints.c index 3d3d8aa..57819df 100644 --- a/debugger/src/breakpoints.c +++ b/debugger/src/breakpoints.c @@ -76,7 +76,7 @@ breakpoint* lookup_breakpoint(gchar* file, int line) breakpoint* bp = NULL; GTree* tree = NULL; if (tree = (GTree*)g_hash_table_lookup(files, file)) - bp = g_tree_lookup(tree, (gconstpointer)line); + bp = g_tree_lookup(tree, GINT_TO_POINTER(line)); return bp; } @@ -91,10 +91,10 @@ breakpoint* lookup_breakpoint(gchar* file, int line) */ gint compare_func(gconstpointer a, gconstpointer b, gpointer user_data) { - if (a == b) - return 0; - else - return a > b ? 1 : -1; + gint ia = GPOINTER_TO_INT(a); + gint ib = GPOINTER_TO_INT(b); + + return ia - ib; } /* @@ -298,7 +298,7 @@ void breaks_add(char* file, int line, char* condition, int enabled, int hitscoun } /* insert to internal storage */ - g_tree_insert(tree, (gpointer)bp->line, (gpointer)bp); + g_tree_insert(tree, GINT_TO_POINTER(bp->line), bp); /* handle creation instantly if debugger is idle or stopped and request debug module interruption overwise */ @@ -442,7 +442,7 @@ gboolean breaks_is_set(char* file, int line) else { /* lookup for the break in GTree*/ - gpointer p = g_tree_lookup(tree, (gconstpointer)line); + gpointer p = g_tree_lookup(tree, GINT_TO_POINTER(line)); return p && ((breakpoint*)p)->enabled; } } diff --git a/debugger/src/dbm_gdb.c b/debugger/src/dbm_gdb.c index 601817f..e6718f7 100644 --- a/debugger/src/dbm_gdb.c +++ b/debugger/src/dbm_gdb.c @@ -251,7 +251,7 @@ GList* read_until_end() static gboolean on_read_from_gdb(GIOChannel * src, GIOCondition cond, gpointer data) { gchar *line; - gint length; + gsize length; if (G_IO_STATUS_NORMAL != g_io_channel_read_line(src, &line, NULL, &length, NULL)) return TRUE; @@ -900,7 +900,7 @@ GList* get_stack() strcpy(f->file, ""); /* whether source is available */ - f->have_source = (gboolean)fullname; + f->have_source = fullname ? TRUE : FALSE; /* line */ int line = 0; diff --git a/debugger/src/stree.c b/debugger/src/stree.c index 959e971..d2c2377 100644 --- a/debugger/src/stree.c +++ b/debugger/src/stree.c @@ -93,7 +93,7 @@ void on_selection_changed(GtkTreeSelection *treeselection, gpointer user_data) -1); /* check if file name is not empty and we have source files for the frame */ - if (strlen(file) && g_hash_table_lookup(frames, (gpointer)file)) + if (strlen(file) && GPOINTER_TO_INT(g_hash_table_lookup(frames, (gpointer)file))) callback(file, line); g_free(file); @@ -203,8 +203,8 @@ void stree_add(frame *f) -1); /* remember if we have source for this frame */ - if (f->have_source && !g_hash_table_lookup(frames, (gpointer)f->file)) - g_hash_table_insert(frames, g_strdup(f->file), (gpointer)f->have_source); + if (f->have_source && !GPOINTER_TO_INT(g_hash_table_lookup(frames, (gpointer)f->file))) + g_hash_table_insert(frames, g_strdup(f->file), GINT_TO_POINTER(f->have_source)); } /* -- 1.7.1
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Geany-devel mailing list [email protected] http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel
