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 667244 - Arrays of variants passed from C to Python always marshal to empty arrays
Arrays of variants passed from C to Python always marshal to empty arrays
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: introspection
3.1.x
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2012-01-04 09:15 UTC by Mikkel Kamstrup Erlandsen
Modified: 2012-07-12 09:20 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch: add relevant ginterface to gobject-introspection (5.30 KB, patch)
2012-01-04 09:21 UTC, Mikkel Kamstrup Erlandsen
committed Details | Review
Patch: (failing) test case for pygobject (1.99 KB, patch)
2012-01-04 09:26 UTC, Mikkel Kamstrup Erlandsen
none Details | Review
Fix C-, Ptr-, and Byte- Array handling for interfaces, properties, and signals (16.94 KB, patch)
2012-01-05 09:47 UTC, Mikkel Kamstrup Erlandsen
needs-work Details | Review
Test passing arrays of variants to ginterface method with py impl (1.99 KB, patch)
2012-01-05 09:51 UTC, Mikkel Kamstrup Erlandsen
needs-work Details | Review

Description Mikkel Kamstrup Erlandsen 2012-01-04 09:15:53 UTC
If you have a GInterface method defined in C that takes an array of variants as an argument, and you implement that interface in Python, then the Python implementation always gets passed an empty array no matter what the caller passes in.

Attaching tests case in a sec.

Note: This bug is not a dupe of https://bugzilla.gnome.org/show_bug.cgi?id=638915. But is dual to it, in the sense that the error appears when passing arrays of variants in the *opposite* direction of that bug. That is, from C to Python.
Comment 1 Mikkel Kamstrup Erlandsen 2012-01-04 09:21:56 UTC
Created attachment 204550 [details] [review]
Patch: add relevant ginterface to gobject-introspection
Comment 2 Mikkel Kamstrup Erlandsen 2012-01-04 09:26:28 UTC
Created attachment 204551 [details] [review]
Patch: (failing) test case for pygobject

Here's a test case for pygobject that fails. I'll look into a fix.
Comment 3 Mikkel Kamstrup Erlandsen 2012-01-04 11:46:17 UTC
A little digging reveals that inside _pygi_closure_convert_ffi_arguments() that tag type GI_TYPE_TAG_ARRAY is not handled at all, and it goes into the default branch of the switch, which sets the argument to zero.

Let's see if I can wrap my head around adding the support for arrays here...
Comment 4 Mikkel Kamstrup Erlandsen 2012-01-05 09:47:04 UTC
Created attachment 204673 [details] [review]
Fix C-, Ptr-, and Byte- Array handling for interfaces, properties, and signals

This started out as a venture to fix the passing of arrays of variants
into Python implementations of a GInterface. As it turned out there
were lots of corner cases where arrays in general wasn't handled properly.
    
The upshot is that _pygi_argument_to_object() now has the documented
expectation of getting arrays packed in GArrays. This was implicit before
and not correctly done on most call sites.
    
The helper _pygi_argument_to_array() has been improved to work on any kind of
array. And I've made sure all call sites of _pygi_argument_to_object() does the
array conversion appropriately before calling _pygi_argument_to_object().
Comment 5 Mikkel Kamstrup Erlandsen 2012-01-05 09:51:14 UTC
Created attachment 204674 [details] [review]
Test passing arrays of variants to ginterface method with py impl

Adds a test case that implements a ginterface, in Python, with a
method that takes an array of variants as input. The test only passes
with the improved array support from the previous commit.
Comment 6 Mikkel Kamstrup Erlandsen 2012-01-05 09:52:57 UTC
All patches should be ready for review.
Comment 7 Sebastian Pölsterl 2012-02-20 19:07:12 UTC
Unfortunately, the patch doesn't apply cleanly anymore, could you please rebase and provide a new patch?

In addition, as your patch is quite extensive you should add more tests for all the array types you want to handle. We want to make sure tests cover all code paths.
Comment 8 Martin Pitt 2012-04-17 09:44:33 UTC
Comment on attachment 204673 [details] [review]
Fix C-, Ptr-, and Byte- Array handling for interfaces, properties, and signals

Patch needs to be forward-ported.
Comment 9 Martin Pitt 2012-04-17 09:44:57 UTC
Comment on attachment 204674 [details] [review]
Test passing arrays of variants to ginterface method with py impl

Patch needs more test cases, see Sebastian's comment 7.
Comment 10 Martin Pitt 2012-04-20 05:15:17 UTC
Comment on attachment 204550 [details] [review]
Patch: add relevant ginterface to gobject-introspection

The g-i patch also does not apply any more, setting to "needs-work", too.

>--- a/tests/gimarshallingtests.h
>+++ b/tests/gimarshallingtests.h
> [...]
>-#define GI_MARSHALLING_TESTS_INTERFACE2_GET_IFACE(obj)    (G_TYPE_INSTANCE_GET_INTERFACE2 ((obj), GI_MARSHALLING_TESTS_TYPE_INTERFACE2, GIMarshallingTestsInterface2Iface))
>+#define GI_MARSHALLING_TESTS_INTERFACE2_GET_IFACE(obj)    (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GI_MARSHALLING_TESTS_TYPE_INTERFACE2, GIMarshallingTestsInterface2Iface))

This looks odd and wrong to me. Possibly just an "oops" typo when you edited the source?
Comment 11 Mikkel Kamstrup Erlandsen 2012-05-02 06:48:33 UTC
(In reply to comment #10)
> (From update of attachment 204550 [details] [review])
> The g-i patch also does not apply any more, setting to "needs-work", too.
> 
> >--- a/tests/gimarshallingtests.h
> >+++ b/tests/gimarshallingtests.h
> > [...]
> >-#define GI_MARSHALLING_TESTS_INTERFACE2_GET_IFACE(obj)    (G_TYPE_INSTANCE_GET_INTERFACE2 ((obj), GI_MARSHALLING_TESTS_TYPE_INTERFACE2, GIMarshallingTestsInterface2Iface))
> >+#define GI_MARSHALLING_TESTS_INTERFACE2_GET_IFACE(obj)    (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GI_MARSHALLING_TESTS_TYPE_INTERFACE2, GIMarshallingTestsInterface2Iface))
> 
> This looks odd and wrong to me. Possibly just an "oops" typo when you edited
> the source?

Ah, no, this is correct. It demonstrates that no-one was using GIMarshallingTestsInterface2 before this. It referenced a non-existing macro G_TYPE_INSTANCE_GET_INTERFACE2. I guess the extra "2" was from a previous bad copy-pasta.
Comment 12 Martin Pitt 2012-07-12 07:18:19 UTC
Comment on attachment 204550 [details] [review]
Patch: add relevant ginterface to gobject-introspection

I updated the g-i test patch to current master, and committed. Thanks!
Comment 13 Martin Pitt 2012-07-12 07:22:33 UTC
Thanks for your work! I fixed the patch to apply to current git master, and pushed:

http://git.gnome.org/browse/pygobject/commit/?id=a31fabdc1
Comment 14 Mikkel Kamstrup Erlandsen 2012-07-12 09:20:31 UTC
Ah, this is awesome. Thanks a bunch Martin! :-D