Wireshark-dev: [Wireshark-dev] Please review: GSEAL fixes: allocation
From: Joerg Mayer <jmayer@xxxxxxxxx>
Date: Wed, 20 Jul 2011 20:23:41 +0200
Hello,

I have fixed most of the struct GtkAllocation access errors when building
with -DGSEAL (all occurences except rtp_player.c).
As I really do not understand what I'm doing here, it would be nice if
someone would be willing to review this, especially whether the call to
gtk_widget_get_allocation() is often enough or too often. I have not
spotted any changes in behavior, but I wouldn't really know what to test.

Thanks
       Joerg

-- 
Joerg Mayer                                           <jmayer@xxxxxxxxx>
We are stuck with technology when what we really want is just stuff that
works. Some say that should read Microsoft instead of technology.
Index: tcp_graph.c
===================================================================
--- tcp_graph.c	(revision 38117)
+++ tcp_graph.c	(working copy)
@@ -678,6 +678,7 @@
 	char window_title[WINDOW_TITLE_LENGTH];
 	struct segment current;
 	struct tcpheader *thdr;
+	GtkAllocation widget_alloc;
 
 	debug(DBS_FENTRY) puts ("create_drawing_area()");
 #if 0
@@ -760,9 +761,14 @@
 	gtk_widget_show (g->toplevel);
 
 	/* in case we didn't get what we asked for */
-	g->wp.width = GTK_WIDGET (g->drawing_area)->allocation.width -
+#if GTK_CHECK_VERSION(2,18,0)
+	gtk_widget_get_allocation(GTK_WIDGET (g->drawing_area), &widget_alloc);
+#else
+	widget_alloc = GTK_WIDGET (g->drawing_area)->allocation;
+#endif
+	g->wp.width = widget_alloc.width -
 						g->wp.x - RMARGIN_WIDTH;
-	g->wp.height = GTK_WIDGET (g->drawing_area)->allocation.height -
+	g->wp.height = widget_alloc.height -
 						g->wp.y - g->x_axis->s.height;
 
         g->font = g->drawing_area->style->font_desc;
Index: iax2_analysis.c
===================================================================
--- iax2_analysis.c	(revision 38117)
+++ iax2_analysis.c	(working copy)
@@ -920,6 +920,7 @@
 	int label_width_mid, label_height_mid;
 	guint32 draw_width, draw_height;
 	char label_string[15];
+	GtkAllocation widget_alloc;
 
 	/* new variables */
 	guint32 num_time_intervals;
@@ -972,12 +973,17 @@
 	/*
 	 * Clear out old plot
 	 */
+#if GTK_CHECK_VERSION(2,18,0)
+	gtk_widget_get_allocation(user_data->dlg.dialog_graph.draw_area, &widget_alloc);
+#else
+	widget_alloc = user_data->dlg.dialog_graph.draw_area->allocation;
+#endif
 	gdk_draw_rectangle(user_data->dlg.dialog_graph.pixmap,
 			   user_data->dlg.dialog_graph.draw_area->style->white_gc,
 			   TRUE,
 			   0, 0,
-			   user_data->dlg.dialog_graph.draw_area->allocation.width,
-			   user_data->dlg.dialog_graph.draw_area->allocation.height);
+			   widget_alloc.width,
+			   widget_alloc.height);
 
 
 	/*
@@ -1349,25 +1355,31 @@
 {
 	user_data_t *user_data = data;
 	int i;
+	GtkAllocation widget_alloc;
 
 	if(user_data->dlg.dialog_graph.pixmap){
 		g_object_unref(user_data->dlg.dialog_graph.pixmap);
 		user_data->dlg.dialog_graph.pixmap=NULL;
 	}
 
+#if GTK_CHECK_VERSION(2,18,0)
+	gtk_widget_get_allocation(widget, &widget_alloc);
+#else
+	widget_alloc = widget->allocation;
+#endif
 	user_data->dlg.dialog_graph.pixmap=gdk_pixmap_new(widget->window,
-			widget->allocation.width,
-			widget->allocation.height,
+			widget_alloc.width,
+			widget_alloc.height,
 			-1);
-	user_data->dlg.dialog_graph.pixmap_width=widget->allocation.width;
-	user_data->dlg.dialog_graph.pixmap_height=widget->allocation.height;
+	user_data->dlg.dialog_graph.pixmap_width=widget_alloc.width;
+	user_data->dlg.dialog_graph.pixmap_height=widget_alloc.height;
 
 	gdk_draw_rectangle(user_data->dlg.dialog_graph.pixmap,
 			widget->style->white_gc,
 			TRUE,
 			0, 0,
-			widget->allocation.width,
-			widget->allocation.height);
+			widget_alloc.width,
+			widget_alloc.height);
 
 	/* set up the colors and the GC structs for this pixmap */
 	for(i=0;i<MAX_GRAPHS;i++){
Index: sctp_byte_graph_dlg.c
===================================================================
--- sctp_byte_graph_dlg.c	(revision 38117)
+++ sctp_byte_graph_dlg.c	(working copy)
@@ -268,6 +268,7 @@
 	gfloat dis;
 	gboolean write_label = FALSE;
 	PangoLayout  *layout;
+	GtkAllocation widget_alloc;
 
 	if (u_data->io->x1_tmp_sec == 0 && u_data->io->x1_tmp_usec == 0)
 		u_data->io->offset = 0;
@@ -321,9 +322,14 @@
 			u_data->io->min_y = u_data->io->tmp_min_tsn2;
 		}
 	}
