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 616674 - Vfuncs require me to implement methods that shouldn't be required
Vfuncs require me to implement methods that shouldn't be required
Status: RESOLVED FIXED
Product: pygi
Classification: Deprecated
Component: general
unspecified
Other Linux
: Normal normal
: 0.6
Assigned To: pygi-maint
pygi-maint
Depends on:
Blocks:
 
 
Reported: 2010-04-23 19:38 UTC by johnp
Modified: 2010-04-28 17:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Dont force to implement all vfuncs of its bases, only when the base is an interface (1.60 KB, patch)
2010-04-26 14:21 UTC, Tomeu Vizoso
none Details | Review
[PATCH] add the GenericTreeModel override and the GtkBuilder override (4.00 KB, patch)
2010-04-26 19:37 UTC, johnp
none Details | Review
Test for gtkbuilder (289 bytes, text/plain)
2010-04-26 19:39 UTC, johnp
  Details
ui test file (604 bytes, text/plain)
2010-04-26 19:42 UTC, johnp
  Details
[PATCH] if the method is not overridden by the user, don't set vfunc to None (637 bytes, patch)
2010-04-26 21:34 UTC, johnp
needs-work Details | Review
Dont force subclasses to implement all virtual methods of their bases (2.46 KB, patch)
2010-04-27 08:25 UTC, Tomeu Vizoso
committed Details | Review

Description johnp 2010-04-23 19:38:04 UTC
With the latest from git adding an override for GtkBuilder 

class Builder(Gtk.Builder):
    def connect_signals(self, obj_or_map):
       .
       .
       .

causes this error when running a pygi app

Traceback (most recent call last):
  • File "./d-feet", line 44 in <module>
    import dfeet.DFeetApp as DFeetApp
  • File "/home/johnp/devel/gnome-shell/source/d-feet/dfeet/DFeetApp.py", line 3 in <module>
    from gi.repository import Gtk
  • File "/home/johnp/devel/gnome-shell/install/lib64/python2.6/site-packages/gtk-2.0/gi/importer.py", line 71 in load_module
    overrides_modules = __import__('gi.overrides', fromlist=[namespace])
  • File "/home/johnp/devel/gnome-shell/install/lib64/python2.6/site-packages/gtk-2.0/gi/overrides/Gtk.py", line 173 in <module>
    class Builder(Gtk.Builder):
  • File "/home/johnp/devel/gnome-shell/install/lib64/python2.6/site-packages/gtk-2.0/gi/types.py", line 129 in __init__
    cls._setup_vfuncs()
  • File "/home/johnp/devel/gnome-shell/install/lib64/python2.6/site-packages/gtk-2.0/gi/types.py", line 106 in _setup_vfuncs
    vfunc_info.get_name()))
TypeError: Class implementing Gtk.Builder should implement the method do_get_type_from_name()

I've never had to override that method before and am not sure how I would.  

