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 668902 - FFI calls broken on big endian architectures
FFI calls broken on big endian architectures
Status: RESOLVED FIXED
Product: gobject-introspection
Classification: Platform
Component: general
unspecified
Other Linux
: Normal major
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2012-01-28 12:32 UTC by Michel Dänzer
Modified: 2015-02-07 16:56 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Properly convert values between glib and FFI (11.18 KB, patch)
2012-01-28 12:32 UTC, Michel Dänzer
reviewed Details | Review
Michel's patch in git format-patch format (11.53 KB, patch)
2012-02-16 16:48 UTC, Colin Walters
none Details | Review
repository: Fix conversion of FFI values on big-endian architectures (11.12 KB, patch)
2012-02-16 21:46 UTC, Colin Walters
committed Details | Review
repository: Add new public gi_type_info_extract_ffi_return_value() API (2.91 KB, patch)
2012-02-16 22:01 UTC, Colin Walters
committed Details | Review
repository: Remove extraneous leftover assignment to rvalue. (890 bytes, patch)
2012-03-08 12:29 UTC, Michel Dänzer
committed Details | Review

Description Michel Dänzer 2012-01-28 12:32:48 UTC
Created attachment 206320 [details] [review]
Properly convert values between glib and FFI

The attached patch is adapted from the fixes for gjs bug 665152. It makes sure values are properly converted between glib and FFI, which is critical for big endian architectures.
Comment 1 Michel Dänzer 2012-01-28 12:38:47 UTC
This patch and the patch from pygobject bug 668903 together allow
running gnome-tweak-tool on PPC.
Comment 2 Michel Dänzer 2012-02-10 08:52:33 UTC
I see gobject-introspection 1.31.10 was released without these fixes. Can they be considered for the next release?
Comment 3 Colin Walters 2012-02-10 23:34:27 UTC
Review of attachment 206320 [details] [review]:

Hi Michel, thanks a lot for doing this!

::: gobject-introspection-1.31.1.orig/girepository/ginvoke.c
@@ +101,3 @@
+    float    rv_float;
+    double   rv_double;
+};

Can we avoid duplicating this structure at least?  Either add a new internal header, or we could conceivably make it public (and actually export a shared API to extract FFI return values that gjs could use too).

@@ +179,3 @@
       break;
+  case G_TYPE_BOOLEAN:
+      g_value_set_boolean (gvalue, (gboolean)value->rv_ffi_arg);

gboolean is a typedef for int, so this should be rv_ffi_sarg, right?  In practice it shouldn't matter though.

@@ +209,3 @@
       break;
+  case G_TYPE_BOXED:
+      g_value_set_boxed (gvalue, (gpointer)value->rv_ffi_sarg);

This should be consistent with G_TYPE_POINTER.  I'd use rv_ffi_arg.
Comment 4 Michel Dänzer 2012-02-14 09:53:35 UTC
(In reply to comment #3)
> ::: gobject-introspection-1.31.1.orig/girepository/ginvoke.c
> @@ +101,3 @@
> +    float    rv_float;
> +    double   rv_double;
> +};
> 
> Can we avoid duplicating this structure at least?  Either add a new internal
> header, or we could conceivably make it public (and actually export a shared
> API to extract FFI return values that gjs could use too).

I made a minimal adaptation of the gjs fix. I don't have the time or particular interest in getting involved in glib development beyond that. Feel free to fix the problem any way you like.


> @@ +179,3 @@
>        break;
> +  case G_TYPE_BOOLEAN:
> +      g_value_set_boolean (gvalue, (gboolean)value->rv_ffi_arg);
> 
> gboolean is a typedef for int, so this should be rv_ffi_sarg, right?