+#if GTK_CHECK_VERSION(2,18,0)
+	gtk_widget_get_allocation(u_data->io->draw_area, &widget_alloc);
+#else
+	widget_alloc = u_data->io->draw_area->allocation;
+#endif
 	gdk_draw_rectangle(u_data->io->pixmap, u_data->io->draw_area->style->white_gc,
-	                   TRUE, 0, 0, u_data->io->draw_area->allocation.width,
-	                   u_data->io->draw_area->allocation.height);
+	                   TRUE, 0, 0, widget_alloc.width,
+	                   widget_alloc.height);
 
 	distance = 5;
 	/* x_axis */
@@ -572,6 +578,7 @@
 static void sctp_graph_redraw(struct sctp_udata *u_data)
 {
 	sctp_graph_t *ios;
+	GtkAllocation widget_alloc;
 
 	u_data->io->needs_redraw = TRUE;
 
@@ -593,6 +600,11 @@
 	ios=(sctp_graph_t *)g_object_get_data(G_OBJECT(u_data->io->draw_area), "sctp_graph_t");
 	g_assert(ios != NULL);
 
+#if GTK_CHECK_VERSION(2,18,0)
+	gtk_widget_get_allocation(u_data->io->draw_area, &widget_alloc);
+#else
+	widget_alloc = u_data->io->draw_area->allocation;
+#endif
 	gdk_draw_pixmap(u_data->io->draw_area->window,
 #if GTK_CHECK_VERSION(2,18,0)
 	                u_data->io->draw_area->style->fg_gc[gtk_widget_get_state(u_data->io->draw_area)],
@@ -602,8 +614,8 @@
 	                ios->pixmap,
 	                0,0,
 	                0, 0,
-	                u_data->io->draw_area->allocation.width,
-	                u_data->io->draw_area->allocation.height);
+	                widget_alloc.width,
+	                widget_alloc.height);
 }
 
 
@@ -642,6 +654,7 @@
 on_configure_event(GtkWidget *widget, GdkEventConfigure *event _U_, gpointer user_data)
 {
 	struct sctp_udata *u_data = user_data;
+	GtkAllocation widget_alloc;
 
 	g_assert(u_data->io != NULL);
 
@@ -650,19 +663,24 @@
 		u_data->io->pixmap = NULL;
 	}
 
+#if GTK_CHECK_VERSION(2,18,0)
+	gtk_widget_get_allocation(widget, &widget_alloc);
+#else
+widget_alloc = widget->allocation;
+#endif
 	u_data->io->pixmap = gdk_pixmap_new(widget->window,
-	                                    widget->allocation.width,
-	                                    widget->allocation.height,
+	                                    widget_alloc.width,
+	                                    widget_alloc.height,
 	                                    -1);
