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 657767 - Add support for flat GValue arrays
Add support for flat GValue arrays
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2011-08-30 22:02 UTC by Jasper St. Pierre (not reading bugmail)
Modified: 2012-01-06 21:01 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
tests: Add tests for GValue (1.03 KB, patch)
2011-08-30 22:02 UTC, Jasper St. Pierre (not reading bugmail)
rejected Details | Review
Add support for flat GValue arrays (1.42 KB, patch)
2011-08-30 22:02 UTC, Jasper St. Pierre (not reading bugmail)
rejected Details | Review
tests: Add tests for GValue (1.03 KB, patch)
2011-09-01 19:08 UTC, Jasper St. Pierre (not reading bugmail)
none Details | Review
Add support for flat GValue arrays (4.85 KB, patch)
2011-09-01 19:08 UTC, Jasper St. Pierre (not reading bugmail)
reviewed Details | Review
Add support for flat GValue arrays (8.30 KB, patch)
2012-01-04 21:11 UTC, Jasper St. Pierre (not reading bugmail)
committed Details | Review

Description Jasper St. Pierre (not reading bugmail) 2011-08-30 22:02:17 UTC
Some APIs like to use a singular, flat GValue* array for convenience.
Comment 1 Jasper St. Pierre (not reading bugmail) 2011-08-30 22:02:19 UTC
Created attachment 195255 [details] [review]
tests: Add tests for GValue
Comment 2 Jasper St. Pierre (not reading bugmail) 2011-08-30 22:02:22 UTC
Created attachment 195256 [details] [review]
Add support for flat GValue arrays
Comment 3 Jasper St. Pierre (not reading bugmail) 2011-09-01 19:08:41 UTC
Created attachment 195431 [details] [review]
tests: Add tests for GValue
Comment 4 Jasper St. Pierre (not reading bugmail) 2011-09-01 19:08:47 UTC
Created attachment 195433 [details] [review]
Add support for flat GValue arrays
Comment 5 Emmanuele Bassi (:ebassi) 2011-09-11 09:33:30 UTC
look at bug 560567 — Chris Lord had a branch a year ago fixing this.
Comment 6 Colin Walters 2012-01-03 21:44:26 UTC
Review of attachment 195433 [details] [review]:

This should be squashed with the test patch.

I don't see this depending on a patch to add GIMarshallingTests.gvalue_flat_array().

So...this is changing how we handle all GValue arrays, right?  I'm not sure that is_pointer is going to be false for arrays right now.  So the commit title should be "Assume arrays of GValue are 'flat'."

Now special casing GValue here is just perpetuating the hack for flat arrays.  It's really a mess, I know, but...it's probably worth adding an annotation for this.

Also, we should be encouraging C authors to use GValueArray, not a C array of GValue*.
Comment 7 Jasper St. Pierre (not reading bugmail) 2012-01-03 22:05:32 UTC
(In reply to comment #6)
> Review of attachment 195433 [details] [review]:
> 
> This should be squashed with the test patch.
> 
> I don't see this depending on a patch to add
> GIMarshallingTests.gvalue_flat_array().

bug #657766. I should add a dependency.

> So...this is changing how we handle all GValue arrays, right?  I'm not sure
> that is_pointer is going to be false for arrays right now.  So the commit title
> should be "Assume arrays of GValue are 'flat'." 

GValue** should still work because is_pointer is TRUE. We can add tests to other things for that.

> Now special casing GValue here is just perpetuating the hack for flat arrays. 
> It's really a mess, I know, but...it's probably worth adding an annotation for
> this.

An annotation for what? We can pretty safely assume that a "GValue*" annotated with the (array) annotation is a flat array.

> Also, we should be encouraging C authors to use GValueArray, not a C array of
> GValue*.
Comment 8 Colin Walters 2012-01-03 23:01:14 UTC
(In reply to comment #7)
>
> GValue** should still work because is_pointer is TRUE. We can add tests to
> other things for that.

Hmm...ok.  But then I'm still worried that there's code out there that is using GValue * for a non-flat array, and after this it will just start crashing.

From inspecting a few random modules they all seem to be flat, so maybe it's unusual enough that we could probably get by with just changing it.

> An annotation for what? We can pretty safely assume that a "GValue*" annotated
> with the (array) annotation is a flat array.

The general problem - what do we do with other arrays of boxed types?  If a C author returns GDateTime * and says it's an array, do we also assume it's flat or not?  If it's flat, do we unref individual elements?  Should we just reject this?  (Probably).

It's definitely worth looking at Chris' patch as ebassi mentioned - but I think Giovanni did some more generalizations of the array work, so it might be mostly obsolete.
Comment 9 Jasper St. Pierre (not reading bugmail) 2012-01-04 21:11:58 UTC
Created attachment 204637 [details] [review]
Add support for flat GValue arrays

Tests are squashed. We also support flat GValue array returns, although
this made the code a bit more complicated.
Comment 10 Colin Walters 2012-01-06 20:21:00 UTC
Review of attachment 204637 [details] [review]:

Looks OK in general.

::: gi/arg.c
@@ +2729,3 @@
+                g_free(arg->v_pointer);
+                return JS_TRUE;
+            }

I think you shouldn't free if transfer is GI_TRANSFER_CONTAINER, though I doubt anyone would actually return such a thing.
Comment 11 Jasper St. Pierre (not reading bugmail) 2012-01-06 21:01:07 UTC
Attachment 204637 [details] pushed as 0688f72 - Add support for flat GValue arrays


Pushed with suggested changes. Thanks for reviewing!