summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Ehresman <jpe@wingware.com>2010-04-13 11:46:28 -0400
committerJohn Ehresman <jpe@wingware.com>2010-04-15 12:13:35 -0400
commitec3473468d688922c38f2b8e0f0168ab1c774dd7 (patch)
treeef5f110182cdd721c8439952d78ddc04befd4741
parent1459fd6e361453953fca4e62ab544703ef70f4a9 (diff)
downloadpygobject-ec3473468d688922c38f2b8e0f0168ab1c774dd7.tar.gz
pygobject-ec3473468d688922c38f2b8e0f0168ab1c774dd7.tar.xz
pygobject-ec3473468d688922c38f2b8e0f0168ab1c774dd7.zip
Return byte array from read_chars iff encoding is NULL, otherwise return a unicode instance in python 3
-rw-r--r--glib/pygiochannel.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/glib/pygiochannel.c b/glib/pygiochannel.c
index fbaa9bd..15510e5 100644
--- a/glib/pygiochannel.c
+++ b/glib/pygiochannel.c
@@ -204,16 +204,16 @@ py_io_channel_read_chars(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
}
if ( ret_obj == NULL ) {
- ret_obj = _PyUnicode_FromStringAndSize((char *)NULL, buf_size);
+ ret_obj = _PyByteArray_FromStringAndSize((char *)NULL, buf_size);
if (ret_obj == NULL)
goto failure;
}
- else if (buf_size + total_read > _PyUnicode_GET_SIZE(ret_obj)) {
- if (_PyUnicode_Resize(&ret_obj, buf_size + total_read) == -1)
+ else if (buf_size + total_read > _PyByteArray_Size(ret_obj)) {
+ if (_PyByteArray_Resize(&ret_obj, buf_size + total_read) == -1)
goto failure;
}
- buf = _PyUnicode_AS_STRING(ret_obj) + total_read;
+ buf = _PyByteArray_AsString(ret_obj) + total_read;
pyglib_unblock_threads();
status = g_io_channel_read_chars(self->channel, buf, buf_size,
@@ -225,10 +225,26 @@ py_io_channel_read_chars(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
total_read += single_read;
}
- if ( total_read != _PyUnicode_GET_SIZE(ret_obj) ) {
- if (_PyUnicode_Resize(&ret_obj, total_read) == -1)
+ if ( total_read != _PyByteArray_Size(ret_obj) ) {
+ if (_PyByteArray_Resize(&ret_obj, total_read) == -1)
goto failure;
}
+
+ if (g_io_channel_get_encoding(self->channel) == NULL)
+ return ret_obj;
+
+#if PY_VERSION_HEX >= 0x03000000
+ {
+ PyObject *unicode_obj;
+
+ unicode_obj = PyUnicode_FromString(PyByteArray_AS_STRING(ret_obj));
+ if (unicode_obj == NULL)
+ goto failure;
+ Py_DECREF(ret_obj);
+ ret_obj = unicode_obj;
+ }
+#endif
+
return ret_obj;
failure: