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

Move _pygi_argument_from_object_basic_type into pygi-marshal-from-py.c

Move _pygi_argument_from_object_basic_type into pygi-marshal-from-py.c
and rename to: _pygi_marshal_from_py_basic_type

https://bugzilla.gnome.org/show_bug.cgi?id=693405
parent 9c9510ee
......@@ -887,153 +887,6 @@ _pygi_argument_to_array (GIArgument *arg,
return g_array;
}
static gboolean
_pygi_argument_from_object_basic_type (PyObject *object, /* in */
GIArgument *arg, /* out */
GITypeTag type_tag,
GITransfer transfer)
{
switch (type_tag) {
case GI_TYPE_TAG_VOID:
g_warn_if_fail (transfer == GI_TRANSFER_NOTHING);
if (object == Py_None) {
arg->v_pointer = NULL;
} else if (!PYGLIB_PyLong_Check(object) && !PyLong_Check(object)) {
PyErr_SetString(PyExc_TypeError,
"Pointer assignment is restricted to integer values. "
"See: https://bugzilla.gnome.org/show_bug.cgi?id=683599");
} else {
arg->v_pointer = PyLong_AsVoidPtr (object);
}
break;
case GI_TYPE_TAG_BOOLEAN:
{
arg->v_boolean = PyObject_IsTrue (object);
break;
}
case GI_TYPE_TAG_INT8:
case GI_TYPE_TAG_INT16:
case GI_TYPE_TAG_INT32:
{
PyObject *int_;
int_ = PYGLIB_PyNumber_Long (object);
if (int_ == NULL) {
PyErr_SetString (PyExc_TypeError, "expected int argument");
break;
}
if (type_tag == GI_TYPE_TAG_INT32)
arg->v_int32 = PYGLIB_PyLong_AsLong (int_);
else if (type_tag == GI_TYPE_TAG_INT8)
arg->v_int8 = PYGLIB_PyLong_AsLong (int_);
else if (type_tag == GI_TYPE_TAG_INT16)
arg->v_int16 = PYGLIB_PyLong_AsLong (int_);
Py_DECREF (int_);
break;
}
case GI_TYPE_TAG_UINT8:
case GI_TYPE_TAG_UINT16:
case GI_TYPE_TAG_UINT32:
case GI_TYPE_TAG_UINT64:
{
PyObject *number;
guint64 value;
number = PYGLIB_PyNumber_Long (object);
if (number == NULL) {
PyErr_SetString (PyExc_TypeError, "expected int argument");
break;
}
#if PY_VERSION_HEX < 0x03000000
if (PyInt_Check (number)) {
value = PyInt_AS_LONG (number);
} else
#endif
value = PyLong_AsUnsignedLongLong (number);
if (type_tag == GI_TYPE_TAG_UINT32)
arg->v_uint32 = value;
else if (type_tag == GI_TYPE_TAG_UINT64)
arg->v_uint64 = value;
else if (type_tag == GI_TYPE_TAG_UINT8)
arg->v_uint8 = value;
else if (type_tag == GI_TYPE_TAG_UINT16)
arg->v_uint16 = value;
Py_DECREF (number);
break;
}
case GI_TYPE_TAG_INT64:
{
PyObject *number;
gint64 value;
number = PYGLIB_PyNumber_Long (object);
if (number == NULL) {
PyErr_SetString (PyExc_TypeError, "expected int argument");
break;
}
#if PY_VERSION_HEX < 0x03000000
if (PyInt_Check (number)) {
value = PyInt_AS_LONG (number);
} else
#endif
value = PyLong_AsLongLong (number);
arg->v_int64 = value;
Py_DECREF (number);
break;
}
case GI_TYPE_TAG_FLOAT:
{
_pygi_marshal_from_py_float (NULL, NULL, NULL,
object, arg);
break;
}
case GI_TYPE_TAG_DOUBLE:
{
_pygi_marshal_from_py_double (NULL, NULL, NULL,
object, arg);
break;
}
case GI_TYPE_TAG_GTYPE:
{
arg->v_long = pyg_type_from_object (object);
break;
}
case GI_TYPE_TAG_UNICHAR:
{
_pygi_marshal_from_py_unichar (NULL, NULL, NULL,
object, arg);
break;
}
case GI_TYPE_TAG_UTF8:
{
_pygi_marshal_from_py_utf8 (NULL, NULL, NULL,
object, arg);
break;
}
case GI_TYPE_TAG_FILENAME:
{
_pygi_marshal_from_py_filename (NULL, NULL, NULL,
object, arg);
break;
}
default:
return FALSE;
}
return TRUE;
}
GIArgument
_pygi_argument_from_object (PyObject *object,
GITypeInfo *type_info,
......@@ -1045,7 +898,7 @@ _pygi_argument_from_object (PyObject *object,
memset(&arg, 0, sizeof(GIArgument));
type_tag = g_type_info_get_tag (type_info);
if (_pygi_argument_from_object_basic_type (object, &arg, type_tag, transfer)) {
if (_pygi_marshal_from_py_basic_type (object, &arg, type_tag, transfer)) {
return arg;
}
......
......@@ -923,6 +923,153 @@ _pygi_marshal_from_py_filename (PyGIInvokeState *state,
return TRUE;
}
gboolean
_pygi_marshal_from_py_basic_type (PyObject *object, /* in */
GIArgument *arg, /* out */
GITypeTag type_tag,
GITransfer transfer)
{
switch (type_tag) {
case GI_TYPE_TAG_VOID:
g_warn_if_fail (transfer == GI_TRANSFER_NOTHING);
if (object == Py_None) {
arg->v_pointer = NULL;
} else if (!PYGLIB_PyLong_Check(object) && !PyLong_Check(object)) {
PyErr_SetString(PyExc_TypeError,
"Pointer assignment is restricted to integer values. "
"See: https://bugzilla.gnome.org/show_bug.cgi?id=683599");
} else {
arg->v_pointer = PyLong_AsVoidPtr (object);
}
break;
case GI_TYPE_TAG_BOOLEAN:
{
arg->v_boolean = PyObject_IsTrue (object);
break;
}
case GI_TYPE_TAG_INT8:
case GI_TYPE_TAG_INT16:
case GI_TYPE_TAG_INT32:
{
PyObject *int_;
int_ = PYGLIB_PyNumber_Long (object);
if (int_ == NULL) {
PyErr_SetString (PyExc_TypeError, "expected int argument");
break;
}
if (type_tag == GI_TYPE_TAG_INT32)
arg->v_int32 = PYGLIB_PyLong_AsLong (int_);
else if (type_tag == GI_TYPE_TAG_INT8)
arg->v_int8 = PYGLIB_PyLong_AsLong (int_);
else if (type_tag == GI_TYPE_TAG_INT16)
arg->v_int16 = PYGLIB_PyLong_AsLong (int_);
Py_DECREF (int_);
break;
}
case GI_TYPE_TAG_UINT8:
case GI_TYPE_TAG_UINT16:
case GI_TYPE_TAG_UINT32:
case GI_TYPE_TAG_UINT64:
{
PyObject *number;
guint64 value;
number = PYGLIB_PyNumber_Long (object);
if (number == NULL) {
PyErr_SetString (PyExc_TypeError, "expected int argument");
break;
}
#if PY_VERSION_HEX < 0x03000000
if (PyInt_Check (number)) {
value = PyInt_AS_LONG (number);
} else
#endif
value = PyLong_AsUnsignedLongLong (number);
if (type_tag == GI_TYPE_TAG_UINT32)
arg->v_uint32 = value;
else if (type_tag == GI_TYPE_TAG_UINT64)
arg->v_uint64 = value;
else if (type_tag == GI_TYPE_TAG_UINT8)
arg->v_uint8 = value;
else if (type_tag == GI_TYPE_TAG_UINT16)
arg->v_uint16 = value;
Py_DECREF (number);
break;
}
case GI_TYPE_TAG_INT64:
{
PyObject *number;
gint64 value;
number = PYGLIB_PyNumber_Long (object);
if (number == NULL) {
PyErr_SetString (PyExc_TypeError, "expected int argument");
break;
}
#if PY_VERSION_HEX < 0x03000000
if (PyInt_Check (number)) {
value = PyInt_AS_LONG (number);
} else
#endif
value = PyLong_AsLongLong (number);
arg->v_int64 = value;
Py_DECREF (number);
break;
}
case GI_TYPE_TAG_FLOAT:
{
_pygi_marshal_from_py_float (NULL, NULL, NULL,
object, arg);
break;
}
case GI_TYPE_TAG_DOUBLE:
{
_pygi_marshal_from_py_double (NULL, NULL, NULL,
object, arg);
break;
}
case GI_TYPE_TAG_GTYPE:
{
arg->v_long = pyg_type_from_object (object);
break;
}
case GI_TYPE_TAG_UNICHAR:
{
_pygi_marshal_from_py_unichar (NULL, NULL, NULL,
object, arg);
break;
}
case GI_TYPE_TAG_UTF8:
{
_pygi_marshal_from_py_utf8 (NULL, NULL, NULL,
object, arg);
break;
}
case GI_TYPE_TAG_FILENAME:
{
_pygi_marshal_from_py_filename (NULL, NULL, NULL,
object, arg);
break;
}
default:
return FALSE;
}
return TRUE;
}
gboolean
_pygi_marshal_from_py_array (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
......
......@@ -185,6 +185,10 @@ gboolean _pygi_marshal_from_py_interface_instance (PyGIInvokeState *state,
GIArgument *arg);
/* Simplified marshalers shared between vfunc/closure and direct function calls. */
gboolean _pygi_marshal_from_py_basic_type (PyObject *object, /* in */
GIArgument *arg, /* out */
GITypeTag type_tag,
GITransfer transfer);
gboolean pygi_marshal_from_py_gobject (PyObject *py_arg, /*in*/
GIArgument *arg, /*out*/
......
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