Commit 7746d218 authored by Michel Dänzer's avatar Michel Dänzer Committed by Martin Pitt
Browse files

Fix marshalling to/from Python to work on big endian machines.

https://bugzilla.gnome.org/show_bug.cgi?id=668903

Signed-off-by: Martin Pitt's avatarMartin Pitt <martin.pitt@ubuntu.com>
parent 0591cc6f
......@@ -722,15 +722,8 @@ _pygi_argument_from_object (PyObject *object,
arg.v_boolean = PyObject_IsTrue (object);
break;
}
case GI_TYPE_TAG_UINT8:
if (PYGLIB_PyBytes_Check(object)) {
arg.v_long = (long)(PYGLIB_PyBytes_AsString(object)[0]);
break;
}
case GI_TYPE_TAG_INT8:
case GI_TYPE_TAG_INT16:
case GI_TYPE_TAG_UINT16:
case GI_TYPE_TAG_INT32:
{
PyObject *int_;
......@@ -740,12 +733,19 @@ _pygi_argument_from_object (PyObject *object,
break;
}
arg.v_long = PYGLIB_PyLong_AsLong (int_);
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:
{
......@@ -764,7 +764,14 @@ _pygi_argument_from_object (PyObject *object,
#endif
value = PyLong_AsUnsignedLongLong (number);
arg.v_uint64 = value;
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);
......
......@@ -145,7 +145,7 @@ _pygi_marshal_from_py_int8 (PyGIInvokeState *state,
return FALSE;
}
arg->v_long = long_;
arg->v_int8 = long_;
return TRUE;
}
......@@ -194,7 +194,7 @@ _pygi_marshal_from_py_uint8 (PyGIInvokeState *state,
return FALSE;
}
arg->v_long = long_;
arg->v_uint8 = long_;
return TRUE;
}
......@@ -233,7 +233,7 @@ _pygi_marshal_from_py_int16 (PyGIInvokeState *state,
return FALSE;
}
arg->v_long = long_;
arg->v_int16 = long_;
return TRUE;
}
......@@ -272,7 +272,7 @@ _pygi_marshal_from_py_uint16 (PyGIInvokeState *state,
return FALSE;
}
arg->v_long = long_;
arg->v_uint16 = long_;
return TRUE;
}
......@@ -311,7 +311,7 @@ _pygi_marshal_from_py_int32 (PyGIInvokeState *state,
return FALSE;
}
arg->v_long = long_;
arg->v_int32 = long_;
return TRUE;
}
......@@ -356,7 +356,7 @@ _pygi_marshal_from_py_uint32 (PyGIInvokeState *state,
return FALSE;
}
arg->v_uint64 = long_;
arg->v_uint32 = long_;
return TRUE;
}
......@@ -1041,6 +1041,22 @@ err:
return TRUE;
}
static gpointer
_pygi_arg_to_hash_pointer (const GIArgument *arg,
GITypeTag type_tag)
{
switch (type_tag) {
case GI_TYPE_TAG_INT32:
return GINT_TO_POINTER(arg->v_int32);
case GI_TYPE_TAG_UTF8:
case GI_TYPE_TAG_FILENAME:
return arg->v_pointer;
default:
g_assert_not_reached();
return arg->v_pointer;
}
}
gboolean
_pygi_marshal_from_py_ghash (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
......@@ -1128,7 +1144,9 @@ _pygi_marshal_from_py_ghash (PyGIInvokeState *state,
&value))
goto err;
g_hash_table_insert (hash_, key.v_pointer, value.v_pointer);
g_hash_table_insert (hash_,
_pygi_arg_to_hash_pointer (&key, hash_cache->key_cache->type_tag),
_pygi_arg_to_hash_pointer (&value, hash_cache->value_cache->type_tag));
continue;
err:
/* FIXME: cleanup hash keys and values */
......
......@@ -511,6 +511,22 @@ _pygi_marshal_to_py_gslist (PyGIInvokeState *state,
return py_obj;
}
static void
_pygi_hash_pointer_to_arg (GIArgument *arg,
GITypeTag type_tag)
{
switch (type_tag) {
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:
break;
default:
g_assert_not_reached();
}
}
PyObject *
_pygi_marshal_to_py_ghash (PyGIInvokeState *state,
PyGICallableCache *callable_cache,
......@@ -558,6 +574,8 @@ _pygi_marshal_to_py_ghash (PyGIInvokeState *state,
PyObject *py_value;
int retval;
_pygi_hash_pointer_to_arg (&key_arg, hash_cache->key_cache->type_tag);
py_key = key_to_py_marshaller ( state,
callable_cache,
key_arg_cache,
......@@ -568,6 +586,7 @@ _pygi_marshal_to_py_ghash (PyGIInvokeState *state,
return NULL;
}
_pygi_hash_pointer_to_arg (&value_arg, hash_cache->value_cache->type_tag);
py_value = value_to_py_marshaller ( state,
callable_cache,
value_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