Re: custom cell renderer start_editing refcount

Torsten Schoenfeld <kaffeetisch gmx de> writes:

Then I guess I'm asking for a complete inspection by the QA department. :-)

Well the amount of Q in most QA departments probably means they put it
through "wc" then make a 30-page report about how many lines the files

set_cursor() with a bool argument that starts editing.

I'll try to have a go at that.

And since the generated object handling macros are part of our public
API, we can't just change newSVGtkCellEditable, I think.

I guess sinking where it didn't sink before might upset someone's
assumptions.  I suppose it's a case of which is worse, a GInterface
object not wrapped the same as other interfaced objects, or a widget not
wrapped the same as SVGtkWidget :-)

How about leaving the macros alone but changing GtkCellRenderer.xs along
the lines below (the only two places returning GtkCellEditable)?

Index: GtkCellRenderer.xs
--- GtkCellRenderer.xs  (revision 2104)
+++ GtkCellRenderer.xs  (working copy)
@@ -1,5 +1,5 @@
- * Copyright (c) 2003-2004 by the gtk2-perl team (see the file AUTHORS)
+ * Copyright (c) 2003-2004, 2009 by the gtk2-perl team (see the file AUTHORS)
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -540,8 +540,25 @@
        GdkRectangle         * cell_area
        GtkCellRendererState   flags
+## gtk_cell_renderer_start_editing() is normally a constructor,
+## returning a widget with a floating ref ready for the caller to take
+## over.  But the typemap for GtkCellEditable as a GInterface only
+## assumes GObject, it doesn't sink that ref when making the perl
+## wrapper.  So cast up to GtkWidget.  GtkWidget is a requirement of
+## GtkCellEditable, so "editable" is certain to be a widget.
+## The returned widget is normally about to be put in a container and
+## that would sink any floating ref anyway, but sink it now to follow
+## the general rule that wrapped widgets at the perl level don't have
+## a floating ref left.  (In particular this means if you
+## start_editing() and then strike an error it won't be a memory
+## leak.)
 ##GtkCellEditable* gtk_cell_renderer_start_editing (GtkCellRenderer *cell, GdkEvent *event, GtkWidget 
*widget, const gchar *path, GdkRectangle *background_area, GdkRectangle *cell_area, GtkCellRendererState 
-GtkCellEditable_ornull *
+=for apidoc
+=for signature celleditable or undef = $cell->start_editing ($event, $widget, $path, $background_area, 
$cell_area, $flags)
+GtkWidget_ornull *
 gtk_cell_renderer_start_editing (cell, event, widget, path, background_area, cell_area, flags)
        GtkCellRenderer      * cell
        GdkEvent             * event
@@ -550,6 +567,13 @@
        GdkRectangle         * background_area
        GdkRectangle         * cell_area
        GtkCellRendererState   flags
+       GtkCellEditable *editable;
+       editable = gtk_cell_renderer_start_editing (cell, event, widget, path, background_area, cell_area, 
+       RETVAL = GTK_WIDGET (editable);
+       RETVAL
 #if GTK_CHECK_VERSION (2, 4, 0)
@@ -757,7 +781,12 @@
                                                                SvGdkRectangle_ornull (ST (5)),
                                                                SvGtkCellRendererState (ST (6)));
                        EXTEND (SP, 1);
-                       PUSHs (sv_2mortal (newSVGtkCellEditable_ornull (editable)));
+                       /* Note newSVGtkWidget here instead of
+                        * newSVGtkCellEditable so as to take ownership of
+                        * any floating ref.  See comments with
+                        * gtk_cell_renderer_start_editing() above.
+                        */
+                       PUSHs (sv_2mortal (newSVGtkWidget_ornull (GTK_WIDGET (editable))));

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