GNOME Bugzilla – Bug 343960
duplicate gtk.Clipboard causing visit_decref error
Last modified: 2006-07-13 11:05:20 UTC
Steps to reproduce: I have a little utility that has a couple classes that do this in their constructors: self.clipboard = gtk.Clipboard() I'm on GTK 2.6 so I'm assuming I can call this with no arguments like the documentation claims. I get this error in a deterministic fashion: python: Modules/gcmodule.c:275: visit_decref: Assertion `gc->gc.gc_refs> != 0' failed. If I switch to instead have only one instance of gtk.Clipboard and pass it into the classes that need clipboard functionality the problem goes away. Without getting off my butt and looking at how PyGTK works I'm going to go out on a limb here and say there is a reference counting problem with the clipboard extension. Stack trace: Other information: Here's some details on my system below. Basically just a stock FC4 install with GTK 2.6 (we have another machine which is FC3 that exhibits the same issue). Python 2.4.1 (#1, May 16 2005, 15:19:29) [GCC 4.0.0 20050512 (Red Hat 4.0.0-5)] on linux2 [root@localhost ~]# rpm -qa | grep gtk usermode-gtk-1.80-1 gtkhtml2-2.6.3-1 gnome-python2-gtkhtml2-2.10.0-2.1 gtk+-1.2.10-39 pygtk2-devel-2.6.0-2 pygtk2-libglade-2.6.0-2 gtk2-engines-2.6.3-2 gtkhtml3-3.6.2-1 gtksourceview-1.2.0-1 gtk2-devel-2.6.7-4 gtk-doc-1.3-2 gtk2-2.6.7-4 pygtk2-2.6.0-2 authconfig-gtk-4.6.12-1 gtkspell-2.0.7-3 gtk-engines-0.12-7
It seems that the GTK+ clipboard objects are owned and managed by GTK+ and therefore the Clipboard() constructor creates an object with a __grefcount__ of 1. When the PyGTK Clipboard object is finalized it decrements the GObject clipboard ref count which leads to the attempt to finalize it. This is the error. By comparison if the clipboard is created using the clipboard_get() function which uses pygobject_new() the resulting object has a __grefcount__ of 2. Any subsequent calls just return the existing wrapper and the __grefcount__ remains at 2. To fix the refcount problem a couple of possibilities are: disable the constructor and replace it with a function - clipboard_get_for_display(); or, add an additional g_object_ref() in the constructor.
(In reply to comment #1) > To fix the refcount problem a couple of possibilities are: disable the > constructor and replace it with a function - clipboard_get_for_display(); or, > add an additional g_object_ref() in the constructor. > Fixed with the latter approach: http://cvs.gnome.org/viewcvs/gnome-python/pygtk/gtk/gtk-base.defs?r1=1.5&r2=1.6
*** Bug 340133 has been marked as a duplicate of this bug. ***