Bug 182666 - [GTK] webkit_uri_scheme_request_finish_error introspection broken
Summary: [GTK] webkit_uri_scheme_request_finish_error introspection broken
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKitGTK (show other bugs)
Version: Other
Hardware: PC Linux
: P3 Normal
Assignee: Nobody
URL:
Keywords: Gtk
Depends on:
Blocks:
 
Reported: 2018-02-09 17:35 PST by talby
Modified: 2018-03-05 15:47 PST (History)
2 users (show)

See Also:


Attachments
bug reproduction script (1.16 KB, application/x-perl)
2018-02-09 17:35 PST, talby
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description talby 2018-02-09 17:35:16 PST
Created attachment 333543 [details]
bug reproduction script

webkit_uri_scheme_request_finish_error() doesn't seem to be usable via GObject Introspection in Perl.
When GError pointers are passed as function arguments https://github.com/GNOME/perl-Glib-Object-Introspection/blob/master/gperl-i11n-marshal-arg.c#L118 seems to enforce a specific GITransfer setting.  I think this would be satisfied if https://trac.webkit.org/browser/webkit/trunk/Source/WebKit/UIProcess/API/glib/WebKitURISchemeRequest.cpp#L244 had a "(transfer full)" annotation for the error argument of webkit_uri_scheme_request_finish_error(), but I'm really not sure if that is the right thing to do, would solve my problem, or would mean code changes elsewhere as well.

I've attached a small script that reproduces the call failure I'm seeing, which is giving me:
> **
> ERROR:gperl-i11n-marshal-arg.c:118:sv_to_arg: assertion failed: (transfer == GI_TRANSFER_EVERYTHING)
> Aborted
Comment 1 Michael Catanzaro 2018-02-10 10:02:38 PST
It's actually supposed to be (transfer none).
Comment 2 talby 2018-02-13 15:29:02 PST
Thanks, I'm new to these subsystems.  Just to clarify, "(transfer none)" would correspond to GI_TRANSFER_NOTHING, and my problem is really with perl-Glib-Object-Introspection handling of this argument?
Comment 3 Michael Catanzaro 2018-02-13 16:25:04 PST
(In reply to talby from comment #2)
> Thanks, I'm new to these subsystems.  Just to clarify, "(transfer none)"
> would correspond to GI_TRANSFER_NOTHING,

Yeah, it just means that the calling code does not transfer ownership when it calls the function. The GError is not freed by WebKit: it has to be freed by the caller, after calling the function.

If we were to add a (transfer full) annotation, that would tell the application code (perl-Glib-Object-Introspection) that it should not free the GError because WebKit is responsible for doing so, and that would result in a memory leak, so that would be wrong.

> and my problem is really with
> perl-Glib-Object-Introspection handling of this argument?

Well maybe. Or, it might also be broken in all languages, which would indicate a WebKit bug. That seems a bit more likely here. GError is kinda special in that it's usually an optional out parameter allocated by the function being called. webkit_uri_scheme_request_finish_error() doesn't follow the usual pattern at all, and it does not have any annotation to indicate this, so I suspect it's WebKit's fault and we need to add some new annotation there.

I'll find time to look at this sooner or later. For faster results, if you're willing to try rebuilding WebKit, you could try this change:

-@error: a #GError that will be passed to the #WebKitWebView
+@error: (transfer none): a #GError that will be passed to the #WebKitWebView

which is my first guess at how to solve this. If that's not sufficient, we might need to try some rarely-used annotations to override the defaults, like:

-@error: a #GError that will be passed to the #WebKitWebView
+@error: (transfer none) (not nullable) (in): a #GError that will be passed to the #WebKitWebView

None of us here at webkit.org have much experience with introspection, so I'm just guessing.
Comment 4 Michael Catanzaro 2018-03-05 15:23:32 PST
I looked into this today, but I don't know enough gobject-introspection to help. I translated your example into python and it's working fine for me there. At this point, I would recommend asking the perl-gi developers for advice; they'll probably know whether it's their bug or if we have to change our annotations somehow. They have a Bugzilla here:

https://bugzilla.gnome.org/enter_bug.cgi?product=gnome-perl
Comment 5 talby 2018-03-05 15:47:04 PST
Thanks so much!  I will investigate the perl side of things.