Commit 93c1536b authored by Simon Feltman's avatar Simon Feltman
Browse files

Unify Python callable to GClosure GI marshaling code

Add pygi_marshal_from_py_gclosure which can be used for direct gi method
call args and vfunc out args.

https://bugzilla.gnome.org/show_bug.cgi?id=693405
parent 9e47afe4
......@@ -1252,19 +1252,7 @@ array_success:
FALSE /*is_allocated*/);
} else if (g_type_is_a (type, G_TYPE_CLOSURE)) {
GClosure *closure;
if (pyg_type_from_object_strict (object, FALSE) == G_TYPE_CLOSURE) {
closure = (GClosure *)pyg_boxed_get (object, void);
} else {
closure = pyg_closure_new (object, NULL, NULL);
if (closure == NULL) {
PyErr_SetString (PyExc_RuntimeError, "PyObject conversion to GClosure failed");
break;
}
}
arg.v_pointer = closure;
pygi_marshal_from_py_gclosure (object, &arg);
} else if (g_struct_info_is_foreign (info)) {
pygi_struct_foreign_convert_to_g_argument (object, info, transfer, &arg);
} else if (g_type_is_a (type, G_TYPE_BOXED)) {
......
......@@ -1629,28 +1629,7 @@ _pygi_marshal_from_py_interface_struct (PyGIInvokeState *state,
*/
if (iface_cache->g_type == G_TYPE_CLOSURE) {
GClosure *closure;
GType object_gtype = pyg_type_from_object_strict (py_arg, FALSE);
if ( !(PyCallable_Check(py_arg) ||
g_type_is_a (object_gtype, G_TYPE_CLOSURE))) {
PyErr_Format (PyExc_TypeError, "Must be callable, not %s",
py_arg->ob_type->tp_name);
return FALSE;
}
if (g_type_is_a (object_gtype, G_TYPE_CLOSURE))
closure = (GClosure *)pyg_boxed_get (py_arg, void);
else
closure = pyg_closure_new (py_arg, NULL, NULL);
if (closure == NULL) {
PyErr_SetString (PyExc_RuntimeError, "PyObject conversion to GClosure failed");
return FALSE;
}
arg->v_pointer = closure;
return TRUE;
return pygi_marshal_from_py_gclosure (py_arg, arg);
} else if (iface_cache->g_type == G_TYPE_VALUE) {
return pygi_marshal_from_py_gvalue(py_arg, arg,
arg_cache->transfer,
......@@ -1936,3 +1915,35 @@ pygi_marshal_from_py_gvalue (PyObject *py_arg,
arg->v_pointer = value;
return TRUE;
}
/* pygi_marshal_from_py_gclosure:
* py_arg: (in):
* arg: (out):
*/
gboolean
pygi_marshal_from_py_gclosure(PyObject *py_arg,
GIArgument *arg)
{
GClosure *closure;
GType object_gtype = pyg_type_from_object_strict (py_arg, FALSE);
if ( !(PyCallable_Check(py_arg) ||
g_type_is_a (object_gtype, G_TYPE_CLOSURE))) {
PyErr_Format (PyExc_TypeError, "Must be callable, not %s",
py_arg->ob_type->tp_name);
return FALSE;
}
if (g_type_is_a (object_gtype, G_TYPE_CLOSURE))
closure = (GClosure *)pyg_boxed_get (py_arg, void);
else
closure = pyg_closure_new (py_arg, NULL, NULL);
if (closure == NULL) {
PyErr_SetString (PyExc_RuntimeError, "PyObject conversion to GClosure failed");
return FALSE;
}
arg->v_pointer = closure;
return TRUE;
}
......@@ -195,6 +195,9 @@ gboolean pygi_marshal_from_py_gvalue (PyObject *py_arg, /*in*/
GITransfer transfer,
gboolean is_allocated);
gboolean pygi_marshal_from_py_gclosure(PyObject *py_arg, /*in*/
GIArgument *arg); /*out*/
G_END_DECLS
#endif /* __PYGI_MARSHAL_from_py_PY__ */
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