Another point is that vfuncs in pygtk use the on_ prefix not the do_ prefix.  This causes issues with my implementation of GenericTreeModel which requires a number of vfuncs to be implemented.
Comment 1 Johan (not receiving bugmail) Dahlin 2010-04-23 19:40:18 UTC
Overrides classes shouldn't be proper subclasses as in they shouldn't register a GType.
Comment 2 Tomeu Vizoso 2010-04-26 08:32:18 UTC
(In reply to comment #0)
> I've never had to override that method before and am not sure how I would.

True, this restriction should only apply when implementing an interface, not when inheriting from a class with vfuncs.

> Another point is that vfuncs in pygtk use the on_ prefix not the do_ prefix.

Hmm, what I guess happens is that vfuncs that are event handlers use the on_ prefix, and the rest of vfuncs use do_. I'm not sure how we could know that a vfunc is one or the other without adding one more annotation.
Comment 3 Tomeu Vizoso 2010-04-26 14:21:13 UTC
Created attachment 159601 [details] [review]
Dont force to implement all vfuncs of its bases, only when the base is an interface
Comment 4 johnp 2010-04-26 15:41:36 UTC
We still have an issue with the GenericTreeModel in the override file. It still gets registered and then fails because we are not implementing the vfuncs.  Note that it doesn't get the override decorator to fix a previous bug.
Comment 5 johnp 2010-04-26 19:37:34 UTC
Created attachment 159634 [details] [review]
[PATCH] add the GenericTreeModel override and the GtkBuilder override

 gi/overrides/Gtk.py |  111 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 110 insertions(+), 1 deletions(-)
Comment 6 johnp 2010-04-26 19:39:27 UTC
Created attachment 159635 [details]
Test for gtkbuilder

This doesn't currently work after the vfunc changes were added
Comment 7 johnp 2010-04-26 19:42:45 UTC
Created attachment 159636 [details]
ui test file
Comment 8 johnp 2010-04-26 19:52:21 UTC
I don't know if we want a separate bug but it seems related since the test I attached used to work until the vfunc code was added.  It looks like we are getting back invalid type data when loading widgets from a ui file.

Attached is the patch for the Gtk.py override file and a python test along with the ui file.  I am getting this error when running the test with all patches in this bug applied:

/home/johnp/devel/gnome-shell/install/lib64/python2.6/site-packages/gtk-2.0/gi/types.py:109: Warning: cannot unreference class of invalid (unclassed) type `GtkTreeModel'
  vfunc)
TypeError: 'NoneType' object is not callable
/home/johnp/devel/gnome-shell/install/lib64/python2.6/site-packages/gtk-2.0/gi/types.py:40: Warning: cannot retrieve class for invalid (unclassed) type `(null)'
  return info.invoke(*args)
**
Gtk:ERROR:gtkbuilder.c:259:gtk_builder_get_parameters: assertion failed: (oclass != NULL)
Aborted (core dumped)

It seems we are trashing the stack somewhere because the types.py warning sometimes comes back with a type name instead of (null).

Another interesting point is the TypeError:'NoneType' comes back when we execute gtk_builder_get_type_from_name in gtk/gtkbuilder.c.  On the line which reads   return GTK_BUILDER_GET_CLASS (builder)->get_type_from_name (builder, type_name); we should be executing gtk_builder_real_get_type_from_name which the vfunc is set to.  It never gets there.  This leads me to believe we are failing at GTK_BUILDER_GET_CLASS (builder).

I have written a C test that does the same thing as the python test and it works without an issue.  Also if I take out the builder override the widgets do show up but then we lose the connect_signals override so no signals are connected.
Comment 9 johnp 2010-04-26 21:08:05 UTC
Ah, ha.  Tracked it down.  GTK_BUILDER_GET_CLASS (builder) works fine.  I edited the Gtk code to make it easier to debug.  Apparently we are still overriding vfuncs on overridden classes even if there is an internal default.

Breakpoint 1, IA__gtk_builder_get_type_from_name (builder=0x6ec2d0, type_name=
    0x7e3d10 "GtkWindow") at gtkbuilder.c:1598

with override:
(gdb) p bc->get_type_from_name
(GType (*)(GtkBuilder *, const char *)) 0x7ffff7fef010

without override:
(gdb) p bc->get_type_from_name
$1 = (GType (*)(GtkBuilder *, const char *)) 
    0x7fffed8e9f02 <gtk_builder_real_get_type_from_name>
Comment 10 johnp 2010-04-26 21:34:57 UTC
Created attachment 159644 [details] [review]
[PATCH] if the method is not overridden by the user, don't set vfunc to None


* in the case where we have a class which has a vfunc which may already be
  implemented on the C level, we do not want to replace this with a None
  object.  In fact in the case where vfunc (the user supplied vfunc)
  evaluates to None, we never want to set the class vfunc to None
  because None is not a callable object and will throw an error
  when the vfunc is invoked
---
 gi/types.py |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Comment 11 Tomeu Vizoso 2010-04-27 07:41:43 UTC
Review of attachment 159644 [details] [review]:

I'm very confused by this, no matter how many times I read the code, I don't see how this patch could have any effect.

In any case, could you add a test case?
Comment 12 Tomeu Vizoso 2010-04-27 07:42:55 UTC
Review of attachment 159644 [details] [review]:

Ah, gotcha, this patch applies on top of my previous patch, I see where's the issue now. Will add a test case myself.
Comment 13 Tomeu Vizoso 2010-04-27 08:25:09 UTC
Created attachment 159676 [details] [review]
Dont force subclasses to implement all virtual methods of their bases
Comment 14 johnp 2010-04-28 15:11:28 UTC
Review of attachment 159676 [details] [review]:

Looks good.  Only suggestion would be to add a test object that does override the default to make sure it can still do that (though that test may already be somewhere else).
Comment 15 Tomeu Vizoso 2010-04-28 16:51:01 UTC
(In reply to comment #14)
> Review of attachment 159676 [details] [review]:
> 
> Looks good.  Only suggestion would be to add a test object that does override
> the default to make sure it can still do that (though that test may already be
> somewhere else).

Yup, that is tested some lines above.
Comment 16 Tomeu Vizoso 2010-04-28 16:51:59 UTC
Comment on attachment 159676 [details] [review]
Dont force subclasses to implement all virtual methods of their bases

Attachment 159676 [details] pushed as 1d9c6b6 - Dont force subclasses to implement all virtual methods of their bases