Re: [PATCH] Don't multiply by -1 when assigning memory



On Thu, 2006-01-05 at 18:43 +0800, James Henstridge wrote:
> Rodrigo Moya wrote:
> 
> >>What Matthias is saying is that in the case of zero args, you don't need
> >>to allocate the full size of GtkBindingSignal: you don't need to
> >>GtkBindingArg embedded at the end of the struct.  So the correct answer
> >>would probably be:
> >>  sizeof (GtkBindingSignal) + n_args * sizeof (GtkBindingArg) - sizeof
> >>(GtkBindingArg)
> >>    
> >>
> >hmm, but if I understand it correctly, this would yield an invalid value
> >when n_args = 0, since it would be:
> >
> >sizeof (GtkBindingSignal) + 0 * sizeof (GtkBindingArg) - sizeof
> >(GtkBindingArg)
> >
> >which will be:
> >
> >sizeof (GtkBindingSignal) + sizeof (GtkBindingArg)
> >  
> >
> It would actually be:
>     sizeof (GtkBindingSignal) - sizeof (GtkBindingArg)
> 
yes, sorry, mistyped it.

> >is that what we want?
> >  
> >
> Yes.  That allocates enough space for everything except the 1-element
> GtkBindingArg array at the end of the structure, which is not a problem
> if n_args is 0.
> 
ok, patch attached
-- 
Rodrigo Moya <rodrigo gnome-db org>
? gdk/quartz/Makefile
? gdk/quartz/Makefile.in
? tests/floatingtest
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/ChangeLog,v
retrieving revision 1.7394
diff -u -p -r1.7394 ChangeLog
--- ChangeLog	5 Jan 2006 06:28:57 -0000	1.7394
+++ ChangeLog	5 Jan 2006 11:20:29 -0000
@@ -1,3 +1,8 @@
+2006-01-05  Rodrigo Moya <rodrigo novell com>
+
+	* gtk/gtkbindings.c (binding_signal_new): allocate correct amount for
+	signal and arguments.
+
 2006-01-05  Matthias Clasen  <mclasen redhat com>
 
 	* gtk/gtklabel.c (gtk_label_grab_focus): Don't return a value from
Index: gtk/gtkbindings.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkbindings.c,v
retrieving revision 1.51
diff -u -p -r1.51 gtkbindings.c
--- gtk/gtkbindings.c	5 Jan 2006 04:21:09 -0000	1.51
+++ gtk/gtkbindings.c	5 Jan 2006 11:20:30 -0000
@@ -64,8 +64,8 @@ binding_signal_new (const gchar *signal_
 		    guint	 n_args)
 {
   GtkBindingSignal *signal;
-  
-  signal = (GtkBindingSignal *) g_slice_alloc0 (sizeof (GtkBindingSignal) + n_args * sizeof (GtkBindingArg));
+
+  signal = (GtkBindingSignal *) g_slice_alloc0 (sizeof (GtkBindingSignal) + n_args * sizeof (GtkBindingArg) - sizeof (GtkBindingArg));
   signal->next = NULL;
   signal->signal_name = (gchar *)g_intern_string (signal_name);
   signal->n_args = n_args;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]