-	u_data->io->pixmap_width = widget->allocation.width;
-	u_data->io->pixmap_height = widget->allocation.height;
+	u_data->io->pixmap_width = widget_alloc.width;
+	u_data->io->pixmap_height = widget_alloc.height;
 
 	gdk_draw_rectangle(u_data->io->pixmap,
 	                   widget->style->white_gc,
 	                   TRUE,
 	                   0, 0,
-	                   widget->allocation.width,
-	                   widget->allocation.height);
+	                   widget_alloc.width,
+	                   widget_alloc.height);
 	sctp_graph_redraw(u_data);
 	return TRUE;
 }
@@ -869,6 +887,8 @@
 	GList *tsnlist=NULL;
 	tsn_t *tsn, *tmptsn;
 	PangoLayout  *layout;
+	GtkAllocation widget_alloc;
+
 	g_snprintf(label_string, 15, "%d", 0);
 	memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), 15);
 	layout = gtk_widget_create_pango_layout(u_data->io->draw_area, label_string);
@@ -894,6 +914,12 @@
 		ios=(sctp_graph_t *)g_object_get_data(G_OBJECT(u_data->io->draw_area), "sctp_graph_t");
 		g_assert(ios != NULL);
 
+#if GTK_CHECK_VERSION(2,18,0)
+		gtk_widget_get_allocation(u_data->io->draw_area, &widget_alloc);
+#else
+		widget_alloc = u_data->io->draw_area->allocation;
+#endif
+
 		gdk_draw_pixmap(u_data->io->draw_area->window,
 #if GTK_CHECK_VERSION(2,18,0)
 		                u_data->io->draw_area->style->fg_gc[gtk_widget_get_state(u_data->io->draw_area)],
@@ -903,8 +929,8 @@
 		                ios->pixmap,
 		                0, 0,
 		                0, 0,
-		                u_data->io->draw_area->allocation.width,
-		                u_data->io->draw_area->allocation.height);
+		                widget_alloc.width,
+		                widget_alloc.height);
 
 		x1_tmp=(guint32) floor(u_data->io->min_x+((u_data->io->x_old-LEFT_BORDER-u_data->io->offset)*u_data->io->tmp_width/u_data->io->axis_width));
 		x2_tmp=(guint32) floor(u_data->io->min_x+((event->x-LEFT_BORDER-u_data->io->offset)*u_data->io->tmp_width/u_data->io->axis_width));
@@ -1026,6 +1052,11 @@
 			ios=(sctp_graph_t *)g_object_get_data(G_OBJECT(u_data->io->draw_area), "sctp_graph_t");
 			g_assert(ios != NULL);
 
+#if GTK_CHECK_VERSION(2,18,0)
+		gtk_widget_get_allocation(u_data->io->draw_area, &widget_alloc);
+#else
+		widget_alloc = u_data->io->draw_area->allocation;
+#endif
 			gdk_draw_pixmap(u_data->io->draw_area->window,
 #if GTK_CHECK_VERSION(2,18,0)
 		                    u_data->io->draw_area->style->fg_gc[gtk_widget_get_state(u_data->io->draw_area)],
@@ -1035,8 +1066,8 @@
 		                    ios->pixmap,
 		                    0, 0,
 		                    0, 0,
-		                    u_data->io->draw_area->allocation.width,
-		                    u_data->io->draw_area->allocation.height);
+		                    widget_alloc.width,
+		                    widget_alloc.height);
 		}
 	}
 	return TRUE;
Index: rtp_analysis.c
===================================================================
--- rtp_analysis.c	(revision 38117)
+++ rtp_analysis.c	(working copy)
@@ -924,6 +924,7 @@
 	int label_width_mid, label_height_mid;
 	guint32 draw_width, draw_height;
 	char label_string[15];
+	GtkAllocation widget_alloc;
 
 	/* new variables */
 	guint32 num_time_intervals;
@@ -976,12 +977,17 @@
 	/*
 	 * Clear out old plot
 	 */
