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 401080 - Add a generic signal marshaller
Add a generic signal marshaller
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gobject
2.12.x
Other Linux
: Normal enhancement
: ---
Assigned To: Johan (not receiving bugmail) Dahlin
gtkdev
Depends on:
Blocks: 353816 567087
 
 
Reported: 2007-01-26 17:59 UTC by Johan (not receiving bugmail) Dahlin
Modified: 2011-06-20 15:03 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
g_cclosure_marshal_generic implementation using C/Invoke (6.88 KB, patch)
2007-01-28 02:32 UTC, Johan (not receiving bugmail) Dahlin
none Details | Review
test-invoke.c: libffi version (6.23 KB, patch)
2007-01-28 13:48 UTC, Johan (not receiving bugmail) Dahlin
none Details | Review
patch for gobject with tests included (15.49 KB, patch)
2007-01-30 13:23 UTC, Johan (not receiving bugmail) Dahlin
none Details | Review
v2 (15.59 KB, patch)
2008-02-16 13:32 UTC, Johan (not receiving bugmail) Dahlin
none Details | Review

Description Johan (not receiving bugmail) Dahlin 2007-01-26 17:59:19 UTC
Recently the GStreamer camp tried to prototype a new GObject class using a dynamic language binding (eg Python). The object written in Python would define properties and signals using the standard mechanism the language binding provides.
However, it could not easily be done because the Python bindings lacked a way to provide a signal marshaller for code written in C. 
  
PyGObject uses the following piece of code to create a new signal:

      signal_id = g_signal_newv(signal_name, instance_type, signal_flags,
                              pyg_signal_class_closure_get(),
                              accumulator, accum_data,
                              (GSignalCMarshaller)0,
                              return_type, n_params, param_types);

As you can see the c_marshaller is 0 and therefor applications in C will not be able to connect to that signal.

I propose adding a generic C marshaller using a library like libffi to GObject, that would allow C code to use signals written using a language binding.
Comment 1 Behdad Esfahbod 2007-01-26 18:21:52 UTC
Or C/Invoke, which seems to be a maintained replacement for libffi.

I hear Python uses a modified version of libffi maintained internally.  Maybe glib can do the same.
Comment 2 Johan (not receiving bugmail) Dahlin 2007-01-28 02:32:50 UTC
Created attachment 81343 [details] [review]
g_cclosure_marshal_generic implementation using C/Invoke

Attached is a generic CClosure marshal handler implemented using C/Invoke. 
Adopting the implementation to use libffi instead of cinvoke would be mostly trivial since there's a similar existing implementation of that in gobject-introspection/src/ginvoke.c

I can integrate the standalone program in glib if C/Invoke or libffi is an accepted as a dependency.
Comment 3 Johan (not receiving bugmail) Dahlin 2007-01-28 13:48:45 UTC
Created attachment 81376 [details] [review]
test-invoke.c: libffi version

