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 707140 - 3.9.x regression
3.9.x regression
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: general
Git master
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2013-08-30 16:34 UTC by Christoph Reiter (lazka)
Modified: 2013-09-02 05:04 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Change boxed type checking in marshaling to use __gtype__ attribute (3.32 KB, patch)
2013-09-02 04:24 UTC, Simon Feltman
committed Details | Review

Description Christoph Reiter (lazka) 2013-08-30 16:34:52 UTC
The following used to work in 3.8, doesn't anymore with trunk. Removing the __gsignals__ fixes it.

__gsignals__ is left over from pygtk and afaik isn't needed anymore I guess (was that always the case in pygi?)

It's only bad because it breaks code that used to work.

###############################################

from gi.repository import Gtk

class Foo(Gtk.ScrolledWindow):
    __gsignals__ = {'size-allocate': 'override'}

    def do_size_allocate(self, alloc):
        print alloc
        return Gtk.ScrolledWindow.do_size_allocate(self, alloc)


win = Gtk.Window()
win.connect("delete-event", Gtk.main_quit)
foo = Foo()
win.add(foo)
win.show_all()
Gtk.main()
Comment 1 Simon Feltman 2013-08-31 03:43:41 UTC
Using __gsignals__ is not (yet) deprecated and should work for the whole 3.x series. The decorator technique actually relies on it.

The following is printed for me when running the example:

<GdkRectangle at 0x7fff74211d40>
Traceback (most recent call last):
  • File "bugs/707140.py", line 9 in do_size_allocate
    return Gtk.ScrolledWindow.do_size_allocate(self, alloc)
TypeError: wrong boxed type

Things are a bit confusing because "size_allocate" is both a signal and a vfunc. PyGObject seems to use the "do_" prefix for both signal overrides and vfuncs.

I didn't look into this too deeply and the actual problem is still unclear. Some basic investigation: if you connect a discreet "size-allocate' signal and print the alloc argument, it will show up as a cairo.RectangleInt, whereas I'm pretty sure the vfunc override will print as a GdkRectangle/GtkAllocation (all of these are typedefs of cairo.RectangleInt, so it is also possible something is broken with annotations).
Comment 2 Simon Feltman 2013-08-31 04:03:06 UTC
Additional debugging info when printing with:

print(alloc, alloc.__gtype__)

signal override: <GdkRectangle at ...>      <GType CairoRectangleInt (38811360)>
signal handler:  <CairoRectangleInt at ...> <GType CairoRectangleInt (38811360)>
vfunc override:  <CairoRectangleInt at ...> <GType CairoRectangleInt (38811360)>

This shows we are at least getting the correct gtype (CairoRectangleInt) in the various cases. It looks like marshaling refactoring work probably broke this by becoming a bit stricter.
Comment 3 Simon Feltman 2013-08-31 04:34:03 UTC
The stricter type checking was initially added with:
https://git.gnome.org/browse/pygobject/commit/?id=635a7d1b

This made its way into marshaling unification with:
https://git.gnome.org/browse/pygobject/commit/?id=6d3a0751
Comment 4 Simon Feltman 2013-08-31 06:27:19 UTC
The root cause of this seems to be a type discrepancy due to gtk_widget_size_allocate (and its vfunc) defined as using GtkAllocation:
https://git.gnome.org/browse/gtk+/tree/gtk/gtkwidget.c?id=3.8.4#n5206

And the signals argument type is defined using GDK_TYPE_RECTANGLE:
https://git.gnome.org/browse/gtk+/tree/gtk/gtkwidget.c?id=3.8.4#n1597

This is described in bug #683463

We seem to be getting the same gtype back for signal overrides as vfunc so it is still not clear as to why this is failing.
Comment 5 Simon Feltman 2013-09-02 04:24:19 UTC
Created attachment 253802 [details] [review]
Change boxed type checking in marshaling to use __gtype__ attribute

Replace usage of pyg_boxed_check(pyboxed) with g_type_is_a and
pyg_type_from_object. This has the effect of using the __gtype__
attribute stashed on object class instead of the PyGBoxed
internally held gtype. This fixes type descrepencies for objects
marshaled into overridden signal class closures and passed back
to functions taking an alias their type.
Comment 6 Martin Pitt 2013-09-02 05:01:52 UTC
Comment on attachment 253802 [details] [review]
Change boxed type checking in marshaling to use __gtype__ attribute

Thanks!
Comment 7 Simon Feltman 2013-09-02 05:04:24 UTC
Attachment 253802 [details] pushed as 19c1a2d - Change boxed type checking in marshaling to use __gtype__ attribute