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

Move _pygi_argument_to_object_basic_type into pygi-marshal-to-py.c

Move _pygi_argument_to_object_basic_type into pygi-marshal-to-py.c
and rename to _pygi_marshal_to_py_basic_type.
Cleanup and simplify dependant sub-marshalers for unichar, utf8,
and filename types.

https://bugzilla.gnome.org/show_bug.cgi?id=693405
parent cba401ac
......@@ -1251,77 +1251,6 @@ hash_table_release:
return arg;
}
/**
* _pygi_argument_to_object_basic_type:
* @arg: The argument to convert to an object.
* @type_tag: Type tag for @arg
* @transfer: Transfer annotation
*
* Convert the given argument to a Python object. This function
* is restricted to simple types that only require the GITypeTag
* and GITransfer. For a more complete conversion routine, use:
* _pygi_argument_to_object.
*
* Returns: A PyObject representing @arg or NULL if it cannot convert
* the argument.
*/
PyObject *
_pygi_argument_to_object_basic_type (GIArgument *arg,
GITypeTag type_tag,
GITransfer transfer)
{
switch (type_tag) {
case GI_TYPE_TAG_BOOLEAN:
return PyBool_FromLong (arg->v_boolean);
case GI_TYPE_TAG_INT8:
return PYGLIB_PyLong_FromLong (arg->v_int8);
case GI_TYPE_TAG_UINT8:
return PYGLIB_PyLong_FromLong (arg->v_uint8);
case GI_TYPE_TAG_INT16:
return PYGLIB_PyLong_FromLong (arg->v_int16);
case GI_TYPE_TAG_UINT16:
return PYGLIB_PyLong_FromLong (arg->v_uint16);
case GI_TYPE_TAG_INT32:
return PYGLIB_PyLong_FromLong (arg->v_int32);
case GI_TYPE_TAG_UINT32:
return PyLong_FromLongLong (arg->v_uint32);
case GI_TYPE_TAG_INT64:
return PyLong_FromLongLong (arg->v_int64);
case GI_TYPE_TAG_UINT64:
return PyLong_FromUnsignedLongLong (arg->v_uint64);
case GI_TYPE_TAG_FLOAT:
return PyFloat_FromDouble (arg->v_float);
case GI_TYPE_TAG_DOUBLE:
return PyFloat_FromDouble (arg->v_double);
case GI_TYPE_TAG_GTYPE:
return pyg_type_wrapper_new ( (GType) arg->v_long);
case GI_TYPE_TAG_UNICHAR:
return _pygi_marshal_to_py_unichar (NULL, NULL, NULL, arg);
case GI_TYPE_TAG_UTF8:
return _pygi_marshal_to_py_utf8 (NULL, NULL, NULL, arg);
case GI_TYPE_TAG_FILENAME:
return _pygi_marshal_to_py_filename (NULL, NULL, NULL, arg);
default:
return NULL;
}
return NULL;
}
/**
* _pygi_argument_to_object:
* @arg: The argument to convert to an object.
......@@ -1343,7 +1272,7 @@ _pygi_argument_to_object (GIArgument *arg,
PyObject *object = NULL;
type_tag = g_type_info_get_tag (type_info);
object = _pygi_argument_to_object_basic_type (arg, type_tag, transfer);
object = _pygi_marshal_to_py_basic_type (arg, type_tag, transfer);
if (object)
return object;
......
......@@ -59,10 +59,6 @@ GIArgument _pygi_argument_from_object (PyObject *object,
GITypeInfo *type_info,
GITransfer transfer);
PyObject *_pygi_argument_to_object_basic_type (GIArgument *arg,
GITypeTag type_tag,
GITransfer transfer);
PyObject* _pygi_argument_to_object (GIArgument *arg,
GITypeInfo *type_info,
GITransfer transfer);
......
......@@ -268,7 +268,7 @@ _arg_cache_from_py_basic_type_setup (PyGIArgCache *arg_cache)
static void
_arg_cache_to_py_basic_type_setup (PyGIArgCache *arg_cache)
{
arg_cache->to_py_marshaller = _pygi_marshal_to_py_basic_type;
arg_cache->to_py_marshaller = _pygi_marshal_to_py_basic_type_cache_adapter;
}
static void
......@@ -295,7 +295,7 @@ static void
_arg_cache_to_py_utf8_setup (PyGIArgCache *arg_cache,
GITransfer transfer)
{
arg_cache->to_py_marshaller = _pygi_marshal_to_py_basic_type;
arg_cache->to_py_marshaller = _pygi_marshal_to_py_basic_type_cache_adapter;
arg_cache->to_py_cleanup = _pygi_marshal_cleanup_to_py_utf8;
}
......
......@@ -111,17 +111,6 @@ gi_argument_to_gsize (GIArgument *arg_in,
}
}
PyObject *
_pygi_marshal_to_py_basic_type (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg)
{
return _pygi_argument_to_object_basic_type (arg,
arg_cache->type_tag,
arg_cache->transfer);
}
PyObject *
_pygi_marshal_to_py_void (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
......@@ -144,11 +133,8 @@ _pygi_marshal_to_py_void (PyGIInvokeState *state,
return py_obj;
}
PyObject *
_pygi_marshal_to_py_unichar (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg)
static PyObject *
_pygi_marshal_to_py_unichar (GIArgument *arg)
{
PyObject *py_obj = NULL;
......@@ -171,11 +157,8 @@ _pygi_marshal_to_py_unichar (PyGIInvokeState *state,
return py_obj;
}
PyObject *
_pygi_marshal_to_py_utf8 (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg)
static PyObject *
_pygi_marshal_to_py_utf8 (GIArgument *arg)
{
PyObject *py_obj = NULL;
if (arg->v_string == NULL) {
......@@ -186,11 +169,8 @@ _pygi_marshal_to_py_utf8 (PyGIInvokeState *state,
return py_obj;
}
PyObject *
_pygi_marshal_to_py_filename (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg)
static PyObject *
_pygi_marshal_to_py_filename (GIArgument *arg)
{
gchar *string = NULL;
PyObject *py_obj = NULL;
......@@ -213,6 +193,89 @@ _pygi_marshal_to_py_filename (PyGIInvokeState *state,
return py_obj;
}
/**
* _pygi_marshal_to_py_basic_type:
* @arg: The argument to convert to an object.
* @type_tag: Type tag for @arg
* @transfer: Transfer annotation
*
* Convert the given argument to a Python object. This function
* is restricted to simple types that only require the GITypeTag
* and GITransfer. For a more complete conversion routine, use:
* _pygi_argument_to_object.
*
* Returns: A PyObject representing @arg or NULL if it cannot convert
* the argument.
*/
PyObject *
_pygi_marshal_to_py_basic_type (GIArgument *arg,
GITypeTag type_tag,
GITransfer transfer)
{
switch (type_tag) {
case GI_TYPE_TAG_BOOLEAN:
return PyBool_FromLong (arg->v_boolean);
case GI_TYPE_TAG_INT8:
return PYGLIB_PyLong_FromLong (arg->v_int8);
case GI_TYPE_TAG_UINT8:
return PYGLIB_PyLong_FromLong (arg->v_uint8);
case GI_TYPE_TAG_INT16:
return PYGLIB_PyLong_FromLong (arg->v_int16);
case GI_TYPE_TAG_UINT16:
return PYGLIB_PyLong_FromLong (arg->v_uint16);
case GI_TYPE_TAG_INT32:
return PYGLIB_PyLong_FromLong (arg->v_int32);
case GI_TYPE_TAG_UINT32:
return PyLong_FromLongLong (arg->v_uint32);
case GI_TYPE_TAG_INT64:
return PyLong_FromLongLong (arg->v_int64);
case GI_TYPE_TAG_UINT64:
return PyLong_FromUnsignedLongLong (arg->v_uint64);
case GI_TYPE_TAG_FLOAT:
return PyFloat_FromDouble (arg->v_float);
case GI_TYPE_TAG_DOUBLE:
return PyFloat_FromDouble (arg->v_double);
case GI_TYPE_TAG_GTYPE:
return pyg_type_wrapper_new ( (GType) arg->v_long);
case GI_TYPE_TAG_UNICHAR:
return _pygi_marshal_to_py_unichar (arg);
case GI_TYPE_TAG_UTF8:
return _pygi_marshal_to_py_utf8 (arg);
case GI_TYPE_TAG_FILENAME:
return _pygi_marshal_to_py_filename (arg);
default:
return NULL;
}
return NULL;
}
PyObject *
_pygi_marshal_to_py_basic_type_cache_adapter (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg)
{
return _pygi_marshal_to_py_basic_type (arg,
arg_cache->type_tag,
arg_cache->transfer);
}
PyObject *
_pygi_marshal_to_py_array (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
......
......@@ -22,30 +22,17 @@
#ifndef __PYGI_MARSHAL_TO_PY_H__
#define __PYGI_MARSHAL_TO_PY_H__
PyObject *_pygi_marshal_to_py_basic_type (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg);
PyObject *_pygi_marshal_to_py_basic_type (GIArgument *arg,
GITypeTag type_tag,
GITransfer transfer);
PyObject *_pygi_marshal_to_py_basic_type_cache_adapter (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg);
PyObject *_pygi_marshal_to_py_void (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg);
PyObject *_pygi_marshal_to_py_unichar (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg);
PyObject *_pygi_marshal_to_py_gtype (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg);
PyObject *_pygi_marshal_to_py_utf8 (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg);
PyObject *_pygi_marshal_to_py_filename (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg);
PyObject *_pygi_marshal_to_py_array (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
......
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