Same as attachment 81343 [details] [review] but it uses libffi instead of C/Invoke.
Comment 4 Johan (not receiving bugmail) Dahlin 2007-01-30 13:23:33 UTC
Created attachment 81513 [details] [review]
patch for gobject with tests included
Comment 5 Bastien Nocera 2007-05-23 10:43:24 UTC
Shouldn't the presence/absence of FFI be advertised in glibconfig.h?
Comment 6 Behdad Esfahbod 2007-05-29 22:28:26 UTC
I suggest including libffi unconditionally inside glib.  Python has a copy, so it should be portable enough.
Comment 7 Johan (not receiving bugmail) Dahlin 2007-07-26 14:52:47 UTC
(In reply to comment #4)
> Created an attachment (id=81513) [edit]
> patch for gobject with tests included
> 

This patch is outdated; it doesn't handle return arguments.
PyGObject ships with an implmentation which handles that;
http://svn.gnome.org/viewcvs/pygobject/trunk/gobject/ffi-marshaller.c?revision=651&view=markup
Comment 8 John Stowers 2008-02-16 10:03:41 UTC
Perhaps this can be revisited now that libffi has made a stable 3.0 release

http://sourceware.org/ml/libffi-announce/2008/msg00001.html
Comment 9 Johan (not receiving bugmail) Dahlin 2008-02-16 13:32:45 UTC
Created attachment 105381 [details] [review]
v2

Attaching a new patch which is:
* Updated to trunk
* Using system libffi via pkg-config available in the new 3.0.x releases
* Updated copy of the marshaller which actually marshalls the return values.

The same libffi version has been included in pygobject for a while.
Comment 10 Behdad Esfahbod 2008-02-17 06:26:13 UTC
Exciting.  I think we should provide this and possibly some other API exposing libffi functionality unconditionally, probably using an internal copy if needed, like we do for pcre.
Comment 11 Johan (not receiving bugmail) Dahlin 2008-02-21 13:18:18 UTC
(In reply to comment #10)
> Exciting.  I think we should provide this and possibly some other API exposing
> libffi functionality unconditionally, probably using an internal copy if
> needed, like we do for pcre.
It would be better to just depend on libffi imho, the idea of the new 3.0  release was to reduce the number of external copies.

But perhaps there'll be another 10 years before the next release...

It's about 26k lines of code and 15ish supported platforms in the new release.
Comment 12 Johan (not receiving bugmail) Dahlin 2008-03-02 13:56:12 UTC
bug 496006 is related, allowing different linking options to libffi, which appears to be necessary on some systems.
Comment 13 Bastien Nocera 2008-07-31 10:44:29 UTC
+if HAVE_LIBFFI
+libgobject_2_0_la_LIBADD += $(LIBFFI_LIBS)
+libgobject_2_0_la_CFLAGS += $(LIBFFI_CFLAGS)
+endif

That's unnecessary, it doesn't need to be conditional. LIBFFI_LIBS and LIBFFI_CFLAGS will be empty if we didn't find a libffi in configure.

So you can remove that as well:
+AM_CONDITIONAL(HAVE_LIBFFI, $have_libffi)

I'd add a variable to gobject's pkg-config though, so applications can require a gobject with libffi support.

libffi is up to 3.0.6 [1], and the patch looks good. When can we get this in?

[1]: ftp://sourceware.org/pub/libffi/
Comment 14 Colin Walters 2008-10-02 18:25:20 UTC
Just a note, gobject-introspection will depend on libffi.  And my current Java bindings depend on JNA which depends on libffi.  And someone should fix the bug that Python comes with an internal libffi..
Comment 15 David Zeuthen (not reading bugmail) 2011-02-08 11:37:02 UTC
Any chance we can get this in? Thanks
Comment 16 Colin Walters 2011-02-08 16:14:15 UTC
(In reply to comment #13)
> +if HAVE_LIBFFI
> +libgobject_2_0_la_LIBADD += $(LIBFFI_LIBS)
> +libgobject_2_0_la_CFLAGS += $(LIBFFI_CFLAGS)
> +endif
> 
> That's unnecessary, it doesn't need to be conditional. LIBFFI_LIBS and
> LIBFFI_CFLAGS will be empty if we didn't find a libffi in configure.

Actually though, since this is something we expect infrastructure and apps to use, we can't just fail at runtime if it's not available or something.  Basically the whole thing needs to be a hard requirement.
Comment 17 Colin Walters 2011-06-20 15:03:51 UTC
commit 88ab35f3cb6127036361e421987a127bddb989c8
Author: David Zeuthen <davidz@redhat.com>
Date:   Fri Apr 8 17:34:44 2011 -0400

    Add a generic libffi based marshaller to libgobject
    
    This code is from https://bugzilla.gnome.org/show_bug.cgi?id=567087
    and was adapted by myself to also support the GVariant fundamental
    type.
    
    Signed-off-by: David Zeuthen <davidz@redhat.com>