Commit 0e244151 authored by Simon Feltman's avatar Simon Feltman
Browse files

Replace to Python cached marshalers with unified basic type marshaler

Add cached arg marshaler "_pygi_marshal_to_py_basic_type" which
unifies functions, vfuncs, signals, and property marshaling for
"basic types". Remove all the individual cached arg marshalers
for these types.

https://bugzilla.gnome.org/show_bug.cgi?id=693405
parent 663fe589
......@@ -1392,99 +1392,61 @@ hash_table_release:
* Returns: A PyObject representing @arg or NULL if it cannot convert
* the argument.
*/
static PyObject *
PyObject *
_pygi_argument_to_object_basic_type (GIArgument *arg,
GITypeTag type_tag,
GITransfer transfer)
{
PyObject *object = NULL;
switch (type_tag) {
case GI_TYPE_TAG_BOOLEAN:
{
object = PyBool_FromLong (arg->v_boolean);
break;
}
return PyBool_FromLong (arg->v_boolean);
case GI_TYPE_TAG_INT8:
{
object = PYGLIB_PyLong_FromLong (arg->v_int8);
break;
}
return PYGLIB_PyLong_FromLong (arg->v_int8);
case GI_TYPE_TAG_UINT8:
{
object = PYGLIB_PyLong_FromLong (arg->v_uint8);
break;
}
return PYGLIB_PyLong_FromLong (arg->v_uint8);
case GI_TYPE_TAG_INT16:
{
object = PYGLIB_PyLong_FromLong (arg->v_int16);
break;
}
return PYGLIB_PyLong_FromLong (arg->v_int16);
case GI_TYPE_TAG_UINT16:
{
object = PYGLIB_PyLong_FromLong (arg->v_uint16);
break;
}
return PYGLIB_PyLong_FromLong (arg->v_uint16);
case GI_TYPE_TAG_INT32:
{
object = PYGLIB_PyLong_FromLong (arg->v_int32);
break;
}
return PYGLIB_PyLong_FromLong (arg->v_int32);
case GI_TYPE_TAG_UINT32:
{
object = PyLong_FromLongLong (arg->v_uint32);
break;
}
return PyLong_FromLongLong (arg->v_uint32);
case GI_TYPE_TAG_INT64:
{
object = PyLong_FromLongLong (arg->v_int64);
break;
}
return PyLong_FromLongLong (arg->v_int64);
case GI_TYPE_TAG_UINT64:
{
object = PyLong_FromUnsignedLongLong (arg->v_uint64);
break;
}
return PyLong_FromUnsignedLongLong (arg->v_uint64);
case GI_TYPE_TAG_FLOAT:
{
object = PyFloat_FromDouble (arg->v_float);
break;
}
return PyFloat_FromDouble (arg->v_float);
case GI_TYPE_TAG_DOUBLE:
{
object = PyFloat_FromDouble (arg->v_double);
break;
}
return PyFloat_FromDouble (arg->v_double);
case GI_TYPE_TAG_GTYPE:
{
object = pyg_type_wrapper_new ( (GType) arg->v_long);
break;
}
return pyg_type_wrapper_new ( (GType) arg->v_long);
case GI_TYPE_TAG_UNICHAR:
{
object = _pygi_marshal_to_py_unichar (NULL, NULL, NULL,
arg);
break;
}
return _pygi_marshal_to_py_unichar (NULL, NULL, NULL, arg);
case GI_TYPE_TAG_UTF8:
{
object = _pygi_marshal_to_py_utf8 (NULL, NULL, NULL,
arg);
break;
}
return _pygi_marshal_to_py_utf8 (NULL, NULL, NULL, arg);
case GI_TYPE_TAG_FILENAME:
{
object = _pygi_marshal_to_py_filename (NULL, NULL, NULL,
arg);
break;
}
return _pygi_marshal_to_py_filename (NULL, NULL, NULL, arg);
default:
{
object = NULL;
break;
}
return NULL;
}
return object;
return NULL;
}
/**
......
......@@ -59,6 +59,10 @@ 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);
......
......@@ -259,6 +259,12 @@ _arg_cache_alloc (void)
return g_slice_new0 (PyGIArgCache);
}
static void
_arg_cache_to_py_basic_type_setup (PyGIArgCache *arg_cache)
{
arg_cache->to_py_marshaller = _pygi_marshal_to_py_basic_type;
}
static void
_arg_cache_from_py_void_setup (PyGIArgCache *arg_cache)
{
......@@ -277,156 +283,78 @@ _arg_cache_from_py_boolean_setup (PyGIArgCache *arg_cache)
arg_cache->from_py_marshaller = _pygi_marshal_from_py_boolean;
}
static void
_arg_cache_to_py_boolean_setup (PyGIArgCache *arg_cache)
{
arg_cache->to_py_marshaller = _pygi_marshal_to_py_boolean;
}
static void
_arg_cache_from_py_int8_setup (PyGIArgCache *arg_cache)
{
arg_cache->from_py_marshaller = _pygi_marshal_from_py_int8;
}
static void
_arg_cache_to_py_int8_setup (PyGIArgCache *arg_cache)
{
arg_cache->to_py_marshaller = _pygi_marshal_to_py_int8;
}
static void
_arg_cache_from_py_uint8_setup (PyGIArgCache *arg_cache)
{
arg_cache->from_py_marshaller = _pygi_marshal_from_py_uint8;
}
static void
_arg_cache_to_py_uint8_setup (PyGIArgCache *arg_cache)
{
arg_cache->to_py_marshaller = _pygi_marshal_to_py_uint8;
}
static void
_arg_cache_from_py_int16_setup (PyGIArgCache *arg_cache)
{
arg_cache->from_py_marshaller = _pygi_marshal_from_py_int16;
}
static void
_arg_cache_to_py_int16_setup (PyGIArgCache *arg_cache)
{
arg_cache->to_py_marshaller = _pygi_marshal_to_py_int16;
}
static void
_arg_cache_from_py_uint16_setup (PyGIArgCache *arg_cache)
{
arg_cache->from_py_marshaller = _pygi_marshal_from_py_uint16;
}
static void
_arg_cache_to_py_uint16_setup (PyGIArgCache *arg_cache)
{
arg_cache->to_py_marshaller = _pygi_marshal_to_py_uint16;
}
static void
_arg_cache_from_py_int32_setup (PyGIArgCache *arg_cache)
{
arg_cache->from_py_marshaller = _pygi_marshal_from_py_int32;
}
static void
_arg_cache_to_py_int32_setup (PyGIArgCache *arg_cache)
{
arg_cache->to_py_marshaller = _pygi_marshal_to_py_int32;
}
static void
_arg_cache_from_py_uint32_setup (PyGIArgCache *arg_cache)
{
arg_cache->from_py_marshaller = _pygi_marshal_from_py_uint32;
}
static void
_arg_cache_to_py_uint32_setup (PyGIArgCache *arg_cache)
{
arg_cache->to_py_marshaller = _pygi_marshal_to_py_uint32;
}
static void
_arg_cache_from_py_int64_setup (PyGIArgCache *arg_cache)
{
arg_cache->from_py_marshaller = _pygi_marshal_from_py_int64;
}
static void
_arg_cache_to_py_int64_setup (PyGIArgCache *arg_cache)
{
arg_cache->to_py_marshaller = _pygi_marshal_to_py_int64;
}
static void
_arg_cache_from_py_uint64_setup (PyGIArgCache *arg_cache)
{
arg_cache->from_py_marshaller = _pygi_marshal_from_py_uint64;
}
static void
_arg_cache_to_py_uint64_setup (PyGIArgCache *arg_cache)
{
arg_cache->to_py_marshaller = _pygi_marshal_to_py_uint64;
}
static void
_arg_cache_from_py_float_setup (PyGIArgCache *arg_cache)
{
arg_cache->from_py_marshaller = _pygi_marshal_from_py_float;
}
static void
_arg_cache_to_py_float_setup (PyGIArgCache *arg_cache)
{
arg_cache->to_py_marshaller = _pygi_marshal_to_py_float;
}
static void
_arg_cache_from_py_double_setup (PyGIArgCache *arg_cache)
{
arg_cache->from_py_marshaller = _pygi_marshal_from_py_double;
}
static void
_arg_cache_to_py_double_setup (PyGIArgCache *arg_cache)
{
arg_cache->to_py_marshaller = _pygi_marshal_to_py_double;
}
static void
_arg_cache_from_py_unichar_setup (PyGIArgCache *arg_cache)
{
arg_cache->from_py_marshaller = _pygi_marshal_from_py_unichar;
}
static void
_arg_cache_to_py_unichar_setup (PyGIArgCache *arg_cache)
{
arg_cache->to_py_marshaller = _pygi_marshal_to_py_unichar;
}
static void
_arg_cache_from_py_gtype_setup (PyGIArgCache *arg_cache)
{
arg_cache->from_py_marshaller = _pygi_marshal_from_py_gtype;
}
static void
_arg_cache_to_py_gtype_setup (PyGIArgCache *arg_cache)
{
arg_cache->to_py_marshaller = _pygi_marshal_to_py_gtype;
}
static void
_arg_cache_from_py_utf8_setup (PyGIArgCache *arg_cache,
GITransfer transfer)
......@@ -439,7 +367,7 @@ static void
_arg_cache_to_py_utf8_setup (PyGIArgCache *arg_cache,
GITransfer transfer)
{
arg_cache->to_py_marshaller = _pygi_marshal_to_py_utf8;
arg_cache->to_py_marshaller = _pygi_marshal_to_py_basic_type;
arg_cache->to_py_cleanup = _pygi_marshal_cleanup_to_py_utf8;
}
......@@ -455,7 +383,7 @@ static void
_arg_cache_to_py_filename_setup (PyGIArgCache *arg_cache,
GITransfer transfer)
{
arg_cache->to_py_marshaller = _pygi_marshal_to_py_filename;
arg_cache->to_py_marshaller = _pygi_marshal_to_py_basic_type;
arg_cache->to_py_cleanup = _pygi_marshal_cleanup_to_py_utf8;
}
......@@ -878,7 +806,7 @@ _arg_cache_new (GITypeInfo *type_info,
_arg_cache_from_py_boolean_setup (arg_cache);
if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
_arg_cache_to_py_boolean_setup (arg_cache);
_arg_cache_to_py_basic_type_setup (arg_cache);
break;
case GI_TYPE_TAG_INT8:
......@@ -890,7 +818,7 @@ _arg_cache_new (GITypeInfo *type_info,
_arg_cache_from_py_int8_setup (arg_cache);
if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
_arg_cache_to_py_int8_setup (arg_cache);
_arg_cache_to_py_basic_type_setup (arg_cache);
break;
case GI_TYPE_TAG_UINT8:
......@@ -902,7 +830,7 @@ _arg_cache_new (GITypeInfo *type_info,
_arg_cache_from_py_uint8_setup (arg_cache);
if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
_arg_cache_to_py_uint8_setup (arg_cache);
_arg_cache_to_py_basic_type_setup (arg_cache);
break;
case GI_TYPE_TAG_INT16:
......@@ -914,7 +842,7 @@ _arg_cache_new (GITypeInfo *type_info,
_arg_cache_from_py_int16_setup (arg_cache);
if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
_arg_cache_to_py_int16_setup (arg_cache);
_arg_cache_to_py_basic_type_setup (arg_cache);
break;
case GI_TYPE_TAG_UINT16:
......@@ -926,7 +854,7 @@ _arg_cache_new (GITypeInfo *type_info,
_arg_cache_from_py_uint16_setup (arg_cache);
if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
_arg_cache_to_py_uint16_setup (arg_cache);
_arg_cache_to_py_basic_type_setup (arg_cache);
break;
case GI_TYPE_TAG_INT32:
arg_cache = _arg_cache_alloc ();
......@@ -937,7 +865,7 @@ _arg_cache_new (GITypeInfo *type_info,
_arg_cache_from_py_int32_setup (arg_cache);
if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
_arg_cache_to_py_int32_setup (arg_cache);
_arg_cache_to_py_basic_type_setup (arg_cache);
break;
case GI_TYPE_TAG_UINT32:
......@@ -949,7 +877,7 @@ _arg_cache_new (GITypeInfo *type_info,
_arg_cache_from_py_uint32_setup (arg_cache);
if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
_arg_cache_to_py_uint32_setup (arg_cache);
_arg_cache_to_py_basic_type_setup (arg_cache);
break;
case GI_TYPE_TAG_INT64:
......@@ -961,7 +889,7 @@ _arg_cache_new (GITypeInfo *type_info,
_arg_cache_from_py_int64_setup (arg_cache);
if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
_arg_cache_to_py_int64_setup (arg_cache);
_arg_cache_to_py_basic_type_setup (arg_cache);
break;
case GI_TYPE_TAG_UINT64:
......@@ -973,7 +901,7 @@ _arg_cache_new (GITypeInfo *type_info,
_arg_cache_from_py_uint64_setup (arg_cache);
if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
_arg_cache_to_py_uint64_setup (arg_cache);
_arg_cache_to_py_basic_type_setup (arg_cache);
break;
case GI_TYPE_TAG_FLOAT:
......@@ -985,7 +913,7 @@ _arg_cache_new (GITypeInfo *type_info,
_arg_cache_from_py_float_setup (arg_cache);
if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
_arg_cache_to_py_float_setup (arg_cache);
_arg_cache_to_py_basic_type_setup (arg_cache);
break;
case GI_TYPE_TAG_DOUBLE:
......@@ -997,7 +925,7 @@ _arg_cache_new (GITypeInfo *type_info,
_arg_cache_from_py_double_setup (arg_cache);
if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
_arg_cache_to_py_double_setup (arg_cache);
_arg_cache_to_py_basic_type_setup (arg_cache);
break;
case GI_TYPE_TAG_UNICHAR:
......@@ -1009,7 +937,7 @@ _arg_cache_new (GITypeInfo *type_info,
_arg_cache_from_py_unichar_setup (arg_cache);
if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
_arg_cache_to_py_unichar_setup (arg_cache);
_arg_cache_to_py_basic_type_setup (arg_cache);
break;
case GI_TYPE_TAG_GTYPE:
......@@ -1021,7 +949,7 @@ _arg_cache_new (GITypeInfo *type_info,
_arg_cache_from_py_gtype_setup (arg_cache);
if (direction == PYGI_DIRECTION_TO_PYTHON || direction == PYGI_DIRECTION_BIDIRECTIONAL)
_arg_cache_to_py_gtype_setup (arg_cache);
_arg_cache_to_py_basic_type_setup (arg_cache);
break;
case GI_TYPE_TAG_UTF8:
......
......@@ -33,6 +33,7 @@
#include "pygi-cache.h"
#include "pygi-marshal-cleanup.h"
#include "pygi-marshal-to-py.h"
#include "pygi-argument.h"
static gboolean
gi_argument_to_c_long (GIArgument *arg_in,
......@@ -110,6 +111,16 @@ 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,
......@@ -133,125 +144,6 @@ _pygi_marshal_to_py_void (PyGIInvokeState *state,
return py_obj;
}
PyObject *
_pygi_marshal_to_py_boolean (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg)
{
PyObject *py_obj = PyBool_FromLong (arg->v_boolean);
return py_obj;
}
PyObject *
_pygi_marshal_to_py_int8 (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg)
{
PyObject *py_obj = PYGLIB_PyLong_FromLong (arg->v_int8);
return py_obj;
}
PyObject *
_pygi_marshal_to_py_uint8 (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg)
{
PyObject *py_obj = PYGLIB_PyLong_FromLong (arg->v_uint8);
return py_obj;
}
PyObject *
_pygi_marshal_to_py_int16 (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg)
{
PyObject *py_obj = PYGLIB_PyLong_FromLong (arg->v_int16);
return py_obj;
}
PyObject *
_pygi_marshal_to_py_uint16 (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg)
{
PyObject *py_obj = PYGLIB_PyLong_FromLong (arg->v_uint16);
return py_obj;
}
PyObject *
_pygi_marshal_to_py_int32 (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg)
{
PyObject *py_obj = PYGLIB_PyLong_FromLong (arg->v_int32);
return py_obj;
}
PyObject *
_pygi_marshal_to_py_uint32 (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg)
{
PyObject *py_obj = PyLong_FromLongLong (arg->v_uint32);
return py_obj;
}
PyObject *
_pygi_marshal_to_py_int64 (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg)
{
PyObject *py_obj = PyLong_FromLongLong (arg->v_int64);
return py_obj;
}
PyObject *
_pygi_marshal_to_py_uint64 (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg)
{
PyObject *py_obj = PyLong_FromUnsignedLongLong (arg->v_uint64);
return py_obj;
}
PyObject *
_pygi_marshal_to_py_float (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg)
{
PyObject *py_obj = PyFloat_FromDouble (arg->v_float);
return py_obj;
}
PyObject *
_pygi_marshal_to_py_double (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg)
{
PyObject *py_obj = PyFloat_FromDouble (arg->v_double);
return py_obj;
}
PyObject *
_pygi_marshal_to_py_unichar (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
......@@ -279,18 +171,6 @@ _pygi_marshal_to_py_unichar (PyGIInvokeState *state,
return py_obj;
}
PyObject *
_pygi_marshal_to_py_gtype (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg)
{
PyObject *py_obj = NULL;
py_obj = pyg_type_wrapper_new ( (GType)arg->v_long);
return py_obj;
}
PyObject *
_pygi_marshal_to_py_utf8 (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
......
......@@ -22,54 +22,14 @@
#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_void (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg);
PyObject *_pygi_marshal_to_py_boolean (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg);
PyObject *_pygi_marshal_to_py_int8 (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg);
PyObject *_pygi_marshal_to_py_uint8 (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,
GIArgument *arg);
PyObject *_pygi_marshal_to_py_int16 (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
PyGIArgCache *arg_cache,