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 602709 - Structs in arrays are not marshalled correctly
Structs in arrays are not marshalled correctly
Status: RESOLVED FIXED
Product: pygi
Classification: Deprecated
Component: general
unspecified
Other All
: Normal normal
: 0.6
Assigned To: pygi-maint
pygi-maint
Depends on:
Blocks:
 
 
Reported: 2009-11-23 10:49 UTC by Tomeu Vizoso
Modified: 2009-11-27 12:49 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Structs in arrays are not marshalled correctly (5.15 KB, patch)
2009-11-23 10:49 UTC, Tomeu Vizoso
reviewed Details | Review
Structs in arrays are not marshalled correctly (5.03 KB, patch)
2009-11-24 15:52 UTC, Tomeu Vizoso
needs-work Details | Review
Structs in arrays are not marshalled correctly (5.41 KB, patch)
2009-11-26 11:04 UTC, Tomeu Vizoso
needs-work Details | Review
Structs in arrays are not marshalled correctly (5.47 KB, patch)
2009-11-27 12:08 UTC, Tomeu Vizoso
committed Details | Review
Structs in arrays are not marshalled correctly (5.43 KB, patch)
2009-11-27 12:49 UTC, Tomeu Vizoso
committed Details | Review

Description Tomeu Vizoso 2009-11-23 10:49:44 UTC
Patch with test attached.
Comment 1 Tomeu Vizoso 2009-11-23 10:49:45 UTC
Created attachment 148307 [details] [review]
Structs in arrays are not marshalled correctly
Comment 2 Johan (not receiving bugmail) Dahlin 2009-11-24 13:29:42 UTC
Review of attachment 148307 [details] [review]:

::: gi/pygi-argument.c
@@ +1495,3 @@
                 PyObject *py_item;
