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 646632 - Support in arrays of any type
Support in arrays of any type
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks: 651558
 
 
Reported: 2011-04-03 16:47 UTC by Giovanni Campagna
Modified: 2011-06-16 20:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Support in arrays of any type (7.40 KB, patch)
2011-04-03 16:47 UTC, Giovanni Campagna
none Details | Review
Add tests for complex arrays as in arguments (3.19 KB, patch)
2011-05-12 21:40 UTC, Giovanni Campagna
none Details | Review
Support in arrays of any type (13.73 KB, patch)
2011-05-12 21:41 UTC, Giovanni Campagna
none Details | Review
Support in arrays of any type (13.86 KB, patch)
2011-05-19 16:22 UTC, Giovanni Campagna
accepted-commit_now Details | Review
Rework how special arguments are marshalled (43.06 KB, patch)
2011-05-21 18:09 UTC, Giovanni Campagna
needs-work Details | Review
Rework how special arguments are marshalled (43.09 KB, patch)
2011-06-01 16:27 UTC, Giovanni Campagna
none Details | Review
Rework how special arguments are marshalled (45.52 KB, patch)
2011-06-01 16:38 UTC, Giovanni Campagna
none Details | Review
Rework how special arguments are marshalled (46.48 KB, patch)
2011-06-02 15:18 UTC, Giovanni Campagna
none Details | Review
whitespace fixes for "support in arrays" (4.38 KB, patch)
2011-06-02 19:16 UTC, Dan Winship
none Details | Review
Rework how special arguments are marshalled (46.48 KB, patch)
2011-06-02 19:16 UTC, Dan Winship
none Details | Review
whitespace fixes for "rework..." (8.35 KB, patch)
2011-06-02 19:17 UTC, Dan Winship
none Details | Review
Support in arrays of any type (13.84 KB, patch)
2011-06-02 21:16 UTC, Giovanni Campagna
reviewed Details | Review
Rework how special arguments are marshalled (48.05 KB, patch)
2011-06-02 21:17 UTC, Giovanni Campagna
none Details | Review
Add tests for complex arrays as in arguments (12.92 KB, patch)
2011-06-11 19:37 UTC, Giovanni Campagna
committed Details | Review
Support in arrays of any type (14.48 KB, patch)
2011-06-11 19:38 UTC, Giovanni Campagna
committed Details | Review
Rework how special arguments are marshalled (50.14 KB, patch)
2011-06-11 20:13 UTC, Giovanni Campagna
committed Details | Review

Description Giovanni Campagna 2011-04-03 16:47:24 UTC
Currently GJS supports in arrays only of the various integer types, and this is a serious limitation.
Comment 1 Giovanni Campagna 2011-04-03 16:47:40 UTC
Created attachment 185042 [details] [review]
Support in arrays of any type

Adds support for converting JS Arrays to C arrays of any type, not
just integers as before.
Comment 2 Colin Walters 2011-05-04 18:43:28 UTC
Review of attachment 185042 [details] [review]:

This patch needs tests; I'll look once we have those
Comment 3 Giovanni Campagna 2011-05-12 21:40:10 UTC
Created attachment 187746 [details] [review]
Add tests for complex arrays as in arguments

Previously gjs supported only arrays of integers. Now that this
changed, we need tests to avoid regressions.

(Patch against gobject-introspection for libgimarshallingtests)
Comment 4 Giovanni Campagna 2011-05-12 21:41:20 UTC
Created attachment 187747 [details] [review]
Support in arrays of any type

Adds support for converting JS Arrays to C arrays of any type, not
just integers as before. Includes new infrastructure for releasing
said arrays.

Now with tests!
(And a bug found :) )
Comment 5 Giovanni Campagna 2011-05-19 16:22:54 UTC
Created attachment 188141 [details] [review]
Support in arrays of any type

Adds support for converting JS Arrays to C arrays of any type, not
just integers as before. Includes new infrastructure for releasing
said arrays.

