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

Unify Python unicode to unichar GI marshaling code

Change _pygi_argument_from_object to use the cachers marshaler
(_pygi_marshal_from_py_unichar) directly instead of keeping a
copy of the code.

https://bugzilla.gnome.org/show_bug.cgi?id=693405
parent 216caf59
......@@ -1035,38 +1035,8 @@ _pygi_argument_from_object (PyObject *object,
}
case GI_TYPE_TAG_UNICHAR:
{
gchar *string;
if (object == Py_None) {
arg.v_uint32 = 0;
break;
}
#if PY_VERSION_HEX < 0x03000000
if (PyUnicode_Check(object)) {
PyObject *pystr_obj = PyUnicode_AsUTF8String (object);
if (!pystr_obj)
break;
string = g_strdup(PyString_AsString (pystr_obj));
Py_DECREF(pystr_obj);
} else {
string = g_strdup(PyString_AsString (object));
}
#else
{
PyObject *pybytes_obj = PyUnicode_AsUTF8String (object);
if (!pybytes_obj)
break;
string = g_strdup(PyBytes_AsString (pybytes_obj));
Py_DECREF (pybytes_obj);
}
#endif
arg.v_uint32 = g_utf8_get_char (string);
_pygi_marshal_from_py_unichar (NULL, NULL, NULL,
object, &arg);
break;
}
case GI_TYPE_TAG_UTF8:
......
......@@ -768,11 +768,19 @@ _pygi_marshal_from_py_unichar (PyGIInvokeState *state,
Py_ssize_t size;
gchar *string_;
if (py_arg == Py_None) {
arg->v_uint32 = 0;
return FALSE;
}
if (PyUnicode_Check (py_arg)) {
PyObject *py_bytes;
size = PyUnicode_GET_SIZE (py_arg);
py_bytes = PyUnicode_AsUTF8String (py_arg);
if (!py_bytes)
return FALSE;
string_ = g_strdup(PYGLIB_PyBytes_AsString (py_bytes));
Py_DECREF (py_bytes);
......@@ -804,6 +812,7 @@ _pygi_marshal_from_py_unichar (PyGIInvokeState *state,
return TRUE;
}
gboolean
_pygi_marshal_from_py_gtype (PyGIInvokeState *state,
PyGICallableCache *callable_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