[pygobject] Unify Python callable to GClosure GI marshaling code
- From: Simon Feltman <sfeltman src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Unify Python callable to GClosure GI marshaling code
- Date: Sat, 16 Feb 2013 21:55:18 +0000 (UTC)
commit 93c1536b45f56c20b6d874c41c4cacd2b6cdca0a
Author: Simon Feltman <sfeltman src gnome org>
Date: Fri Feb 15 22:56:29 2013 -0800
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
gi/pygi-argument.c | 14 +----------
gi/pygi-marshal-from-py.c | 55 +++++++++++++++++++++++++++------------------
gi/pygi-marshal-from-py.h | 3 ++
3 files changed, 37 insertions(+), 35 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 81e2ee7..3b65246 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -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)) {
diff --git a/gi/pygi-marshal-from-py.c b/gi/pygi-marshal-from-py.c
index 0f1284e..01138bc 100644
--- a/gi/pygi-marshal-from-py.c
+++ b/gi/pygi-marshal-from-py.c
@@ -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;
+}
diff --git a/gi/pygi-marshal-from-py.h b/gi/pygi-marshal-from-py.h
index 11a21c9..e0a57d3 100644
--- a/gi/pygi-marshal-from-py.h
+++ b/gi/pygi-marshal-from-py.h
@@ -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__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]