After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 343960 - duplicate gtk.Clipboard causing visit_decref error
duplicate gtk.Clipboard causing visit_decref error
Status: RESOLVED FIXED
Product: pygtk
Classification: Bindings
Component: gtk
2.6.x
Other All
: Normal critical
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
: 340133 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2006-06-05 23:32 UTC by Nathan French
Modified: 2006-07-13 11:05 UTC
See Also:
GNOME target: ---
GNOME version: 2.5/2.6



Description Nathan French 2006-06-05 23:32:08 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
Comment 1 John Finlay 2006-07-08 08:56:01 UTC
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.
Comment 2 Gustavo Carneiro 2006-07-08 11:49:14 UTC
(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
Comment 3 Gustavo Carneiro 2006-07-13 11:05:20 UTC
*** Bug 340133 has been marked as a duplicate of this bug. ***