Commit 853e6a71 authored by Carlos Garnacho's avatar Carlos Garnacho Committed by Martin Pitt
Browse files

Fix handling of by-reference structs as out parameters

When marshalling back from python, copy the result of by-reference
structs into the memory expected by the native caller, instead of
attempting to handle it as a pointer.

https://bugzilla.gnome.org/show_bug.cgi?id=653151

Signed-off-by: default avatarMartin Pitt <martinpitt@gnome.org>
parent bac9d526
......@@ -72,6 +72,23 @@ _pygi_closure_assign_pyobj_to_out_argument (gpointer out_arg, PyObject *object,
case GI_TYPE_TAG_DOUBLE:
*((gdouble *) out_arg) = arg.v_double;
break;
case GI_TYPE_TAG_INTERFACE:
{
GIBaseInfo *interface;
GIInfoType interface_type;
interface = g_type_info_get_interface (type_info);
interface_type = g_base_info_get_type (interface);
if (!g_type_info_is_pointer (type_info) &&
interface_type == GI_INFO_TYPE_STRUCT) {
gsize item_size = _pygi_g_type_info_size (type_info);
memcpy (out_arg, arg.v_pointer, item_size);
break;
}
}
/* Fall through */
default:
*((GIArgument *) out_arg) = arg;
break;
......
......@@ -1629,6 +1629,9 @@ class TestPythonGObject(unittest.TestCase):
def do_vfunc_return_value_and_multiple_out_parameters(self):
return (5, 42, 99)
def do_vfunc_caller_allocated_out_parameter(self):
return 'hello'
class SubObject(GIMarshallingTests.SubObject):
def __init__(self, int):
GIMarshallingTests.SubObject.__init__(self)
......@@ -1665,6 +1668,8 @@ class TestPythonGObject(unittest.TestCase):
self.assertEqual(object_.vfunc_return_value_and_one_out_parameter(), (5, 42))
self.assertEqual(object_.vfunc_return_value_and_multiple_out_parameters(), (5, 42, 99))
self.assertEqual(object_.vfunc_caller_allocated_out_parameter(), 'hello')
class ObjectWithoutVFunc(GIMarshallingTests.Object):
def __init__(self, int):
GIMarshallingTests.Object.__init__(self)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment