[pygobject] Unify Python unicode to unichar GI marshaling code
- From: Simon Feltman <sfeltman src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Unify Python unicode to unichar GI marshaling code
- Date: Fri, 5 Apr 2013 11:13:54 +0000 (UTC)
commit e253c73335fccabc61e0329f8528a90f79858c67
Author: Simon Feltman <sfeltman src gnome org>
Date: Sat Feb 16 19:16:43 2013 -0800
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
gi/pygi-argument.c | 34 ++--------------------------------
gi/pygi-marshal-from-py.c | 9 +++++++++
2 files changed, 11 insertions(+), 32 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 6cb8417..a72239c 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -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:
diff --git a/gi/pygi-marshal-from-py.c b/gi/pygi-marshal-from-py.c
index 289aff2..debdfc1 100644
--- a/gi/pygi-marshal-from-py.c
+++ b/gi/pygi-marshal-from-py.c
@@ -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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]