Skip to content

function: Don't assume FFI argument always matches GIArgument

Simon McVittie requested to merge wip/smcv/issue319 into master

Everywhere else in gjs_callback_closure() that writes into result does so by first converting the JavaScript object into a GIArgument according to GIArgument conventions, and then copying the GIArgument into result according to FFI conventions. In particular, for small integers like enums and flags, the value copied into the GIArgument is 32-bit, but the value pointed to by result is typically pointer-sized, which is larger on 64-bit platforms.

However, the code path for vfuncs that fail at the JavaScript level, but have to return something at the C level, was instead treating result as being a pointer to a GIArgument. Writing a small integer to a GIArgument only sets the first few bits (the first 32 for enums and flags), leaving the next 32 bits of a pointer-sized quantity on a 64-bit platform uninitialized. On little-endian CPUs, if the next 32 bits happen to already be all-zeroes, the right thing would happen anyway, but we can't count on that.

In particular, this resulted in the test-case "Wrong virtual functions marshals an enum return value" in GIMarshalling failing on big-endian LP64 architectures like s390x, after I fixed the other code paths involving GArgument and enums/flags for s390x in commit 1ba19d63 "function: Use GIArgument.v_int for enum and flags types".

Resolves: #319 (closed)

Merge request reports