[pygobject] Respect different type lengths when assigning out-argument pointers.
- From: Tomeu Vizoso <tomeuv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Respect different type lengths when assigning out-argument pointers.
- Date: Tue, 28 Dec 2010 17:56:40 +0000 (UTC)
commit 8d5a7857876669f56bb03bf618bcfdcc290721c0
Author: Eitan Isaacson <eitan monotonous org>
Date: Wed Dec 22 12:34:10 2010 -0800
Respect different type lengths when assigning out-argument pointers.
https://bugzilla.gnome.org/show_bug.cgi?id=637832
gi/pygi-closure.c | 66 +++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 56 insertions(+), 10 deletions(-)
---
diff --git a/gi/pygi-closure.c b/gi/pygi-closure.c
index 1e2ce05..0425c99 100644
--- a/gi/pygi-closure.c
+++ b/gi/pygi-closure.c
@@ -27,6 +27,53 @@
*/
static GSList* async_free_list;
+static void
+_pygi_closure_assign_pyobj_to_out_argument (gpointer out_arg, PyObject *object,
+ GITypeInfo *type_info,
+ GITransfer transfer)
+{
+ GIArgument arg = _pygi_argument_from_object (object, type_info, transfer);
+ GITypeTag type_tag = g_type_info_get_tag (type_info);
+
+ switch (type_tag) {
+ case GI_TYPE_TAG_BOOLEAN:
+ *((gboolean *) out_arg) = arg.v_boolean;
+ break;
+ case GI_TYPE_TAG_INT8:
+ *((gint8 *) out_arg) = arg.v_int8;
+ break;
+ case GI_TYPE_TAG_UINT8:
+ *((guint8 *) out_arg) = arg.v_uint8;
+ break;
+ case GI_TYPE_TAG_INT16:
+ *((gint16 *) out_arg) = arg.v_int16;
+ break;
+ case GI_TYPE_TAG_UINT16:
+ *((guint16 *) out_arg) = arg.v_uint16;
+ break;
+ case GI_TYPE_TAG_INT32:
+ *((gint32 *) out_arg) = arg.v_int32;
+ break;
+ case GI_TYPE_TAG_UINT32:
+ *((guint32 *) out_arg) = arg.v_uint32;
+ break;
+ case GI_TYPE_TAG_INT64:
+ *((gint64 *) out_arg) = arg.v_int64;
+ break;
+ case GI_TYPE_TAG_UINT64:
+ *((glong *) out_arg) = arg.v_uint64;
+ break;
+ case GI_TYPE_TAG_FLOAT:
+ *((gfloat *) out_arg) = arg.v_float;
+ break;
+ case GI_TYPE_TAG_DOUBLE:
+ *((gdouble *) out_arg) = arg.v_double;
+ break;
+ default:
+ *((GIArgument *) out_arg) = arg;
+ break;
+ }
+}
static GIArgument *
_pygi_closure_convert_ffi_arguments (GICallableInfo *callable_info, void **args)
@@ -225,15 +272,14 @@ _pygi_closure_set_out_arguments (GICallableInfo *callable_info,
return_type_info = g_callable_info_get_return_type (callable_info);
return_type_tag = g_type_info_get_tag (return_type_info);
if (return_type_tag != GI_TYPE_TAG_VOID) {
- GIArgument arg;
GITransfer transfer = g_callable_info_get_caller_owns (callable_info);
if (PyTuple_Check (py_retval)) {
PyObject *item = PyTuple_GET_ITEM (py_retval, 0);
- arg = _pygi_argument_from_object (item, return_type_info, transfer);
- * ( (GIArgument*) resp) = arg;
+ _pygi_closure_assign_pyobj_to_out_argument (resp, item,
+ return_type_info, transfer);
} else {
- arg = _pygi_argument_from_object (py_retval, return_type_info, transfer);
- * ( (GIArgument*) resp) = arg;
+ _pygi_closure_assign_pyobj_to_out_argument (resp, py_retval,
+ return_type_info, transfer);
}
i_py_retval++;
}
@@ -248,14 +294,14 @@ _pygi_closure_set_out_arguments (GICallableInfo *callable_info,
if (direction == GI_DIRECTION_OUT || direction == GI_DIRECTION_INOUT) {
GITransfer transfer = g_arg_info_get_ownership_transfer (arg_info);
- GIArgument arg;
if (PyTuple_Check (py_retval)) {
PyObject *item = PyTuple_GET_ITEM (py_retval, i_py_retval);
- arg = _pygi_argument_from_object (item, type_info, transfer);
- * ( (GIArgument*) out_args[i_out_args].v_pointer) = arg;
+ _pygi_closure_assign_pyobj_to_out_argument (
+ out_args[i_out_args].v_pointer, item, type_info, transfer);
} else if (i_py_retval == 0) {
- arg = _pygi_argument_from_object (py_retval, type_info, transfer);
- * ( (GIArgument*) out_args[i_out_args].v_pointer) = arg;
+ _pygi_closure_assign_pyobj_to_out_argument (
+ out_args[i_out_args].v_pointer, py_retval, type_info,
+ transfer);
} else
g_assert_not_reached();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]