You're probably right.
Comment 5 Colin Walters 2012-02-16 16:46:08 UTC
(In reply to comment #4)
> (In reply to comment #3)
> > ::: gobject-introspection-1.31.1.orig/girepository/ginvoke.c
> > @@ +101,3 @@
> > +    float    rv_float;
> > +    double   rv_double;
> > +};
> > 
> > Can we avoid duplicating this structure at least?  Either add a new internal
> > header, or we could conceivably make it public (and actually export a shared
> > API to extract FFI return values that gjs could use too).
> 
> I made a minimal adaptation of the gjs fix. I don't have the time 

Fair enough.

> or particular
> interest 

But it's GNOME!  It's cool!  Join our club! =)

> Feel free to fix the problem any way you like.

It's not about "like" so much here as weighing the benefit of working on PPC64 versus long-term code maintenance etc.  

One thing I just realized is there is *another* copy of ffi->GValue code inside glib/gobject/gclosure.c =(

So...it's actually kind of tempting to change gobject-introspection to just call g_cclosure_marshal_generic() and not have it deal with FFI at all.  Then everything goes through the GValue conversion path.  That would be a pretty invasive change though.

One thing that occurs to me is that we could probably just reuse the "union _GIArgument" we already have instead of making up a new one.
Comment 6 Colin Walters 2012-02-16 16:48:51 UTC
Created attachment 207791 [details] [review]
Michel's patch in git format-patch format

Replacing bare patch with one with correct git attribution etc.
Comment 7 Colin Walters 2012-02-16 21:46:29 UTC
Created attachment 207813 [details] [review]
repository: Fix conversion of FFI values on big-endian architectures

Adapted from the fixes for (see bug 665152). It makes sure values are
properly converted between glib and FFI, which is critical for big
endian architectures.

Patch adjusted to use GIArgument instead of custom union types
by Colin Walters <walters@verbum.org>
Comment 8 Colin Walters 2012-02-16 21:48:41 UTC
Michel, can you test this patch?  It's a modified version of yours which just uses GIArgument instead of the custom union.   See https://bugzilla.gnome.org/show_bug.cgi?id=670249 where I make the "set_gargument_from_ffi_return_value" exactly the same between the two, so we can then later make it public in g-i and remove the duplication.
Comment 9 Colin Walters 2012-02-16 22:01:06 UTC
Created attachment 207816 [details] [review]
repository: Add new public gi_type_info_extract_ffi_return_value() API

Dealing with FFI and return values is very tricky; this API allows
sharing the bits to do it between gobject-introspection and gjs (and
potentially other FFI binding consumers).

**NOTE** I swapped the order of the arguments, under the premise that
out arguments should generally be last.
Comment 10 Colin Walters 2012-02-16 22:04:38 UTC
See https://bugzilla.gnome.org/show_bug.cgi?id=670249 for the gjs patches.
Comment 11 Colin Walters 2012-03-05 14:58:17 UTC
Ok, no review here, but I'm fairly confident these patches don't make things worse at least =)
Comment 12 Colin Walters 2012-03-05 14:58:42 UTC
Attachment 207813 [details] pushed as bf71aba - repository: Fix conversion of FFI values on big-endian architectures
Attachment 207816 [details] pushed as c2fc7cb - repository: Add new public gi_type_info_extract_ffi_return_value() API
Comment 13 Michel Dänzer 2012-03-08 12:29:09 UTC
Created attachment 209243 [details] [review]
repository: Remove extraneous leftover assignment to rvalue.

Oops, looks like I made a mistake when generating the original patch. :(

This followup patch removes a leftover assignment that should have been removed in the first place.

Anyway, thanks for applying these!
Comment 14 Colin Walters 2012-03-08 14:33:50 UTC
Attachment 209243 [details] pushed as 7d70b87 - repository: Remove extraneous leftover assignment to rvalue.
Comment 15 Colin Walters 2012-03-08 14:35:57 UTC
(In reply to comment #13)
> Created an attachment (id=209243) [details] [review]
> repository: Remove extraneous leftover assignment to rvalue.
> 
> Oops, looks like I made a mistake when generating the original patch. :(
> 
> This followup patch removes a leftover assignment that should have been removed
> in the first place.
> 
> Anyway, thanks for applying these!

No problem, hopefully it all works now =)
Comment 16 André Klapper 2015-02-07 16:56:51 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]