summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-08-11 19:46:49 (GMT)
committerBenjamin Peterson <benjamin@python.org>2011-08-11 19:46:49 (GMT)
commitff3d3e4c7a0f2e26e814d84c228144209d39c26f (patch)
treeb220ca7c7742f01ead0f8f9e20063c04cf59e37f
parentb684702259e064e0b03d92169a9aacbd5427d3d0 (diff)
parentfdf4a274220d3167234792e91f29eb935c78e15d (diff)
downloadcpython-ff3d3e4c7a0f2e26e814d84c228144209d39c26f.zip
cpython-ff3d3e4c7a0f2e26e814d84c228144209d39c26f.tar.gz
cpython-ff3d3e4c7a0f2e26e814d84c228144209d39c26f.tar.bz2
merge heads
-rw-r--r--Doc/c-api/object.rst13
-rw-r--r--Lib/test/pickletester.py13
-rw-r--r--Misc/NEWS3
-rw-r--r--Modules/_pickle.c3
4 files changed, 30 insertions, 2 deletions
diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst
index d0d45ad..88ba5ac 100644
--- a/Doc/c-api/object.rst
+++ b/Doc/c-api/object.rst
@@ -6,6 +6,19 @@ Object Protocol
===============
+.. c:var:: PyObject* Py_NotImplemented
+
+ The ``NotImplemented`` singleton, used to signal that an operation is
+ not implemented for the given type combination.
+
+
+.. c:macro:: Py_RETURN_NOTIMPLEMENTED
+
+ Properly handle returning :c:data:`Py_NotImplemented` from within a C
+ function (that is, increment the reference count of NotImplemented and
+ return it).
+
+
.. c:function:: int PyObject_Print(PyObject *o, FILE *fp, int flags)
Print an object *o*, on file *fp*. Returns ``-1`` on error. The flags argument
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index 45e8f74..f90d348 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -1438,6 +1438,19 @@ class AbstractPicklerUnpicklerObjectTests(unittest.TestCase):
def test_multiple_unpicklings_unseekable(self):
self._check_multiple_unpicklings(UnseekableIO)
+ def test_unpickling_buffering_readline(self):
+ # Issue #12687: the unpickler's buffering logic could fail with
+ # text mode opcodes.
+ data = list(range(10))
+ for proto in protocols:
+ for buf_size in range(1, 11):
+ f = io.BufferedRandom(io.BytesIO(), buffer_size=buf_size)
+ pickler = self.pickler_class(f, protocol=proto)
+ pickler.dump(data)
+ f.seek(0)
+ unpickler = self.unpickler_class(f)
+ self.assertEqual(unpickler.load(), data)
+
if __name__ == "__main__":
# Print some stuff that can be used to rewrite DATA{0,1,2}
diff --git a/Misc/NEWS b/Misc/NEWS
index 109b4a4..34aac79 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -251,6 +251,9 @@ Core and Builtins
Library
-------
+- Issue #12687: Fix a possible buffering bug when unpickling text mode
+ (protocol 0, mostly) pickles.
+
- Issue #10087: Fix the html output format of the calendar module.
- Issue #12540: Prevent zombie IDLE processes on Windows due to changes
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index 06bce1e..f147e3e 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -1034,9 +1034,8 @@ _Unpickler_Readline(UnpicklerObject *self, char **result)
num_read = _Unpickler_ReadFromFile(self, READ_WHOLE_LINE);
if (num_read < 0)
return -1;
- *result = self->input_buffer;
self->next_read_idx = num_read;
- return num_read;
+ return _Unpickler_CopyLine(self, self->input_buffer, num_read, result);
}
/* If we get here, we've run off the end of the input string. Return the