diff options
Diffstat (limited to 'gi/pygi-argument.c')
-rw-r--r-- | gi/pygi-argument.c | 117 |
1 files changed, 108 insertions, 9 deletions
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c index 737342a..b7cab1a 100644 --- a/gi/pygi-argument.c +++ b/gi/pygi-argument.c @@ -31,6 +31,94 @@ #include <pyglib-python-compat.h> #include <pyglib.h> +static gboolean +gi_argument_to_gssize (GIArgument *arg_in, + GITypeTag type_tag, + gssize *gssize_out) +{ + switch (type_tag) { + case GI_TYPE_TAG_INT8: + *gssize_out = arg_in->v_int8; + return TRUE; + case GI_TYPE_TAG_UINT8: + *gssize_out = arg_in->v_uint8; + return TRUE; + case GI_TYPE_TAG_INT16: + *gssize_out = arg_in->v_int16; + return TRUE; + case GI_TYPE_TAG_UINT16: + *gssize_out = arg_in->v_uint16; + return TRUE; + case GI_TYPE_TAG_INT32: + *gssize_out = arg_in->v_int32; + return TRUE; + case GI_TYPE_TAG_UINT32: + *gssize_out = arg_in->v_uint32; + return TRUE; + case GI_TYPE_TAG_INT64: + *gssize_out = arg_in->v_int64; + return TRUE; + case GI_TYPE_TAG_UINT64: + *gssize_out = arg_in->v_uint64; + return TRUE; + default: + PyErr_Format (PyExc_TypeError, + "Unable to marshal %s to gssize", + g_type_tag_to_string(type_tag)); + return FALSE; + } +} + +void +_pygi_hash_pointer_to_arg (GIArgument *arg, + GITypeTag type_tag) +{ + switch (type_tag) { + case GI_TYPE_TAG_INT8: + arg->v_int8 = GPOINTER_TO_INT (arg->v_pointer); + break; + case GI_TYPE_TAG_INT16: + arg->v_int16 = GPOINTER_TO_INT (arg->v_pointer); + break; + case GI_TYPE_TAG_INT32: + arg->v_int32 = GPOINTER_TO_INT (arg->v_pointer); + break; + case GI_TYPE_TAG_UTF8: + case GI_TYPE_TAG_FILENAME: + case GI_TYPE_TAG_INTERFACE: + break; + default: + g_critical ("Unsupported type %s", g_type_tag_to_string(type_tag)); + } +} + +gpointer +_pygi_arg_to_hash_pointer (const GIArgument *arg, + GITypeTag type_tag) +{ + switch (type_tag) { + case GI_TYPE_TAG_INT8: + return GINT_TO_POINTER (arg->v_int8); + case GI_TYPE_TAG_UINT8: + return GINT_TO_POINTER (arg->v_uint8); + case GI_TYPE_TAG_INT16: + return GINT_TO_POINTER (arg->v_int16); + case GI_TYPE_TAG_UINT16: + return GINT_TO_POINTER (arg->v_uint16); + case GI_TYPE_TAG_INT32: + return GINT_TO_POINTER (arg->v_int32); + case GI_TYPE_TAG_UINT32: + return GINT_TO_POINTER (arg->v_uint32); + case GI_TYPE_TAG_UTF8: + case GI_TYPE_TAG_FILENAME: + case GI_TYPE_TAG_INTERFACE: + return arg->v_pointer; + default: + g_critical ("Unsupported type %s", g_type_tag_to_string(type_tag)); + return arg->v_pointer; + } +} + static void _pygi_g_type_tag_py_bounds (GITypeTag type_tag, PyObject **lower, @@ -658,6 +746,7 @@ check_number_release: * @arg: The argument to convert * @args: Arguments to method invocation, possibly contaning the array length. * Set to NULL if this is not for a method call + * @callable_info: Info on the callable, if this a method call; otherwise NULL * @type_info: The type info for @arg * @out_free_array: A return location for a gboolean that indicates whether * or not the wrapped GArray should be freed @@ -675,6 +764,7 @@ check_number_release: GArray * _pygi_argument_to_array (GIArgument *arg, GIArgument *args[], + GICallableInfo *callable_info, GITypeInfo *type_info, gboolean *out_free_array) { @@ -712,12 +802,19 @@ _pygi_argument_to_array (GIArgument *arg, return g_array; } gint length_arg_pos; + GIArgInfo *length_arg_info; + GITypeInfo *length_type_info; length_arg_pos = g_type_info_get_array_length (type_info); g_assert (length_arg_pos >= 0); - - /* FIXME: Take into account the type of the length argument */ - length = args[length_arg_pos]->v_int; + g_assert (callable_info); + length_arg_info = g_callable_info_get_arg (callable_info, length_arg_pos); + length_type_info = g_arg_info_get_type (length_arg_info); + if (!gi_argument_to_gssize (args[length_arg_pos], + g_type_info_get_tag (length_type_info), + &length)) { + return NULL; + } } } @@ -1196,7 +1293,7 @@ array_success: break; } - arg.v_long = PYGLIB_PyLong_AsLong (int_); + arg.v_int = PYGLIB_PyLong_AsLong (int_); Py_DECREF (int_); @@ -1369,7 +1466,8 @@ list_item_error: goto hash_table_item_error; } - g_hash_table_insert (hash_table, key.v_pointer, value.v_pointer); + g_hash_table_insert (hash_table, key.v_pointer, + _pygi_arg_to_hash_pointer (&value, g_type_info_get_tag (value_type_info))); continue; hash_table_item_error: @@ -1713,21 +1811,21 @@ _pygi_argument_to_object (GIArgument *arg, return NULL; py_args = PyTuple_New (1); - if (PyTuple_SetItem (py_args, 0, PyLong_FromLong (arg->v_long)) != 0) { + if (PyTuple_SetItem (py_args, 0, PyLong_FromLong (arg->v_int)) != 0) { Py_DECREF (py_args); Py_DECREF (py_type); return NULL; } - object = PyObject_CallFunction (py_type, "l", arg->v_long); + object = PyObject_CallFunction (py_type, "i", arg->v_int); Py_DECREF (py_args); Py_DECREF (py_type); } else if (info_type == GI_INFO_TYPE_ENUM) { - object = pyg_enum_from_gtype (type, arg->v_long); + object = pyg_enum_from_gtype (type, arg->v_int); } else { - object = pyg_flags_from_gtype (type, arg->v_long); + object = pyg_flags_from_gtype (type, arg->v_int); } break; @@ -1840,6 +1938,7 @@ _pygi_argument_to_object (GIArgument *arg, break; } + _pygi_hash_pointer_to_arg (&value, g_type_info_get_tag (value_type_info)); py_value = _pygi_argument_to_object (&value, value_type_info, item_transfer); if (py_value == NULL) { Py_DECREF (py_key); |