[pygobject] Fix various bugs in GLib.IOChannel
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Fix various bugs in GLib.IOChannel
- Date: Wed, 24 Oct 2012 10:54:09 +0000 (UTC)
commit 0e1a6ccee45ae2239da1c44de1866596343165ba
Author: Martin Pitt <martinpitt gnome org>
Date: Wed Oct 24 12:50:50 2012 +0200
Fix various bugs in GLib.IOChannel
- Fix segfault when using an IOChannel as an iterator: PyIter_Next() returns
NULL on the last element, instead of raising a StopIteration.
- The default encoding of a stream is 'UTF-8', not NULL. NULL means that the
stream is being used in binary mode; in that case, we should not attempt to
do any automagic conversion to an Unicode object. As this special case is
inconsistent and has never worked anyway, and the current buggy
implementation breaks binary streams, just drop it without replacement.
(Introduced in commit de9eae4dfcce8)
These bugs were uncovered by the previously committed tests.
gi/_glib/pygiochannel.c | 25 +++++--------------------
1 files changed, 5 insertions(+), 20 deletions(-)
---
diff --git a/gi/_glib/pygiochannel.c b/gi/_glib/pygiochannel.c
index 0288145..722fd0d 100644
--- a/gi/_glib/pygiochannel.c
+++ b/gi/_glib/pygiochannel.c
@@ -191,7 +191,7 @@ py_io_channel_read_chars(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
return NULL;
if (max_count == 0)
- return PYGLIB_PyUnicode_FromString("");
+ return PYGLIB_PyBytes_FromString("");
while (status == G_IO_STATUS_NORMAL
&& (max_count == -1 || total_read < max_count)) {
@@ -234,23 +234,6 @@ py_io_channel_read_chars(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
goto failure;
}
-#if PY_VERSION_HEX >= 0x03000000
- /* If this is not UTF8 encoded channel return the raw bytes */
- if (g_io_channel_get_encoding(self->channel) != NULL)
- return ret_obj;
-
- /* convert to Unicode string */
- {
- PyObject *unicode_obj;
-
- unicode_obj = PyUnicode_FromString(PyBytes_AS_STRING(ret_obj));
- if (unicode_obj == NULL)
- goto failure;
- Py_DECREF(ret_obj);
- ret_obj = unicode_obj;
- }
-#endif
-
return ret_obj;
failure:
@@ -298,9 +281,11 @@ py_io_channel_write_lines(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
while (1) {
value = PyIter_Next(iter);
+ if (value == NULL)
+ break;
if (PyErr_ExceptionMatches(PyExc_StopIteration)) {
PyErr_Clear();
- goto normal_exit;
+ break;
}
if (!PYGLIB_PyUnicode_Check(value)) {
PyErr_SetString(PyExc_TypeError, "gi._glib.IOChannel.writelines must"
@@ -318,7 +303,7 @@ py_io_channel_write_lines(PyGIOChannel* self, PyObject *args, PyObject *kwargs)
return NULL;
}
}
-normal_exit:
+
Py_DECREF(iter);
Py_INCREF(Py_None);
return Py_None;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]