+#if GTK_CHECK_VERSION(2,18,0)
+	gtk_widget_get_allocation(user_data->dlg.dialog_graph.draw_area, &widget_alloc);
+#else
+	widget_alloc = user_data->dlg.dialog_graph.draw_area->allocation;
+#endif
 	gdk_draw_rectangle(user_data->dlg.dialog_graph.pixmap,
 			   user_data->dlg.dialog_graph.draw_area->style->white_gc,
 			   TRUE,
 			   0, 0,
-			   user_data->dlg.dialog_graph.draw_area->allocation.width,
-			   user_data->dlg.dialog_graph.draw_area->allocation.height);
+			   widget_alloc.width,
+			   widget_alloc.height);
 
 
 	/*
@@ -1354,6 +1360,7 @@
 	user_data_t *user_data;
 	int i;
 	GtkWidget *bt_save;
+	GtkAllocation widget_alloc;
 
 	user_data=(user_data_t *)g_object_get_data(G_OBJECT(widget), "user_data_t");
 
@@ -1366,12 +1373,17 @@
 		user_data->dlg.dialog_graph.pixmap=NULL;
 	}
 
+#if GTK_CHECK_VERSION(2,18,0)
+	gtk_widget_get_allocation(widget, &widget_alloc);
+#else
+	widget_alloc = widget->allocation;
+#endif
 	user_data->dlg.dialog_graph.pixmap=gdk_pixmap_new(widget->window,
-							  widget->allocation.width,
-							  widget->allocation.height,
+							  widget_alloc.width,
+							  widget_alloc.height,
 							  -1);
-	user_data->dlg.dialog_graph.pixmap_width=widget->allocation.width;
-	user_data->dlg.dialog_graph.pixmap_height=widget->allocation.height;
+	user_data->dlg.dialog_graph.pixmap_width=widget_alloc.width;
+	user_data->dlg.dialog_graph.pixmap_height=widget_alloc.height;
 
 	bt_save = g_object_get_data(G_OBJECT(user_data->dlg.dialog_graph.window), "bt_save");
 	g_object_set_data(G_OBJECT(bt_save), "pixmap", user_data->dlg.dialog_graph.pixmap);
@@ -1381,8 +1393,8 @@
 			   widget->style->white_gc,
 			   TRUE,
 			   0, 0,
-			   widget->allocation.width,
-			   widget->allocation.height);
+			   widget_alloc.width,
+			   widget_alloc.height);
 
 	/* set up the colors and the GC structs for this pixmap */
 	for(i=0;i<MAX_GRAPHS;i++){
Index: sctp_graph_dlg.c
===================================================================
--- sctp_graph_dlg.c	(revision 38117)
+++ sctp_graph_dlg.c	(working copy)
@@ -555,6 +555,7 @@
 	gfloat dis;
 	gboolean write_label = FALSE;
 	PangoLayout  *layout;
+	GtkAllocation widget_alloc;
 
 	if (u_data->io->x1_tmp_sec==0 && u_data->io->x1_tmp_usec==0)
 		u_data->io->offset=0;
@@ -609,12 +610,17 @@
 		}
 	}
 
+#if GTK_CHECK_VERSION(2,18,0)
+	gtk_widget_get_allocation(u_data->io->draw_area, &widget_alloc);
+#else
+	widget_alloc = u_data->io->draw_area->allocation;
+#endif
 	gdk_draw_rectangle(u_data->io->pixmap,
 	                   u_data->io->draw_area->style->white_gc,
 	                   TRUE,
 	                   0, 0,
-	                   u_data->io->draw_area->allocation.width,
-	                   u_data->io->draw_area->allocation.height);
+	                   widget_alloc.width,
+	                   widget_alloc.height);
 
 	distance=5;
 	/* x_axis */
