[PATCH] Use gtk_tree_model_get_value() to get the index and date of a dive

Dirk Hohndel dirk at hohndel.org
Tue Sep 18 15:52:33 PDT 2012


I don't get the part where this would be "safer". Can you point to any
documentation that states this?

I'm obviously thrilled if this does indeed fix the bugs Miika has been
seeing - but I'll admit that I'm deeply unhappy with this. The whole
get_value set of functions are just so horribly atrocious... they make
for truly ugly and unreadable code (IMNSHO)

/D

"Lubomir I. Ivanov" <neolit123 at gmail.com> writes:

> From: "Lubomir I. Ivanov" <neolit123 at gmail.com>
>
> When retrieving the index and date from the model and iterator
> in divelist.c:date_data_func(), use gtk_tree_model_get_value()
> to write to Gvalue entries, which should be technically safer
> than the varargs list of gtk_tree_model_get(), but shouldn't break either.
>
> This seems to solve a bug on Ubuntu 12.0.4, where the DIVE_INDEX in the
> abovementioned functon is never set to -1 (entry is a Trip).
>
> The same bug cannot be reporoduced on Debian 6.0.4 and Windows 7
> with the latest GTK / GLib.
>
> Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
> ---
>  dive.h     |  5 +++++
>  divelist.c | 16 ++++++++++++----
>  2 files changed, 17 insertions(+), 4 deletions(-)
>
> diff --git a/dive.h b/dive.h
> index 5637edf..5ff883a 100644
> --- a/dive.h
> +++ b/dive.h
> @@ -8,6 +8,11 @@
>  #include <glib/gstdio.h>
>  #include <libxml/tree.h>
>  
> +/* Since glib-2.30 */
> +#ifndef G_VALUE_INIT
> +	#define G_VALUE_INIT  { 0, { { 0 } } }
> +#endif
> +
>  /*
>   * Some silly typedefs to make our units very explicit.
>   *
> diff --git a/divelist.c b/divelist.c
> index aedcdf0..8df006a 100644
> --- a/divelist.c
> +++ b/divelist.c
> @@ -375,18 +375,23 @@ static void date_data_func(GtkTreeViewColumn *col,
>  			   GtkTreeIter *iter,
>  			   gpointer data)
>  {
> -	int val, idx, nr;
> +	int nr;
>  	struct tm *tm;
>  	time_t when;
>  	char buffer[40];
>  
> -	gtk_tree_model_get(model, iter, DIVE_INDEX, &idx, DIVE_DATE, &val, -1);
> +	GValue gv_idx = G_VALUE_INIT;
> +	GValue gv_date = G_VALUE_INIT;
> +
> +	gtk_tree_model_get_value(model, iter, DIVE_INDEX, &gv_idx);
> +	gtk_tree_model_get_value(model, iter, DIVE_DATE, &gv_date);
> +
>  	nr = gtk_tree_model_iter_n_children(model, iter);
>  	/* 2038 problem */
> -	when = val;
> +	when = g_value_get_long(&gv_date);
>  
>  	tm = gmtime(&when);
> -	if (idx < 0) {
> +	if (g_value_get_int(&gv_idx) < 0) {
>  		snprintf(buffer, sizeof(buffer),
>  			"Trip %s, %s %d, %d (%d dive%s)",
>  			weekday(tm->tm_wday),
> @@ -401,6 +406,9 @@ static void date_data_func(GtkTreeViewColumn *col,
>  			tm->tm_mday, tm->tm_year + 1900,
>  			tm->tm_hour, tm->tm_min);
>  	}
> +
> +	g_value_unset(&gv_idx);
> +	g_value_unset(&gv_date);
>  	g_object_set(renderer, "text", buffer, NULL);
>  }
>  
> -- 
> 1.7.11.msysgit.0
>
> _______________________________________________
> subsurface mailing list
> subsurface at hohndel.org
> http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

-- 
Dirk Hohndel
Intel Open Source Technology Center


More information about the subsurface mailing list