Commit 46656737 authored by Simon Feltman's avatar Simon Feltman
Browse files

Re-add support for passing GValue's by reference

Fix special casing when marshaling from a Python held GValue
to a GValue argument intended for a function call.
The re-factoring of GValue marshaling in commit #9e47afe4
broke this by always making a copy of the GValue. This removed the
ability to retrieve values with functions like
gtk_style_context_get_style_property.

https://bugzilla.gnome.org/show_bug.cgi?id=701058
parent 40a3cd18
......@@ -1164,7 +1164,7 @@ array_success:
g_type,
py_type,
transfer,
FALSE, /*is_caller_allocates*/
FALSE, /*copy_reference*/
g_struct_info_is_foreign (info));
Py_DECREF (py_type);
......
......@@ -1651,7 +1651,7 @@ _pygi_marshal_from_py_interface_struct (PyGIInvokeState *state,
iface_cache->g_type,
iface_cache->py_type,
arg_cache->transfer,
arg_cache->is_caller_allocates,
TRUE, /*copy_reference*/
iface_cache->is_foreign);
}
......@@ -1856,13 +1856,14 @@ pygi_marshal_from_py_gobject (PyObject *py_arg, /*in*/
* py_arg: (in):
* arg: (out):
* transfer:
* is_allocated: TRUE if arg->v_pointer is an already allocated GValue
* copy_reference: TRUE if arg should use the pointer reference held by py_arg
* when it is already holding a GValue vs. copying the value.
*/
gboolean
pygi_marshal_from_py_gvalue (PyObject *py_arg,
GIArgument *arg,
GITransfer transfer,
gboolean is_allocated) {
gboolean copy_reference) {
GValue *value;
GType object_type;
......@@ -1872,24 +1873,21 @@ pygi_marshal_from_py_gvalue (PyObject *py_arg,
return FALSE;
}
if (is_allocated)
value = (GValue *)arg->v_pointer;
else
value = g_slice_new0 (GValue);
/* if already a gvalue, use that, else marshal into gvalue */
if (object_type == G_TYPE_VALUE) {
GValue *source_value = pyg_boxed_get (py_arg, GValue);
if (G_VALUE_TYPE (value) == G_TYPE_INVALID)
if (copy_reference) {
value = source_value;
} else {
value = g_slice_new0 (GValue);
g_value_init (value, G_VALUE_TYPE (source_value));
g_value_copy (source_value, value);
g_value_copy (source_value, value);
}
} else {
if (G_VALUE_TYPE (value) == G_TYPE_INVALID)
g_value_init (value, object_type);
value = g_slice_new0 (GValue);
g_value_init (value, object_type);
if (pyg_value_from_pyobject (value, py_arg) < 0) {
if (!is_allocated)
g_slice_free (GValue, value);
g_slice_free (GValue, value);
PyErr_SetString (PyExc_RuntimeError, "PyObject conversion to GValue failed");
return FALSE;
}
......@@ -1940,7 +1938,7 @@ pygi_marshal_from_py_interface_struct (PyObject *py_arg,
GType g_type,
PyObject *py_type,
GITransfer transfer,
gboolean is_allocated,
gboolean copy_reference,
gboolean is_foreign)
{
if (py_arg == Py_None) {
......@@ -1958,7 +1956,7 @@ pygi_marshal_from_py_interface_struct (PyObject *py_arg,
return pygi_marshal_from_py_gvalue(py_arg,
arg,
transfer,
is_allocated);
copy_reference);
} else if (is_foreign) {
PyObject *success;
success = pygi_struct_foreign_convert_to_g_argument (py_arg,
......
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