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 652753 - no support for GI_ARRAY_TYPE_PTR_ARRAY
no support for GI_ARRAY_TYPE_PTR_ARRAY
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other Linux
: Normal major
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks: 653941
 
 
Reported: 2011-06-16 16:40 UTC by Guillaume Desmottes
Modified: 2011-08-18 13:20 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add support for GPtrArrays (17.54 KB, patch)
2011-06-19 20:36 UTC, Giovanni Campagna
none Details | Review
Forbid GPtrArrays holding non-pointer types (5.43 KB, patch)
2011-07-02 13:34 UTC, Giovanni Campagna
committed Details | Review
Disallow non byte types for GByteArrays (3.45 KB, patch)
2011-07-02 14:07 UTC, Giovanni Campagna
committed Details | Review
Add support for GPtrArrays (15.88 KB, patch)
2011-07-02 15:00 UTC, Giovanni Campagna
reviewed Details | Review
Don't release too much when releasing arrays (7.72 KB, patch)
2011-07-02 15:01 UTC, Giovanni Campagna
committed Details | Review
Fix (allow-none) for arrays (1.08 KB, patch)
2011-07-05 17:49 UTC, Giovanni Campagna
committed Details | Review
Fix converting to GByteArrays from strings or arrays (905 bytes, patch)
2011-07-05 17:49 UTC, Giovanni Campagna
committed Details | Review
Add support for GPtrArrays (14.54 KB, patch)
2011-07-05 17:49 UTC, Giovanni Campagna
committed Details | Review