@@ -869,7 +875,8 @@
 static void
 sctp_graph_redraw(struct sctp_udata *u_data)
 {
-sctp_graph_t *ios;
+	sctp_graph_t *ios;
+	GtkAllocation widget_alloc;
 
 	u_data->io->needs_redraw=TRUE;
 
@@ -909,6 +916,11 @@
 	ios=(sctp_graph_t *)g_object_get_data(G_OBJECT(u_data->io->draw_area), "sctp_graph_t");
 	g_assert(ios != NULL);
 
+#if GTK_CHECK_VERSION(2,18,0)
+	gtk_widget_get_allocation(u_data->io->draw_area, &widget_alloc);
+#else
+	widget_alloc = u_data->io->draw_area->allocation;
+#endif
 	gdk_draw_pixmap(u_data->io->draw_area->window,
 #if GTK_CHECK_VERSION(2,18,0)
 	                u_data->io->draw_area->style->fg_gc[gtk_widget_get_state(u_data->io->draw_area)],
@@ -918,8 +930,8 @@
 	                ios->pixmap,
 	                0,0,
 	                0, 0,
-	                u_data->io->draw_area->allocation.width,
-	                u_data->io->draw_area->allocation.height);
+	                widget_alloc.width,
+	                widget_alloc.height);
 }
 
 
@@ -964,6 +976,7 @@
 configure_event(GtkWidget *widget, GdkEventConfigure *event _U_, gpointer user_data)
 {
 	struct sctp_udata *u_data = user_data;
+	GtkAllocation widget_alloc;
 
 	g_assert(u_data->io != NULL);
 
@@ -972,19 +985,24 @@
 		u_data->io->pixmap=NULL;
 	}
 
+#if GTK_CHECK_VERSION(2,18,0)
+	gtk_widget_get_allocation(widget, &widget_alloc);
+#else
+	widget_alloc = widget->allocation;
+#endif
 	u_data->io->pixmap=gdk_pixmap_new(widget->window,
-			widget->allocation.width,
-			widget->allocation.height,
+			widget_alloc.width,
+			widget_alloc.height,
 			-1);
-	u_data->io->pixmap_width=widget->allocation.width;
-	u_data->io->pixmap_height=widget->allocation.height;
+	u_data->io->pixmap_width=widget_alloc.width;
+	u_data->io->pixmap_height=widget_alloc.height;
 
 	gdk_draw_rectangle(u_data->io->pixmap,
 			widget->style->white_gc,
 			TRUE,
 			0, 0,
-			widget->allocation.width,
-			widget->allocation.height);
+			widget_alloc.width,
+			widget_alloc.height);
 	sctp_graph_redraw(u_data);
 	return TRUE;
 }
@@ -1194,6 +1212,7 @@
 	struct tsn_sort *tsn, *sack=NULL;
 	gboolean sack_found = FALSE;
 	PangoLayout  *layout;
+	GtkAllocation widget_alloc;
 
 	g_snprintf(label_string, 15, "%d", 0);
 	memcpy(label_string,(gchar *)g_locale_to_utf8(label_string, -1 , NULL, NULL, NULL), 15);
@@ -1219,6 +1238,12 @@
 
 		g_assert(ios != NULL);
 
+#if GTK_CHECK_VERSION(2,18,0)
+		gtk_widget_get_allocation(u_data->io->draw_area, &widget_alloc);
+#else
+		widget_alloc = u_data->io->draw_area->allocation;
+#endif
+
 		gdk_draw_pixmap(u_data->io->draw_area->window,
 #if GTK_CHECK_VERSION(2,18,0)
 		                u_data->io->draw_area->style->fg_gc[gtk_widget_get_state(u_data->io->draw_area)],
@@ -1228,8 +1253,8 @@
 		                ios->pixmap,
 		                0, 0,
 		                0, 0,
-		                u_data->io->draw_area->allocation.width,
-		                u_data->io->draw_area->allocation.height);
+		                widget_alloc.width,
+		                widget_alloc.height);
 
 		x1_tmp=(unsigned int)floor(u_data->io->min_x+((u_data->io->x_old-LEFT_BORDER-u_data->io->offset)*u_data->io->tmp_width/u_data->io->axis_width));
 		x2_tmp=(unsigned int)floor(u_data->io->min_x+((event->x-LEFT_BORDER-u_data->io->offset)*u_data->io->tmp_width/u_data->io->axis_width));
@@ -1377,6 +1402,11 @@
 			ios=(sctp_graph_t *)g_object_get_data(G_OBJECT(u_data->io->draw_area), "sctp_graph_t");
 			g_assert(ios != NULL);
 
