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 729662 - Parse and expose ownership transfer for instance parameters
Parse and expose ownership transfer for instance parameters
Status: RESOLVED FIXED
Product: gobject-introspection
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks: 729545
 
 
Reported: 2014-05-06 17:06 UTC by Giovanni Campagna
Modified: 2015-02-07 16:46 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Parse and expose ownership transfer for instance parameters (10.65 KB, patch)
2014-05-06 17:06 UTC, Giovanni Campagna
reviewed Details | Review
Parse and expose ownership transfer for instance parameters (13.14 KB, patch)
2014-06-15 15:27 UTC, Giovanni Campagna
committed Details | Review

Description Giovanni Campagna 2014-05-06 17:06:26 UTC
Knowing the ownership transfer for instance parameters is
necessary for correct memory management of functions which
"eat" their instance argument, such as g_dbus_method_invocation_return_*.
Parse this information from the gir file and store in the
typelib, and then provide new API on GICallableInfo to
retrieve this.
Comment 1 Giovanni Campagna 2014-05-06 17:06:29 UTC
Created attachment 276006 [details] [review]
Parse and expose ownership transfer for instance parameters
Comment 2 Simon Feltman 2014-05-12 05:20:50 UTC
Review of attachment 276006 [details] [review]:

In general, the implied instance argument is hard to deal with on the bindings side. PyGI determines if there is an instance argument by checking if the info type is GI_INFO_TYPE_FUNCTION and the flags have GI_FUNCTION_IS_METHOD or the info type is GI_INFO_TYPE_VFUNC (not sure about signals). So I think also having an API like g_callable_info_has_instance_arg() to handle those details would be nice, otherwise they are encoded in the bindings. Without a clear conditional context for whether or not the callable has an instance argument, g_callable_info_get_instance_ownership_transfer() doesn't make a lot of sense to me.

Ideally it would be nice to have an API like g_callable_info_get_instance_argument() which gives back a full blown GIArgInfo with all the bits filled out correctly...

How about some tests? :)

::: girepository/gicallableinfo.c
@@ +298,3 @@
+      FunctionBlob *blob;
+      blob = (FunctionBlob *)&rinfo->typelib->data[rinfo->offset];
+{

Since blob->instance_transfer_ownership being set means transfer-full, perhaps the struct attribute should be named accordingly: blob->instance_transfer_full ?

::: girepository/gitypelib-internal.h
@@ +558,2 @@
   guint16 is_static   : 1;
+  guint16 instance_transfer_ownership : 1;

Another option is to add the flag to the SignatureBlob which is available for all the callable blobs and will simplify the implementation. I did this for the last patch in bug 729543.
Comment 3 Giovanni Campagna 2014-06-15 15:05:10 UTC
(In reply to comment #2)
> Review of attachment 276006 [details] [review]:
> 
> In general, the implied instance argument is hard to deal with on the bindings
> side. PyGI determines if there is an instance argument by checking if the info
> type is GI_INFO_TYPE_FUNCTION and the flags have GI_FUNCTION_IS_METHOD or the
> info type is GI_INFO_TYPE_VFUNC (not sure about signals). So I think also
> having an API like g_callable_info_has_instance_arg() to handle those details
> would be nice, otherwise they are encoded in the bindings. Without a clear
> conditional context for whether or not the callable has an instance argument,
> g_callable_info_get_instance_ownership_transfer() doesn't make a lot of sense
> to me.

Well, it's not like that will change any time soon: vfuncs, methods and signals have an instance argument, everything else doesn't. It's basic OOP really, not even g-i conventions.
 
> ::: girepository/gicallableinfo.c
> @@ +298,3 @@
> +      FunctionBlob *blob;
> +      blob = (FunctionBlob *)&rinfo->typelib->data[rinfo->offset];
> +{
> 
> Since blob->instance_transfer_ownership being set means transfer-full, perhaps
> the struct attribute should be named accordingly: blob->instance_transfer_full
> ?

It's called transfer_ownership to mean transfer_full in other places too, and transfer_full is g-ir-scanner terminology, not g-ir-compiler/libgirepository (it would be transfer_everything)

> ::: girepository/gitypelib-internal.h
> @@ +558,2 @@
>    guint16 is_static   : 1;
> +  guint16 instance_transfer_ownership : 1;
> 
> Another option is to add the flag to the SignatureBlob which is available for
> all the callable blobs and will simplify the implementation. I did this for the
> last patch in bug 729543.

Yeah, that's a good idea.
Comment 4 Giovanni Campagna 2014-06-15 15:27:34 UTC
Created attachment 278489 [details] [review]
Parse and expose ownership transfer for instance parameters

Knowing the ownership transfer for instance parameters is
necessary for correct memory management of functions which
"eat" their instance argument, such as g_dbus_method_invocation_return_*.
Parse this information from the gir file and store in the
typelib, and then provide new API on GICallableInfo to
retrieve this.
Comment 5 Simon Feltman 2014-07-03 07:23:32 UTC
Review of attachment 278489 [details] [review]:

Looks good, thanks for adding the tests.
Comment 6 Simon Feltman 2014-07-03 07:25:15 UTC
(In reply to comment #3)
> Well, it's not like that will change any time soon: vfuncs, methods and signals
> have an instance argument, everything else doesn't. It's basic OOP really, not
> even g-i conventions.

I guess my complaint is the API seems like a Liskov violation or at least closely related (bug 709456 is probably a better example). The problem is we have the base type GICallableInfo describing a method which doesn't make sense for certain sub-types, and even returns a valid value for them. From a readability POV, it just seems strange to have to type check a base class in order to verify if methods defined on the base type are valid for the sub-type.

Trying to rework this is obviously not practical, so the suggestion was to package up the sub-type knowledge in an additional method (which will be useful in other contexts as well). I'm happy to add a patch for something like g_callable_info_has_instance_arg() if others agree...

> > ::: girepository/gicallableinfo.c
> > @@ +298,3 @@
> > +      FunctionBlob *blob;
> > +      blob = (FunctionBlob *)&rinfo->typelib->data[rinfo->offset];
> > +{
> > 
> > Since blob->instance_transfer_ownership being set means transfer-full, perhaps
> > the struct attribute should be named accordingly: blob->instance_transfer_full
> > ?
> 
> It's called transfer_ownership to mean transfer_full in other places too, and
> transfer_full is g-ir-scanner terminology, not g-ir-compiler/libgirepository
> (it would be transfer_everything)

Cool, thanks for the explanation.
Comment 7 Giovanni Campagna 2014-07-03 08:40:38 UTC
It's true that you can't really use g_callable_info_get_instance_ownership_transfer()
without knowledge of the subclasses. But that is also true of, say, g_callable_info_invoke(),
and the alternative would be to duplicate this API across the three subclasses.
Besides, I don't believe any new subclass will be introduced in the future, so
this is really a minor issue.

Attachment 278489 [details] pushed as a4c9d09 - Parse and expose ownership transfer for instance parameters
Comment 8 André Klapper 2015-02-07 16:46:31 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]