Description Guillaume Desmottes 2011-06-16 16:40:13 UTC
I'm trying to use tp_base_client_delegate_channels_finish [1] in gnome-shell:

    _delegateFinish : function (o, res, data) {
        try {
            o.delegate_channels_finish(res);
        } catch (e) {
            print ("delegate failed" + e);
        }
    },

    open: function(notification) {
          if (this._client.is_handling_channel(this._channel)) {
              // We are handling the channel, try to pass it to Empathy
              this._client.delegate_channels_async([this._channel], global.get_current_time(), "",
                                                   Lang.bind(this, this._delegateFinish));

(...)

[1] http://telepathy.freedesktop.org/doc/telepathy-glib/telepathy-glib-base-client.html#tp-base-client-delegate-channels-finish

calling o.delegate_channels_finish(res) raises this assertion:

ERROR:gi/arg.c:2246:gjs_g_arg_release_internal: code should not be reached


Here is the gir of this function:

      <method name="delegate_channels_finish" c:identifier="tp_base_client_delegate_channels_finish" version="0.15.0" throws="1">
        <doc xml:whitespace="preserve">Finishes an async channels delegation request started using
tp_base_client_delegate_channels_async().
can be used to know the channels that @self is not handling any more,
otherwise %FALSE.</doc>
        <return-value transfer-ownership="none">
          <doc xml:whitespace="preserve">%TRUE if the operation succeed, @delegated and @not_delegated</doc>
          <type name="gboolean" c:type="gboolean"/>
        </return-value>
        <parameters>
          <parameter name="result" transfer-ownership="none">
            <doc xml:whitespace="preserve">a #GAsyncResult</doc>
            <type name="Gio.AsyncResult" c:type="GAsyncResult*"/>
          </parameter>
          <parameter name="delegated" direction="out" caller-allocates="0" transfer-ownership="container">
            <doc xml:whitespace="preserve">if not %NULL, used to return a #GPtrArray containing the #TpChannel&lt;!-- --&gt;s which have been properly delegated</doc>
            <array name="GLib.PtrArray" c:type="GPtrArray**">
              <type name="Channel"/>
            </array>
          </parameter>
          <parameter name="not_delegated" direction="out" caller-allocates="0" transfer-ownership="container">
            <doc xml:whitespace="preserve">if not not %NULL, used to return a #GHashTable mapping #TpChannel&lt;!-- --&gt;s which have not been delegated to a #GError explaining the reason of the failure</doc>
            <type name="GLib.HashTable" c:type="GHashTable**">
              <type name="Channel"/>
              <type name="GLib.Error"/>
            </type>
          </parameter>
        </parameters>
      </method>
Comment 1 Guillaume Desmottes 2011-06-16 16:47:23 UTC
Here is the trace.


  • #0 raise
    at ../nptl/sysdeps/unix/sysv/linux/raise.c line 64
  • #1 abort
    at abort.c line 92
  • #2 g_assertion_message
    at gtestutils.c line 1417
  • #3 gjs_g_arg_release_internal
    at gi/arg.c line 2246
  • #4 gjs_g_argument_release
    at gi/arg.c line 2336
  • #5 gjs_invoke_c_function
    at gi/function.c line 779
  • #6 function_call
    at gi/function.c line 875
  • #7 js_Invoke
    from /home/cassidy/usr/lib64/xulrunner-1.9.2.13/libmozjs.so
  • #8 ??
    from /home/cassidy/usr/lib64/xulrunner-1.9.2.13/libmozjs.so
  • #9 js_Invoke
    from /home/cassidy/usr/lib64/xulrunner-1.9.2.13/libmozjs.so
  • #10 ??
    from /home/cassidy/usr/lib64/xulrunner-1.9.2.13/libmozjs.so
  • #11 ??
    from /home/cassidy/usr/lib64/xulrunner-1.9.2.13/libmozjs.so
  • #12 js_Invoke
    from /home/cassidy/usr/lib64/xulrunner-1.9.2.13/libmozjs.so
  • #13 ??
    from /home/cassidy/usr/lib64/xulrunner-1.9.2.13/libmozjs.so
  • #14 JS_CallFunctionValue
    from /home/cassidy/usr/lib64/xulrunner-1.9.2.13/libmozjs.so
  • #15 gjs_callback_closure
    at gi/function.c line 191
  • #16 ffi_closure_unix64_inner
    from /usr/lib/libffi.so.5
  • #17 ffi_closure_unix64
    from /usr/lib/libffi.so.5
  • #18 g_simple_async_result_complete
    at gsimpleasyncresult.c line 749
  • #19 delegate_channels_cb
    at base-client.c line 2929
  • #20 _tp_cli_channel_dispatcher_invoke_callback_delegate_channels
    at ../telepathy-glib/_gen/tp-cli-channel-dispatcher-body.h line 605
  • #21 tp_proxy_pending_call_idle_invoke
    at proxy-methods.c line 153
  • #22 g_idle_dispatch
    at gmain.c line 4854
  • #23 g_main_dispatch
    at gmain.c line 2477
  • #24 g_main_context_dispatch
    at gmain.c line 3050
  • #25 g_main_context_iterate
    at gmain.c line 3128
  • #26 g_main_loop_run
    at gmain.c line 3336
  • #27 meta_run
    at core/main.c line 557
  • #28 main
    at main.c line 511

Comment 2 Giovanni Campagna 2011-06-19 20:36:41 UTC
Created attachment 190228 [details] [review]
Add support for GPtrArrays

Using code that already exists for GArray, implement marshalling
for GPtrArrays, including of integers (with GINT_TO_POINTER).
Comment 3 Dan Winship 2011-06-20 12:51:22 UTC
do you have any examples of people using GPtrArrays of ints? If you have ints, you should just use a GArray...
Comment 4 Giovanni Campagna 2011-06-20 12:59:41 UTC
(In reply to comment #3)
> do you have any examples of people using GPtrArrays of ints? If you have ints,
> you should just use a GArray...

gi_marshalling_tests_gptrarray_int_none_in is the example I found, but there could be more, considering that giscanner doesn't warn for such usage
Comment 5 Guillaume Desmottes 2011-06-29 08:35:02 UTC
Would be good to get this merged asap as it blocks this gnome-shell bug: bug #653620
Comment 6 Dan Winship 2011-06-29 12:25:50 UTC
Comment on attachment 190228 [details] [review]
Add support for GPtrArrays

from a quick look the code looks good, as do the various array-handling cleanups

> > do you have any examples of people using GPtrArrays of ints? If you have ints,
> > you should just use a GArray...
> 
> gi_marshalling_tests_gptrarray_int_none_in is the example I found

IMHO that should be removed. If you have ints, you should use a GArray. It's not like GList/GHashTable where there's no corresponding scalar-typed list/hash type and so there's *some* excuse for abusing the type system...

>             GByteArray *byte_array = g_byte_array_sized_new(length);
> 
>             g_byte_array_append(byte_array, data, length);
>+            arg->v_pointer = byte_array;
>+
>+            g_free(data);
>+        } else if (array_type == GI_ARRAY_TYPE_PTR_ARRAY) {
>+            GPtrArray *array = g_ptr_array_sized_new(length);
>+
>+            g_ptr_array_set_size(array, length);
>+            memcpy(array->pdata, data, sizeof(gpointer) * length);
>+            arg->v_pointer = array;
>+
>             g_free(data);

we should fix this at some point to let us convert the array directly into the bytearray/ptrarray so we don't have the g_free() at the end.

>-    // Tests disabled due to do g-i typelib compilation bug
>-    // https://bugzilla.gnome.org/show_bug.cgi?id=622335
>-    //array = GIMarshallingTests.garray_int_none_return();

should that bug be closed?
Comment 7 Giovanni Campagna 2011-07-02 13:34:37 UTC
Created attachment 191145 [details] [review]
Forbid GPtrArrays holding non-pointer types

It should be safe for bindings to assume that GPtrArrays hold only
pointers (or values as big as it), so there is no need to go through
hoops for converting smaller integers when marshalling.
Libraries that need arrays of integers should use GArray.
Comment 8 Giovanni Campagna 2011-07-02 14:07:01 UTC
Created attachment 191150 [details] [review]
Disallow non byte types for GByteArrays

Similarly to GPtrArrays, GByteArrays can only contain bytes. Emit
a warning if an inconsistent (element-type) is placed, and ensure
that the default is guint8 if nothing is added. This way bindings
can support GByteArrays without special casing them.

While we're here, we can fix this one as well, so that I can remove
all code that special cased element_type.
Comment 9 Giovanni Campagna 2011-07-02 15:00:45 UTC
Created attachment 191152 [details] [review]
Add support for GPtrArrays

Using code that already exists for GArray, implement marshalling
for GPtrArrays. Includes some general cleanup of array code.
Comment 10 Giovanni Campagna 2011-07-02 15:01:15 UTC
Created attachment 191153 [details] [review]
Don't release too much when releasing arrays

The functions that released out arrays were iterating over
pointer sized values, irrespective of the actual element size.
Fix that by checking that the element is actually a pointer
(everything else requires no release, except for the actual array
block)
Comment 11 Dan Winship 2011-07-05 13:39:43 UTC
Comment on attachment 191145 [details] [review]
Forbid GPtrArrays holding non-pointer types

>+        # GPtrArrays are allowed to contain non basic types
>+        # (except enums and flags) or basic types that are
>+        # as big as a gpointer
>+        if array.array_type == ast.Array.GLIB_PTRARRAY and \
>+           ((array.element_type in ast.BASIC_GIR_TYPES \
>+             and not array.element_type in ast.POINTER_TYPES) or \
>+            isinstance(array.element_type, ast.Enum) or \
>+            isinstance(array.element_type, ast.Bitfield)):
>+            message.warn("invalid (element-type) for a GPtrArray, "
>+                        "must be a pointer", options.position)

I'm not sure it's safe to assume "non-basic except enum or flags" means "pointer". Colin?

(Even if it is, that expression is really confusing. Maybe just add an is_pointer flag/method to Type?)
Comment 12 Dan Winship 2011-07-05 13:43:05 UTC
Comment on attachment 191150 [details] [review]
Disallow non byte types for GByteArrays

>+        if isinstance(node.type, ast.Array):
>+            self._check_array_element_type(node.type, options)

does this part belong in the previous patch?
Comment 13 Dan Winship 2011-07-05 13:55:17 UTC
Comment on attachment 191152 [details] [review]
Add support for GPtrArrays

>-    if ((JSVAL_IS_NULL(value) && !may_be_null) || (!JSVAL_IS_STRING(value) && !JSVAL_IS_OBJECT(value))) {
>+    if ((JSVAL_IS_NULL(value) && !may_be_null) ||
>+        (!JSVAL_IS_STRING(value) && !JSVAL_IS_OBJECT(value) && !JSVAL_IS_NULL(value))) {

does this mean allow-none was previously broken for arrays?

>+                /* extra reference will be removed gjs_g_argument_release */

removed BY gjs...

>             g_byte_array_append(byte_array, data, length);
>+            arg->v_pointer = byte_array;

so bytearrays were previously totally broken?

(If there are actual bugs fixed here, it would be nice to split those out into a separate commit(s) rather than squashing them with the new feature and general rewrite.)

>@@ -2718,11 +2660,61 @@ gjs_g_arg_release_internal(JSContext  *context,
>+            switch (element_type) {
>+            case GI_TYPE_TAG_UINT8:
>+            case GI_TYPE_TAG_UINT16:
>+            case GI_TYPE_TAG_UINT32:
>+            case GI_TYPE_TAG_UINT64:
>+            case GI_TYPE_TAG_INT8:
>+            case GI_TYPE_TAG_INT16:
>+            case GI_TYPE_TAG_INT32:
>+            case GI_TYPE_TAG_INT64:
>+                g_ptr_array_free(array, TRUE);
>+                break;

unnecessary now? Or still needed for cleanup in a bad-typelib case?
Comment 14 Dan Winship 2011-07-05 13:57:24 UTC
Comment on attachment 191153 [details] [review]
Don't release too much when releasing arrays

looks ok
Comment 15 Giovanni Campagna 2011-07-05 17:19:09 UTC
(In reply to comment #12)
> (From update of attachment 191150 [details] [review])
> >+        if isinstance(node.type, ast.Array):
> >+            self._check_array_element_type(node.type, options)
> 
> does this part belong in the previous patch?

So and so: the previous patch works without this part, because you cannot have a GPtrArray without (element-type), whereas it makes sense for GByteArray.

(In reply to comment #13)
> (From update of attachment 191152 [details] [review])
> >-    if ((JSVAL_IS_NULL(value) && !may_be_null) || (!JSVAL_IS_STRING(value) && !JSVAL_IS_OBJECT(value))) {
> >+    if ((JSVAL_IS_NULL(value) && !may_be_null) ||
> >+        (!JSVAL_IS_STRING(value) && !JSVAL_IS_OBJECT(value) && !JSVAL_IS_NULL(value))) {
> 
> does this mean allow-none was previously broken for arrays?

Yes.
The second gjs patch adds tests for null, so we can hope it won't happen again.

> >             g_byte_array_append(byte_array, data, length);
> >+            arg->v_pointer = byte_array;
> 
> so bytearrays were previously totally broken?

No, only converting from string and regular arrays. JS ByteArrays worked fine (that's why the tests passed).

> (If there are actual bugs fixed here, it would be nice to split those out into
> a separate commit(s) rather than squashing them with the new feature and
> general rewrite.)

Ok.

> >@@ -2718,11 +2660,61 @@ gjs_g_arg_release_internal(JSContext  *context,
> >+            switch (element_type) {
> >+            case GI_TYPE_TAG_UINT8:
> >+            case GI_TYPE_TAG_UINT16:
> >+            case GI_TYPE_TAG_UINT32:
> >+            case GI_TYPE_TAG_UINT64:
> >+            case GI_TYPE_TAG_INT8:
> >+            case GI_TYPE_TAG_INT16:
> >+            case GI_TYPE_TAG_INT32:
> >+            case GI_TYPE_TAG_INT64:
> >+                g_ptr_array_free(array, TRUE);
> >+                break;
> 
> unnecessary now? Or still needed for cleanup in a bad-typelib case?

Probably unnecessary.
Comment 16 Giovanni Campagna 2011-07-05 17:49:05 UTC
Created attachment 191343 [details] [review]
Fix (allow-none) for arrays

Previous check rejected non-string and non-object in all cases,
even when null was allowed.
Comment 17 Giovanni Campagna 2011-07-05 17:49:14 UTC
Created attachment 191344 [details] [review]
Fix converting to GByteArrays from strings or arrays

When converting an array or a string to a GByteArray (but not a JS
ByteArray), it forgot to actually set the bytearray in the resulting
GArgument.
Comment 18 Giovanni Campagna 2011-07-05 17:49:58 UTC
Created attachment 191345 [details] [review]
Add support for GPtrArrays

Using code that already exists for GArray, implement marshalling
for GPtrArrays. Includes some general cleanup of array code.
Comment 19 Dan Winship 2011-07-05 21:31:56 UTC
Comment on attachment 191345 [details] [review]
Add support for GPtrArrays

looks good assuming the tests do in fact pass
Comment 20 Giovanni Campagna 2011-07-09 14:05:10 UTC
Attachment 191343 [details] pushed as 4f63f43 - Fix (allow-none) for arrays
Attachment 191344 [details] pushed as f8a4f68 - Fix converting to GByteArrays from strings or arrays
Holding back the patch for GPtrArray, pending approval on gobject-introspection
Comment 21 Guillaume Desmottes 2011-08-17 10:12:04 UTC
(In reply to comment #18)
> Created an attachment (id=191345) [details] [review]
> Add support for GPtrArrays
> 
> Using code that already exists for GArray, implement marshalling
> for GPtrArrays. Includes some general cleanup of array code.

Could we please merge this? I need it to use tp_connection_dup_contact_list() which I need to fix bug #653941
Comment 22 Giovanni Campagna 2011-08-18 13:15:52 UTC
Attachment 191145 [details] pushed as 8a4e168 - Forbid GPtrArrays holding non-pointer types
Attachment 191150 [details] pushed as 4c90020 - Disallow non byte types for GByteArrays

Nobody complained, so I'm committing these.
Comment 23 Giovanni Campagna 2011-08-18 13:20:43 UTC
Attachment 191153 [details] pushed as fa8b844 - Don't release too much when releasing arrays
Attachment 191345 [details] pushed as 1149483 - Add support for GPtrArrays