+#if GTK_CHECK_VERSION(2,18,0)
+			gtk_widget_get_allocation(u_data->io->draw_area, &widget_alloc);
+#else
+			widget_alloc = u_data->io->draw_area->allocation;
+#endif
 			gdk_draw_pixmap(u_data->io->draw_area->window,
 #if GTK_CHECK_VERSION(2,18,0)
 			                u_data->io->draw_area->style->fg_gc[gtk_widget_get_state(u_data->io->draw_area)],
@@ -1386,8 +1416,8 @@
 			                ios->pixmap,
 			                0, 0,
 			                0, 0,
-			                u_data->io->draw_area->allocation.width,
-			                u_data->io->draw_area->allocation.height);
+			                widget_alloc.width,
+			                widget_alloc.height);
 		}
 	}
 	return TRUE;
Index: io_stat.c
===================================================================
--- io_stat.c	(revision 38117)
+++ io_stat.c	(working copy)
@@ -700,6 +700,7 @@
 	int label_width, label_height;
 	guint32 draw_width, draw_height;
 	char label_string[45];
+	GtkAllocation widget_alloc;
 
 	/* new variables */
 	guint32 num_time_intervals;
@@ -753,12 +754,17 @@
 	/*
 	 * Clear out old plot
 	 */
+#if GTK_CHECK_VERSION(2,18,0)
+	gtk_widget_get_allocation(io->draw_area, &widget_alloc);
+#else
+	widget_alloc = io->draw_area->allocation;
+#endif
 	gdk_draw_rectangle(io->pixmap,
 			   io->draw_area->style->white_gc,
 			   TRUE,
 			   0, 0,
-			   io->draw_area->allocation.width,
-			   io->draw_area->allocation.height);
+			   widget_alloc.width,
+			   widget_alloc.height);
 
 	/*
 	 * Calculate the y scale we should use
@@ -1392,18 +1398,24 @@
 	io_stat_t *io = user_data;
 	int i;
 	GtkWidget *save_bt;
+	GtkAllocation widget_alloc;
 
 	if(io->pixmap){
 		g_object_unref(io->pixmap);
 		io->pixmap=NULL;
 	}
 
+#if GTK_CHECK_VERSION(2,18,0)
+	gtk_widget_get_allocation(widget, &widget_alloc);
+#else
+	widget_alloc = widget->allocation;
+#endif
 	io->pixmap=gdk_pixmap_new(widget->window,
-			widget->allocation.width,
-			widget->allocation.height,
+			widget_alloc.width,
+			widget_alloc.height,
 			-1);
-	io->pixmap_width=widget->allocation.width;
-	io->pixmap_height=widget->allocation.height;
+	io->pixmap_width=widget_alloc.width;
+	io->pixmap_height=widget_alloc.height;
 
 	save_bt = g_object_get_data(G_OBJECT(io->window), "save_bt");
 	g_object_set_data(G_OBJECT(save_bt), "pixmap", io->pixmap);
@@ -1413,8 +1425,8 @@
 			widget->style->white_gc,
 			TRUE,
 			0, 0,
-			widget->allocation.width,
-			widget->allocation.height);
+			widget_alloc.width,
+			widget_alloc.height);
 
 	/* set up the colors and the GC structs for this pixmap */
 	for(i=0;i<MAX_GRAPHS;i++){
@@ -1647,6 +1659,7 @@
 	io_stat_t *io = user_data;
 	static gboolean advanced_visible=FALSE;
 	int i;
+	GtkAllocation widget_alloc;
 
 	io->count_type = gtk_combo_box_get_active (GTK_COMBO_BOX(item));
 
@@ -1655,11 +1668,16 @@
 			disable_graph(&io->graphs[i]);
 			gtk_widget_show(io->graphs[i].advanced_buttons);
 			/* redraw the entire window so the unhidden widgets show up, hopefully */
+#if GTK_CHECK_VERSION(2,18,0)
+			gtk_widget_get_allocation(io->window, &widget_alloc);
+#else
+			widget_alloc = io->window->allocation;
+#endif
 			gtk_widget_queue_draw_area(io->window,
 						   0,
 						   0,
-						   io->window->allocation.width,
-						   io->window->allocation.height);
+						   widget_alloc.width,
+						   widget_alloc.height);
 		}
 		advanced_visible=TRUE;
 		io_stat_redraw(io);