Re: GET_SORT_COLUMN_ID segfault




On Dec 27, 2006, at 12:24 PM, Jens Luedicke wrote:

I get a segfault after returning in my
GET_SORT_COLUMN_ID method:

sub GET_SORT_COLUMN_ID {
        my ($self) = @_;
        return (TRUE, $self->{sort_column_id}, "$self->{sort_order}");
}

BT:

#0  0x40958687 in gtk2perl_tree_sortable_get_sort_column_id
(sortable=0x888c3d0, sort_column_id=0x0, order=0x0) at
GtkTreeSortable.xs:68

sort_column_id and order are return parameters, pointers to the location at which the values should be stored. The code in gtk2perl_tree_sortable_get_sort_column_id() expects them never to be NULL (because it doesn't make sense to call the function if you aren't going to get them), and is segfaulting when trying to dereference a null pointer. However, we should be more robust than that... In gtk+ HEAD, the code in gtk_tree_view_column_update_button () (frame #2 in your trace) looks like this:

  if (GTK_IS_TREE_SORTABLE (model))
    gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (model),
                                          &sort_column_id,
                                          NULL);

In other words, "give me the id, i don't care about the order."


I can see the fix in the code, but my sandbox is broken and i can't compile or test. Please try the patch below; if that works, i'll commit it.

Index: xs/GtkTreeSortable.xs
===================================================================
RCS file: /cvsroot/gtk2-perl/gtk2-perl-xs/Gtk2/xs/GtkTreeSortable.xs,v
retrieving revision 1.11
diff -u -r1.11 GtkTreeSortable.xs
--- xs/GtkTreeSortable.xs       28 Jun 2005 19:42:58 -0000      1.11
+++ xs/GtkTreeSortable.xs       27 Dec 2006 19:48:48 -0000
@@ -52,6 +52,8 @@
                                            GtkSortType     *order)
{
        gboolean retval = FALSE;
+       gint real_sort_column_id;
+       GtkSortType real_order;
        GET_METHOD ("GET_SORT_COLUMN_ID");
        if (METHOD_EXISTS) {
@@ -65,12 +67,17 @@
                SPAGAIN;
-               *order = SvGtkSortType (POPs);
-               *sort_column_id = POPi;
+               real_order = SvGtkSortType (POPs);
+               real_sort_column_id = POPi;
                retval = POPu;
                PUTBACK;
                FINISH;
+
+               if (sort_column_id)
+                       *sort_column_id = real_sort_column_id;
+               if (order)
+                       *order = real_order;
        }
        return retval;






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