(I forgot to git add one bugfix)
Comment 6 Colin Walters 2011-05-19 22:18:24 UTC
So, this patch really provokes the issue of whether we want to expose length arguments to JS.  I'd honestly really prefer we didn't, since well it's lame =)
Comment 7 Giovanni Campagna 2011-05-20 13:06:58 UTC
(In reply to comment #6)
> So, this patch really provokes the issue of whether we want to expose length
> arguments to JS.  I'd honestly really prefer we didn't, since well it's lame =)

Well, we already do. It would be an API break and a major rework.
Not saying it's not possible, though.
Comment 8 Giovanni Campagna 2011-05-21 18:09:28 UTC
Created attachment 188308 [details] [review]
Rework how special arguments are marshalled

Introduce an array of param_types for special arguments (callbacks,
arrays with explicit length). This means that now more than one
callback is supported for each function, and you don't need to
specify an explicit length for arrays.

----

This is on top of the other patch, although it mostly reworks it.
In order to remove length arguments, I had to modify in various places
how marshalling is implemented, and the patch is really complex.
But it works (in the sense that is passes unit tests), and fixes
two bugs at the same time.
Comment 9 Colin Walters 2011-05-23 14:33:39 UTC
Review of attachment 188141 [details] [review]:

This looks fine.
Comment 10 Colin Walters 2011-05-23 14:40:55 UTC
Review of attachment 188308 [details] [review]:

Cool; thanks a lot for working on this!  But we have to decide explicitly about compatibility for 3.2.  Do we bite the bullet and break any users of array+len functions?
Comment 11 Colin Walters 2011-05-23 14:41:11 UTC
(In reply to comment #10)
> Review of attachment 188308 [details] [review]:
> 
> Cool; thanks a lot for working on this!  But we have to decide explicitly about
> compatibility for 3.2.  Do we bite the bullet and break any users of array+len
> functions?

My take is yes.
Comment 12 Giovanni Campagna 2011-05-23 20:35:01 UTC
(In reply to comment #9)
> Review of attachment 188141 [details] [review]:
> 
> This looks fine.

I'll hold this until the other part (gimarshallingtests) is reviewed and accepted as well.
(Or is it implicitly ok?)

(In reply to comment #11)
> (In reply to comment #10)
> > Review of attachment 188308 [details] [review] [details]:
> > 
> > Cool; thanks a lot for working on this!  But we have to decide explicitly about
> > compatibility for 3.2.  Do we bite the bullet and break any users of array+len
> > functions?
> 
> My take is yes.

Same for me. I think we can get away with a mail to desktop-devel-list, given it was said not long ago that gjs is experimental, and currently only the shell is using it. (Actually, also the-board, but I consider that experimental and unstable as well)
I mean, what are the alternatives? If we hold this off, we're either forced with suboptimal API, or we'll have the same problem in 3.4, until 4.0.
Comment 13 Dan Winship 2011-06-01 14:40:11 UTC
Comment on attachment 188308 [details] [review]
Rework how special arguments are marshalled

>-gjs_callback_trampoline_free(GjsCallbackTrampoline *trampoline)
>+gjs_callback_trampoline_ref(GjsCallbackTrampoline *trampoline)

can the trampoline refcounting/deglobalization be done as a separate patch?

>+#if 0
> static JSBool
> init_callback_args_for_invocation(JSContext               *context,
>                                   Function                *function,
>@@ -358,6 +341,7 @@ init_callback_args_for_invocation(JSContext               *context,
>     g_base_info_unref( (GIBaseInfo*) callback_info);
>     return JS_TRUE;
> }
>+#endif

should just go?

>+                in_arg_cvalues[array_length_pos].v_long = length;

It seems like that wouldn't work if you were on a big-endian machine and the argument was smaller than sizeof(long).
Comment 14 Giovanni Campagna 2011-06-01 16:21:34 UTC
(In reply to comment #13)
> (From update of attachment 188308 [details] [review])
> >-gjs_callback_trampoline_free(GjsCallbackTrampoline *trampoline)
> >+gjs_callback_trampoline_ref(GjsCallbackTrampoline *trampoline)
> 
> can the trampoline refcounting/deglobalization be done as a separate patch?

No.
In order to support multiple callbacks, the patch reworks how (scope call) callbacks are freed, and this refcounting is required.
On the other hand, to use refcounting with current style of creating and freeing trampolines, it would be new code, to be deleted by the next commit.

> >+#if 0
> > static JSBool
> > init_callback_args_for_invocation(JSContext               *context,
> >                                   Function                *function,
> >@@ -358,6 +341,7 @@ init_callback_args_for_invocation(JSContext               *context,
> >     g_base_info_unref( (GIBaseInfo*) callback_info);
> >     return JS_TRUE;
> > }
> >+#endif
> 
> should just go?

Yes, probably.

> >+                in_arg_cvalues[array_length_pos].v_long = length;
> 
> It seems like that wouldn't work if you were on a big-endian machine and the
> argument was smaller than sizeof(long).

Ok. So I need to use gjs_value_to_g_argument, I suppose.
Comment 15 Giovanni Campagna 2011-06-01 16:27:27 UTC
Created attachment 189026 [details] [review]
Rework how special arguments are marshalled

Introduce an array of param_types for special arguments (callbacks,
arrays with explicit length). This means that now more than one
callback is supported for each function, and you don't need to
specify an explicit length for arrays.
Comment 16 Giovanni Campagna 2011-06-01 16:38:49 UTC
Created attachment 189028 [details] [review]
Rework how special arguments are marshalled

Introduce an array of param_types for special arguments (callbacks,
arrays with explicit length). This means that now more than one
callback is supported for each function, and you don't need to
specify an explicit length for arrays.

(Forgot to remove commented out code)
Comment 17 Dan Winship 2011-06-01 18:39:53 UTC
sorry, should have pointed out this line too:

+                length = in_arg_cvalues[array_length_pos].v_long;

same problem, opposite direction.
Comment 18 Giovanni Campagna 2011-06-02 15:18:57 UTC
Created attachment 189087 [details] [review]
Rework how special arguments are marshalled

Introduce an array of param_types for special arguments (callbacks,
arrays with explicit length). This means that now more than one
callback is supported for each function, and you don't need to
specify an explicit length for arrays.
Comment 19 Dan Winship 2011-06-02 19:16:43 UTC
Created attachment 189109 [details] [review]
whitespace fixes for "support in arrays"

(fixups for gjs style)
Comment 20 Dan Winship 2011-06-02 19:16:58 UTC
Created attachment 189110 [details] [review]
Rework how special arguments are marshalled

(rebased for the previous patch)
Comment 21 Dan Winship 2011-06-02 19:17:08 UTC
Created attachment 189111 [details] [review]
whitespace fixes for "rework..."
Comment 22 Dan Winship 2011-06-02 19:18:30 UTC
OK, I support pushing this out and breaking things too. About to attach patches to bug 651558 depending on these
Comment 23 Dan Winship 2011-06-02 19:37:58 UTC
Hm. Actually, with just the first patch applied, things are fine, but with the second (rework) patch applied, gnome-shell crashes almost instantly at startup inside the garbage collector.
Comment 24 Giovanni Campagna 2011-06-02 21:16:46 UTC
Created attachment 189122 [details] [review]
Support in arrays of any type

Adds support for converting JS Arrays to C arrays of any type, not
just integers as before. Includes new infrastructure for releasing
said arrays.

Whitespace changes squashed.
Comment 25 Giovanni Campagna 2011-06-02 21:17:28 UTC
Created attachment 189123 [details] [review]
Rework how special arguments are marshalled

Introduce an array of param_types for special arguments (callbacks,
arrays with explicit length). This means that now more than one
callback is supported for each function, and you don't need to
specify an explicit length for arrays.

Whitespace changes squashed. Two bug fixed, and valgrind checked for
memory leaks.
Comment 26 Colin Walters 2011-06-10 19:15:09 UTC
Review of attachment 189122 [details] [review]:

I'd like to see some tests using arrays of enums, and well generally more tests, but this is looking like a good start.

::: gi/arg.c
@@ +2749,3 @@
+    GITypeTag type_tag;
+
+    if (transfer != GI_TRANSFER_NOTHING)

Shouldn't that be == ?
Comment 27 Giovanni Campagna 2011-06-11 12:21:46 UTC
(In reply to comment #26)
> Review of attachment 189122 [details] [review]:
> 
> I'd like to see some tests using arrays of enums, and well generally more
> tests, but this is looking like a good start.

Ok. I'll prepare some more.

> ::: gi/arg.c
> @@ +2749,3 @@
> +    GITypeTag type_tag;
> +
> +    if (transfer != GI_TRANSFER_NOTHING)
> 
> Shouldn't that be == ?

No. This is for (in) arguments, for which:
GI_TRANSFER_NOTHING means that the callee has duped/reffed the arguments, so we need to release our temporary copies.
GI_TRANSFER_CONTAINER is not supported for in arguments (and will throw before calling the C function)
GI_TRANSFER_EVERYTHING means that the callee has taken ownership, so we have nothing to do.
Comment 28 Giovanni Campagna 2011-06-11 19:37:12 UTC
Created attachment 189735 [details] [review]
Add tests for complex arrays as in arguments

Previously gjs supported only arrays of integers. Now that this
changed, we need tests to avoid regressions.

Added tests for arrays of enums and GSList, for having the length
before the array and for lengths that are not gint.
Comment 29 Giovanni Campagna 2011-06-11 19:38:15 UTC
Created attachment 189736 [details] [review]
Support in arrays of any type

Adds support for converting JS Arrays to C arrays of any type, not
just integers as before. Includes new infrastructure for releasing
said arrays.

Updated for new tests
Comment 30 Giovanni Campagna 2011-06-11 20:13:23 UTC
Created attachment 189737 [details] [review]
Rework how special arguments are marshalled

Introduce an array of param_types for special arguments (callbacks,
arrays with explicit length). This means that now more than one
callback is supported for each function, and you don't need to
specify an explicit length for arrays.
Comment 31 Colin Walters 2011-06-13 22:48:57 UTC
Comment on attachment 189735 [details] [review]
Add tests for complex arrays as in arguments

Attachment 189735 [details] pushed as b62e22c - Add tests for complex arrays as in arguments
Comment 32 Giovanni Campagna 2011-06-14 16:33:12 UTC
Comment on attachment 189736 [details] [review]
Support in arrays of any type

Attachment 189736 [details] pushed as f60d0a1 - Support in arrays of any type
Comment 33 Colin Walters 2011-06-16 20:39:31 UTC
Review of attachment 189737 [details] [review]:

So I like the idea of this, it's really hard to review though because it touches so much complicated code.

Some high level things.  

* I definitely see memory leaks running "make valgrind-check".
* I don't see how the multiple callback thing can work for the unfortunate case where you have two callbacks but only one user_data (for example, g_bus_watch_name_on_connection() ).  
* The cleanup path is even more complex now; I wonder if we can have a mechanism where we push stuff onto a "cleanup stack" rather than having two code paths to loop over the arguments

This is an overall improvement though, and my intuition here is to put it in and work on the memory leaks and cleanups after it goes in.
Comment 34 Colin Walters 2011-06-16 20:40:11 UTC
Attachment 189737 [details] pushed as 7ed2e7d - Rework how special arguments are marshalled