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 679876 - No support for Vala's classes and interfaces
No support for Vala's classes and interfaces
Status: RESOLVED NOTABUG
Product: gobject-introspection
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2012-07-13 17:11 UTC by Daniel Espinosa
Modified: 2015-02-07 16:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Complete test case tarball (332.02 KB, application/x-gzip)
2012-07-13 19:44 UTC, Daniel Espinosa
Details
Test case tarball fixed build (332.79 KB, application/x-gzip)
2012-08-28 22:25 UTC, Daniel Espinosa
Details

Description Daniel Espinosa 2012-07-13 17:11:33 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):
  • 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 154 in __getattr__
    interfaces = tuple(interface for interface in get_interfaces_for_object(info)
  • File "/usr/lib/python2.7/dist-packages/gi/module.py", line 83 in get_interfaces_for_object
    interfaces.append(getattr(module, name))
  • 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
>>> 
>>> 
>>> 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>
Comment 1 Daniel Espinosa 2012-07-13 19:44:51 UTC
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.
Comment 2 Daniel Espinosa 2012-08-28 22:25:03 UTC
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.
Comment 3 Daniel Espinosa 2012-08-28 22:30:33 UTC
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):
  • 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
>>> Foo.Toplevel.get_g_type()
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
>>> Foo.Toplevel.get_type()
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

Comment 4 Daniel Espinosa 2012-08-28 22:32:01 UTC
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):
  • 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 105 in __getattr__
    self.__name__, name))
AttributeError: 'gi.repository.Gee' object has no attribute 'Traversable'

Comment 5 Daniel Espinosa 2012-10-18 23:30:52 UTC
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.
Comment 6 Andrés G. Aragoneses (IRC: knocte) 2013-04-22 22:39:32 UTC
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?
Comment 7 André Klapper 2015-02-07 16:47:38 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]