+                    void *pointer = g_malloc(item_size);
+                if (item_type_tag == GI_TYPE_TAG_INTERFACE) {

This should be freed at some point

::: tests/libtestgi.c
@@ +1841,3 @@
 
+ * @structs: (out) (array length=length) (transfer none):
+ * test_gi_array_out_struct:

transfer is wrong here, should be at least container
Comment 3 Johan (not receiving bugmail) Dahlin 2009-11-24 13:29:42 UTC
Review of attachment 148307 [details] [review]:

::: gi/pygi-argument.c
@@ +1495,3 @@
                 PyObject *py_item;
+                    void *pointer = g_malloc(item_size);
+                if (item_type_tag == GI_TYPE_TAG_INTERFACE) {

This should be freed at some point

::: tests/libtestgi.c
@@ +1841,3 @@
 
+ * @structs: (out) (array length=length) (transfer none):
+ * test_gi_array_out_struct:

transfer is wrong here, should be at least container
Comment 4 Tomeu Vizoso 2009-11-24 15:52:27 UTC
Created attachment 148399 [details] [review]
Structs in arrays are not marshalled correctly
Comment 5 Tomeu Vizoso 2009-11-24 15:54:46 UTC
(In reply to comment #3)
> Review of attachment 148307 [details] [review]:
> 
> ::: gi/pygi-argument.c
> @@ +1495,3 @@
>                  PyObject *py_item;
> +                    void *pointer = g_malloc(item_size);
> +                if (item_type_tag == GI_TYPE_TAG_INTERFACE) {
> 
> This should be freed at some point

Removed the malloc, not sure what it was doing there.

> ::: tests/libtestgi.c
> @@ +1841,3 @@
> 
> + * @structs: (out) (array length=length) (transfer none):
> + * test_gi_array_out_struct:
> 
> transfer is wrong here, should be at least container

Would transfer-container match the implementation? I understood that transfer-container would be appropriate if we were creating a new container at every invocation.
Comment 6 Simon van der Linden 2009-11-26 09:48:33 UTC
Review of attachment 148399 [details] [review]:

::: gi/pygi-argument.c
@@ +1512,3 @@
                 PyObject *py_item;
+                    item.v_pointer = &_g_array_index(array, GArgument, i);
+                if (item_type_tag == GI_TYPE_TAG_INTERFACE) {

This should only be done for structures; it'd break anything else.

@@ +1514,3 @@
+                } else {
+                    item.v_pointer = &_g_array_index(array, GArgument, i);
+                if (item_type_tag == GI_TYPE_TAG_INTERFACE) {

You could keep the old statement. It's probably worth investigating for multi-dimensional arrays, though.

::: tests/libtestgi.h
@@ +358,2 @@
 void test_gi_array_out (gint **ints, gint *length);
+void test_gi_array_out_struct (TestGISimpleStruct **structs, gint *length);

Use a fixed-length array instead; it's simpler.
Comment 7 Tomeu Vizoso 2009-11-26 11:03:30 UTC
Review of attachment 148399 [details] [review]:

::: gi/pygi-argument.c
@@ +1512,3 @@
 
+                if (item_type_tag == GI_TYPE_TAG_INTERFACE) {
+                    item.v_pointer = &_g_array_index(array, GArgument, i);

Done.

@@ +1514,3 @@
+                    item.v_pointer = &_g_array_index(array, GArgument, i);
+                } else {
+                    memcpy(&item, &_g_array_index(array, GArgument, i), item_size);

You mean item = _g_array_index(array, GArgument,...?

The problem is that for item sizes smaller than 4, we'll be accessing more than we should, causing a valgrind warning. I know it should be harmless, but hides real problems we may have.

::: tests/libtestgi.h
@@ +357,3 @@
 void test_gi_array_out (gint **ints, gint *length);
 
+void test_gi_array_out_struct (TestGISimpleStruct **structs, gint *length);

Done.
Comment 8 Tomeu Vizoso 2009-11-26 11:04:02 UTC
Created attachment 148518 [details] [review]
Structs in arrays are not marshalled correctly
Comment 9 Simon van der Linden 2009-11-26 21:54:08 UTC
(In reply to comment #7)
> Review of attachment 148399 [details] [review]:
> 
> ::: gi/pygi-argument.c
> @@ +1512,3 @@
> 
> +                if (item_type_tag == GI_TYPE_TAG_INTERFACE) {
> +                    item.v_pointer = &_g_array_index(array, GArgument, i);
> 
> Done.
> 
> @@ +1514,3 @@
> +                    item.v_pointer = &_g_array_index(array, GArgument, i);
> +                } else {
> +                    memcpy(&item, &_g_array_index(array, GArgument, i),
> item_size);
> 
> You mean item = _g_array_index(array, GArgument,...?
> 
> The problem is that for item sizes smaller than 4, we'll be accessing more than
> we should, causing a valgrind warning. I know it should be harmless, but hides
> real problems we may have.

You're right.
Comment 10 Simon van der Linden 2009-11-26 21:57:26 UTC
Review of attachment 148518 [details] [review]:

::: gi/pygi-argument.c
@@ +1513,3 @@
+                if (item_type_tag == GI_TYPE_TAG_INTERFACE) {
+
+                gboolean is_struct = FALSE;

Should be freed!
Comment 11 Tomeu Vizoso 2009-11-27 11:31:41 UTC
(In reply to comment #10)
> Review of attachment 148518 [details] [review]:
> 
> ::: gi/pygi-argument.c
> @@ +1513,3 @@
> +                if (item_type_tag == GI_TYPE_TAG_INTERFACE) {
> +
> +                gboolean is_struct = FALSE;
> 
> Should be freed!

What should be freed?
Comment 12 Simon van der Linden 2009-11-27 12:02:06 UTC
(In reply to comment #11)
> (In reply to comment #10)
> What should be freed?

iface_info
Comment 13 Tomeu Vizoso 2009-11-27 12:08:06 UTC
Created attachment 148583 [details] [review]
Structs in arrays are not marshalled correctly
Comment 14 Simon van der Linden 2009-11-27 12:40:21 UTC
Review of attachment 148583 [details] [review]:

Good. Thanks!
Comment 15 Tomeu Vizoso 2009-11-27 12:49:00 UTC
The following fix has been pushed:
ac80e64 Structs in arrays are not marshalled correctly
Comment 16 Tomeu Vizoso 2009-11-27 12:49:08 UTC
Created attachment 148589 [details] [review]
Structs in arrays are not marshalled correctly