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 654406 - Can't use tp_connection_get_contacts_by_handle()
Can't use tp_connection_get_contacts_by_handle()
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks: 654475
 
 
Reported: 2011-07-11 15:59 UTC by Guillaume Desmottes
Modified: 2012-02-06 20:33 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add tests for array arguments in callbacks (4.42 KB, patch)
2011-07-11 18:07 UTC, Giovanni Campagna
committed Details | Review
Support callbacks that accept array arguments (7.38 KB, patch)
2011-07-11 18:09 UTC, Giovanni Campagna
reviewed Details | Review
Skip only user_data in callbacks (1.78 KB, patch)
2011-07-13 11:49 UTC, Giovanni Campagna
reviewed Details | Review
Support callbacks that accept array arguments (9.24 KB, patch)
2012-02-06 16:12 UTC, Giovanni Campagna
committed Details | Review
Skip only user_data in callbacks (1.82 KB, patch)
2012-02-06 16:13 UTC, Giovanni Campagna
committed Details | Review

Description Guillaume Desmottes 2011-07-11 15:59:29 UTC
I tried to get rid of the shell_get_tp_contacts() C wrapper:

            conn.get_contacts_by_handle([targetHandle], contactFeatures, Lang.bind(...)

but I'm hitting this exception:

aaaaaaaaaaa
    JS ERROR: !!!   Exception was: Error: FIXME: Only supporting fixed size ARRAYs
    JS ERROR: !!!     lineNumber = '0'
    JS ERROR: !!!     fileName = '"gjs_throw"'
    JS ERROR: !!!     stack = '"Error("FIXME: Only supporting fixed size ARRAYs")@:0
("FIXME: Only supporting fixed size ARRAYs")@gjs_throw:0
Comment 1 Dan Winship 2011-07-11 16:00:59 UTC
http://telepathy.freedesktop.org/doc/telepathy-glib/telepathy-glib-contact.html#tp-connection-get-contacts-by-handle

the annotations appear to be correct; this should work... did we not actually test the multiple array case?
Comment 2 Giovanni Campagna 2011-07-11 17:15:05 UTC
(In reply to comment #1)
> http://telepathy.freedesktop.org/doc/telepathy-glib/telepathy-glib-contact.html#tp-connection-get-contacts-by-handle
> 
> the annotations appear to be correct; this should work... did we not actually
> test the multiple array case?

I guess we forgot conversion when invoking callbacks (in fact, that error is for converting C arrays to JS, not the other way round).
Comment 3 Giovanni Campagna 2011-07-11 18:07:08 UTC
Created attachment 191749 [details] [review]
Add tests for array arguments in callbacks

Add a test that accepts a callback receiving array arguments
Comment 4 Giovanni Campagna 2011-07-11 18:09:36 UTC
Created attachment 191751 [details] [review]
Support callbacks that accept array arguments

Introduce a caching layer for callback parameters, similar to that
used for functions, and use it to support arrays with explicit
length, as well as ruling out (out) and (inout) arguments, that were
never really supported.
Comment 5 Guillaume Desmottes 2011-07-12 13:57:11 UTC
I tried your patch and now I'm hitting this issue:

    JS ERROR: !!!   Unhandled type error converting GArgument to JavaScript
Comment 6 Giovanni Campagna 2011-07-12 16:14:43 UTC
(In reply to comment #5)
> I tried your patch and now I'm hitting this issue:
> 
>     JS ERROR: !!!   Unhandled type error converting GArgument to JavaScript

Which is caused by marshalling a GError in the callback (which is GI_TYPE_TAG_ERROR in introspection). Yay for another bug!
Comment 7 Dan Winship 2011-07-12 16:52:44 UTC
Comment on attachment 191751 [details] [review]
Support callbacks that accept array arguments

looks right... maybe wait until fixing the GError issue as well before committing, to make sure it works for the tp-glib case?
Comment 8 Giovanni Campagna 2011-07-12 17:11:33 UTC
(In reply to comment #7)
> (From update of attachment 191751 [details] [review])
> looks right... maybe wait until fixing the GError issue as well before
> committing, to make sure it works for the tp-glib case?

Actually, I fixed that in bug 618193, which seemed more appropriate. Do you think I should squash the patches? They are otherwise unrelated.
Comment 9 Dan Winship 2011-07-12 17:52:22 UTC
no, wasn't suggesting squashing, I was just saying that since Guillaume has not yet successfully tested this bugfix against his code, we might not want to commit/close it yet.
Comment 10 Guillaume Desmottes 2011-07-13 07:34:43 UTC
Yep, works fine with these 2 patches. Thanks guys!
Comment 11 Guillaume Desmottes 2011-07-13 08:59:02 UTC
Hum actually there is still an issue.


            conn.get_contacts_by_handle([targetHandle], contactFeatures,
                    Lang.bind(this, function (connection, contacts, failed, wtf, weak_object) {
                        (...)
                    }), null);

I add to add this 'wtf' arg to the callback to have the right value of the
weak_object param (null here but still). 'wtf' seems to always be null.
Comment 12 Giovanni Campagna 2011-07-13 10:59:07 UTC
(In reply to comment #11)
> Hum actually there is still an issue.
> 
> 
>             conn.get_contacts_by_handle([targetHandle], contactFeatures,
>                     Lang.bind(this, function (connection, contacts, failed,
> wtf, weak_object) {
>                         (...)
>                     }), null);
> 
> I add to add this 'wtf' arg to the callback to have the right value of the
> weak_object param (null here but still). 'wtf' seems to always be null.

wtf is the user_data argument. Normally user_data are at the end of the callback (so you can ignore them, in C and in JS), so they go unnoticed, whereas in this case there is another param after it. In gjs you cannot use user_data (it is used for an internal structure), so it is be appropriate to skip this param.
Comment 13 Giovanni Campagna 2011-07-13 11:04:20 UTC
(In reply to comment #12)
> (In reply to comment #11)
> > Hum actually there is still an issue.
> > 
> > 
> >             conn.get_contacts_by_handle([targetHandle], contactFeatures,
> >                     Lang.bind(this, function (connection, contacts, failed,
> > wtf, weak_object) {
> >                         (...)
> >                     }), null);
> > 
> > I add to add this 'wtf' arg to the callback to have the right value of the
> > weak_object param (null here but still). 'wtf' seems to always be null.
> 
> wtf is the user_data argument. Normally user_data are at the end of the
> callback (so you can ignore them, in C and in JS), so they go unnoticed,
> whereas in this case there is another param after it. In gjs you cannot use
> user_data (it is used for an internal structure), so it is be appropriate to
> skip this param.

No wait, I misread the callback signature. wtf is the GError parameter, and it is correctly NULL.
(In fact, the user_data should be undefined, being GI_TYPE_TAG_VOID, not null)
Comment 14 Guillaume Desmottes 2011-07-13 11:25:42 UTC
Oh, we do expose GError in the JS API? Shouldn't we raise an exception instead?
Comment 15 Giovanni Campagna 2011-07-13 11:49:18 UTC
Created attachment 191876 [details] [review]
Skip only user_data in callbacks

Previously, all void* arguments in callbacks were skipped. Now we
check in the closure id in the caching layer and correctly mark
them skipped.

Not a real fix, but I think it is cleaner like this.
Comment 16 Giovanni Campagna 2011-07-13 11:51:31 UTC
(In reply to comment #14)
> Oh, we do expose GError in the JS API? Shouldn't we raise an exception instead?

How can we? Exceptions are thrown out from a function, not inside a function. You could expose a JS Error object instead of a GError, but it wouldn't make much difference.
Comment 17 Dan Winship 2011-07-13 13:21:30 UTC
(In reply to comment #16)
> (In reply to comment #14)
> > Oh, we do expose GError in the JS API? Shouldn't we raise an exception instead?
> 
> How can we? Exceptions are thrown out from a function, not inside a function.

Right. If you want an exception, you should make the API use the gio callback style, where the callback just gets a GAsyncResult*, and you have to pass that to a _finish() function, which takes the GAsyncResult* and a GError**, and either returns the real result(s), or throws an error.
Comment 18 Guillaume Desmottes 2011-07-13 13:25:22 UTC
Good point. Fine with me then.
Comment 19 Guillaume Desmottes 2011-08-04 09:32:24 UTC
These patches fix my issue and so allow me to remove wrapper in the Shell (bug #654475). Any chance to get them merged?
Comment 20 Colin Walters 2011-08-05 15:36:53 UTC
Review of attachment 191876 [details] [review]:

I'm not sure how the second part works; the closure invocation doesn't use the cached function data, right?  So I think this change would effectively do the same thing if we just used the deletions.
Comment 21 Giovanni Campagna 2011-08-11 19:43:29 UTC
(In reply to comment #20)
> Review of attachment 191876 [details] [review]:
> 
> I'm not sure how the second part works; the closure invocation doesn't use the
> cached function data, right?  So I think this change would effectively do the
> same thing if we just used the deletions.

Right now, it does not use the cached data, but it will start doing it if the first patch is merged.
Comment 22 Giovanni Campagna 2011-11-25 08:20:27 UTC
Any updates on this?
Comment 23 Jasper St. Pierre (not reading bugmail) 2011-11-25 09:58:27 UTC
(In reply to comment #22)
> Any updates on this?

It's currently a holiday in the US. Ping Colin on Monday.
Comment 24 Giovanni Campagna 2012-02-06 16:12:35 UTC
Created attachment 206908 [details] [review]
Support callbacks that accept array arguments

Introduce a caching layer for callback parameters, similar to that
used for functions, and use it to support arrays with explicit
length.
Comment 25 Giovanni Campagna 2012-02-06 16:13:08 UTC
Created attachment 206909 [details] [review]
Skip only user_data in callbacks

Previously, all void* arguments in callbacks were skipped. Now we
check in the closure id in the caching layer and correctly mark
them skipped.
Comment 26 Giovanni Campagna 2012-02-06 16:14:04 UTC
(In reply to comment #23)
> (In reply to comment #22)
> > Any updates on this?
> 
> It's currently a holiday in the US. Ping Colin on Monday.

It's monday (XD). Patches rebased.
Comment 27 Giovanni Campagna 2012-02-06 16:15:16 UTC
Comment on attachment 191749 [details] [review]
Add tests for array arguments in callbacks

Attachment 191749 [details] pushed as 6757460 - Add tests for array arguments in callbacks
Comment 28 Jasper St. Pierre (not reading bugmail) 2012-02-06 16:20:38 UTC
Review of attachment 206908 [details] [review]:

Makes sense.
Comment 29 Jasper St. Pierre (not reading bugmail) 2012-02-06 16:21:39 UTC
Review of attachment 206909 [details] [review]:

Yep.
Comment 30 Giovanni Campagna 2012-02-06 19:17:08 UTC
Attachment 206908 [details] pushed as 0a9e958 - Support callbacks that accept array arguments
Attachment 206909 [details] pushed as 97e08e5 - Skip only user_data in callbacks
Comment 31 Giovanni Campagna 2012-02-06 20:10:05 UTC
(In reply to comment #29)
> Review of attachment 206909 [details] [review]:
> 
> Yep.

No, this commit is wrong, and I reverted. It breaks callbacks that receive void* and expect to ignore it. One example of it is the callback Meta.keybindings_set_custom_handler (so this breaks all global keybindings in gnome-shell).
Comment 32 Jasper St. Pierre (not reading bugmail) 2012-02-06 20:24:57 UTC
Is there anything that needs that commit, or is it just a "clean up"?
Comment 33 Giovanni Campagna 2012-02-06 20:31:11 UTC
(In reply to comment #32)
> Is there anything that needs that commit, or is it just a "clean up"?

Honestly, I don't remember. I'd say "just a clean up", at this point, which makes it useless.
Comment 34 Jasper St. Pierre (not reading bugmail) 2012-02-06 20:33:11 UTC
OK, then.