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 726206 - Handle GI_TRANSFER_EVERYTHING for returns of foreign structures
Handle GI_TRANSFER_EVERYTHING for returns of foreign structures
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: introspection
unspecified
Other All
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks: 693111
 
 
Reported: 2014-03-12 23:01 UTC by Owen Taylor
Modified: 2014-03-13 13:27 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Handle GI_TRANSFER_EVERYTHING for returns of foreign structures (6.74 KB, patch)
2014-03-12 23:01 UTC, Owen Taylor
committed Details | Review

Description Owen Taylor 2014-03-12 23:01:36 UTC
Any (transfer full) return of a cairo type other than a path
was leaked.

Pass the transfer type PyGIArgOverrideFromGIArgumentFunc and handle
it for the cairo foreign type. For paths we can only handle
(transfer full) so throw an error for (transfer none).
Comment 1 Owen Taylor 2014-03-12 23:01:39 UTC
Created attachment 271664 [details] [review]
Handle GI_TRANSFER_EVERYTHING for returns of foreign structures
Comment 2 Simon Feltman 2014-03-13 03:19:17 UTC
Review of attachment 271664 [details] [review]:

Thanks for this. I verified this indeed cleans up the following leaks when running tests/test_everything.py which hits cairo marshaling:

2 bytes, 1 blocks
malloc
???
???
regress_test_cairo_context_full_return
ffi_call_unix64
ffi_call
_invoke_callable
pygi_callable_info_invoke
_wrap_g_callable_info_invoke
_callable_info_call
_function_info_call
PyObject_Call

1 bytes, 1 blocks
malloc
???
???
regress_test_cairo_surface_full_out
ffi_call_unix64
ffi_call
_invoke_callable
pygi_callable_info_invoke
_wrap_g_callable_info_invoke
_callable_info_call
_function_info_call
PyObject_Call

1 bytes, 1 blocks
malloc
???
???
regress_test_cairo_surface_full_return
ffi_call_unix64
ffi_call
_invoke_callable
pygi_callable_info_invoke
_wrap_g_callable_info_invoke
_callable_info_call
_function_info_call
PyObject_Call

::: gi/pygi-foreign-cairo.c
@@ +148,3 @@
 
+    if (transfer == GI_TRANSFER_NOTHING) {
+        PyErr_SetString(PyExc_TypeError, "Unsupported annotation (transfer none) for cairo.Path return");

Shouldn't we do a cairo_copy_path to handle this case? e.g passing copied memory to PycairoPath_FromPath which it will then manage (not sure if there is a real world use for this but it still seems valid...)
Comment 3 Owen Taylor 2014-03-13 03:36:22 UTC
> +    if (transfer == GI_TRANSFER_NOTHING) {
> +        PyErr_SetString(PyExc_TypeError, "Unsupported annotation (transfer
> none) for cairo.Path return");
> 
> Shouldn't we do a cairo_copy_path to handle this case? e.g passing copied
> memory to PycairoPath_FromPath which it will then manage (not sure if there is
> a real world use for this but it still seems valid...)

cairo_copy_path() isn't what it sounds like, if you look at it's signature it's:

 cairo_path_t *cairo_copy_path (cairo_t *cr);

What it does is makes a copy of the current path for the context (the cairo_t). In theory you could:

 - Creating a 1x1 image surface
 - Creating a context for it
 - Using cairo_append_path() path to append the path on it
 - Using cairo_copy_path() to get the path back
 - Destroy the surface and context

But practically speaking, there's no way to copy a cairo_path_t, so an API that returns a cairo_path_t (transfer none) is buggy and unbindable.
Comment 4 Simon Feltman 2014-03-13 05:05:30 UTC
Comment on attachment 271664 [details] [review]
Handle GI_TRANSFER_EVERYTHING for returns of foreign structures

OK, thanks for the clarification.
Comment 5 Owen Taylor 2014-03-13 13:27:51 UTC
Attachment 271664 [details] pushed as bbfcebd - Handle GI_TRANSFER_EVERYTHING for returns of foreign structures