GNOME Bugzilla – Bug 679876
No support for Vala's classes and interfaces
Last modified: 2015-02-07 16:47:38 UTC
If you create a Vala class or interface and its GIR packages using valac, they can't be used by GObject Introspection. I've defined a class as: namespace Foo { public class User : GLib.Object, Toplevel { public string name { get; set; } // Constructor public User () { } } } and an interface as: namespace Foo { public interface Toplevel : GLib.Object { public abstract string name { get; set; } } } >>>>>>> FIRST TRY: when you compile, create GIR/TYPELIB and install when using python to access that simple class/interface you'll get: >>>>> PYTHON TESTS: >>> from gi.repository import Foo >>> Foo.User Traceback (most recent call last):
+ Trace 230507
return getattr(self._introspection_module, name)
interfaces = tuple(interface for interface in get_interfaces_for_object(info)
interfaces.append(getattr(module, name))
wrapper = metaclass(name, bases, dict_)
register_interface_info(cls.__info__.get_g_type())
>>> >>> >>> Foo.Toplevel Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/dist-packages/gi/module.py", line 243, in __getattr__ return getattr(self._introspection_module, name) File "/usr/lib/python2.7/dist-packages/gi/module.py", line 180, in __getattr__ wrapper = metaclass(name, bases, dict_) File "/usr/lib/python2.7/dist-packages/gi/types.py", line 232, in __init__ register_interface_info(cls.__info__.get_g_type()) TypeError: must be an interface >>> There a problem in modlue.py to get correctly a Vala interface. >>> JAVASCRIPT TEST: gjs> var Foo = imports.gi.Foo; typein:1: strict warning: reference to undefined property imports.gi typein:1: strict warning: reference to undefined property imports.gi typein:1: strict warning: reference to undefined property imports.gi typein:1: strict warning: reference to undefined property imports.gi typein:1: strict warning: reference to undefined property imports.gi typein:1: strict warning: reference to undefined property imports.gi typein:1: strict warning: reference to undefined property imports.gi typein:1: strict warning: reference to undefined property imports.gi typein:1: strict warning: reference to undefined property imports.gi typein:1: strict warning: reference to undefined property imports.gi.Foo typein:1: strict warning: reference to undefined property imports.gi.Foo typein:1: strict warning: reference to undefined property imports.gi.Foo gjs> Foo.User Error: Unsupported type void, deriving from fundamental void gjs> Foo.Toplevel typein:3: strict warning: reference to undefined property Foo.Toplevel typein:3: strict warning: reference to undefined property Foo.Toplevel function _private_Foo_Toplevel() { [native code] } gjs> var u = new Foo.User(); Error: Unsupported type void, deriving from fundamental void gjs> >>>>>>> SECOND TRY: Now if I remove Toplevel interface implementation in User class, compile and install I'll get >>>>> PYTHON TESTS: Python 2.7.3 (default, Apr 20 2012, 22:39:59) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from gi.repository import Foo >>> Foo.User <class 'gi.repository.Foo.User'> >>> u = Foo.User() __main__:1: Warning: cannot retrieve class for invalid (unclassed) type `void' Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: could not get a reference to type class >>> Foo.Toplevel Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/dist-packages/gi/module.py", line 243, in __getattr__ return getattr(self._introspection_module, name) File "/usr/lib/python2.7/dist-packages/gi/module.py", line 180, in __getattr__ wrapper = metaclass(name, bases, dict_) File "/usr/lib/python2.7/dist-packages/gi/types.py", line 232, in __init__ register_interface_info(cls.__info__.get_g_type()) TypeError: must be an interface >>> >>>>> JAVASCRIPT TESTS: gjs> var Foo = imports.gi.Foo; typein:1: strict warning: reference to undefined property imports.gi typein:1: strict warning: reference to undefined property imports.gi typein:1: strict warning: reference to undefined property imports.gi typein:1: strict warning: reference to undefined property imports.gi typein:1: strict warning: reference to undefined property imports.gi typein:1: strict warning: reference to undefined property imports.gi typein:1: strict warning: reference to undefined property imports.gi typein:1: strict warning: reference to undefined property imports.gi typein:1: strict warning: reference to undefined property imports.gi typein:1: strict warning: reference to undefined property imports.gi.Foo typein:1: strict warning: reference to undefined property imports.gi.Foo typein:1: strict warning: reference to undefined property imports.gi.Foo gjs> Foo.User Error: Unsupported type void, deriving from fundamental void gjs> var u = new Foo.User(); Error: Unsupported type void, deriving from fundamental void gjs> Foo.Toplevel typein:4: strict warning: reference to undefined property Foo.Toplevel typein:4: strict warning: reference to undefined property Foo.Toplevel function _private_Foo_Toplevel() { [native code] } gjs>
Created attachment 218753 [details] Complete test case tarball This is the complete test project I have to create in order to reproduce this bug report.
Created attachment 222687 [details] Test case tarball fixed build I've fixed some build issues and make dist a new version set to 0.1.1, if any one want to use it. I've tested against vala 0.17.5 but still doesn't work.
After installed libfoo-0.1.1 version, I found that I can't see the type of Toplevel Interface, may be this interface is never registered before its use: Python 2.7.3 (default, Aug 1 2012, 05:14:39) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from gi.repository import Foo >>> Foo.User <class 'gi.repository.Foo.User'> >>> Foo.Toplevel Traceback (most recent call last):
+ Trace 230745
>>> Foo.Toplevel.get_g_type() Traceback (most recent call last):
>>> Foo.Toplevel.get_type() Traceback (most recent call last):
I've installed Vala 0.17.5 with libgee-0.7.90, to test Gee interfaces against this bug and found that Traversable is not defined in Gee package even when it is declared in GIR file: Python 2.7.3 (default, Aug 1 2012, 05:14:39) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from gi.repository import Gee >>> Gee.Traversable Traceback (most recent call last):
+ Trace 230746
self.__name__, name))
I've found the problem! GObject Introspection compiler needs the *.so.* shared library in order to find the required interfaces and other objects. The solution was found in Bugs #658002 and Bug #585116, by adding the following code to your project in Vala to GObject Introspection: At Makefile.am you should have (from http://git.gnome.org/browse/folks/tree/folks/Makefile.am): # We have to extract our own dlname from libfolks.la; see bgo#658002. # This is what g-ir-scanner does. libfolks_dlname = \ `$(SED) -n "s/^dlname='\([A-Za-z0-9.+-]\+\)'/\1/p" libfolks.la` INTROSPECTION_COMPILER_ARGS = -l $(libfolks_dlname) Definition to libfolks_dlname is the magic and add it to introspection compiler arguments with -l switch. Replace libfolks.la with the .la file name used in your project. Make this more easy will be necessary, but that is another bug report.
Hi Daniel, (In reply to comment #5) > Make this more easy will be necessary, but that is another bug report. I'm curious, have you reported this bug you talk about?
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]