From 03acd85dbf94b7c5cede331597cca9b22365fb4f Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Wed, 5 Dec 2007 12:51:23 +0000 Subject: [PATCH] merge -r59315:59316 from py3k: Fix issue #1553: An errornous __length_hint__ can make list() raise a SystemError --- Misc/NEWS | 3 +++ Objects/abstract.c | 5 +++-- Objects/listobject.c | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index 735b073bd1e..24a43f09d43 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ What's New in Python 2.5.2c1? Core and builtins ----------------- +- Issue #1553: An errornous __length_hint__ can make list() raise a + SystemError. + - Issue #1521: On 64bit platforms, using PyArgs_ParseTuple with the t# of w# format code incorrectly truncated the length to an int, even when PY_SSIZE_T_CLEAN is set. The str.decode method used to return incorrect diff --git a/Objects/abstract.c b/Objects/abstract.c index f7a3bfefb6c..fb123db6f78 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -1507,8 +1507,9 @@ PySequence_Tuple(PyObject *v) /* Guess result size and allocate space. */ n = _PyObject_LengthHint(v); if (n < 0) { - if (!PyErr_ExceptionMatches(PyExc_TypeError) && - !PyErr_ExceptionMatches(PyExc_AttributeError)) { + if (PyErr_Occurred() + && !PyErr_ExceptionMatches(PyExc_TypeError) + && !PyErr_ExceptionMatches(PyExc_AttributeError)) { Py_DECREF(it); return NULL; } diff --git a/Objects/listobject.c b/Objects/listobject.c index 75ba6d071a3..c0d0e090dfa 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -784,8 +784,9 @@ listextend(PyListObject *self, PyObject *b) /* Guess a result list size. */ n = _PyObject_LengthHint(b); if (n < 0) { - if (!PyErr_ExceptionMatches(PyExc_TypeError) && - !PyErr_ExceptionMatches(PyExc_AttributeError)) { + if (PyErr_Occurred() + && !PyErr_ExceptionMatches(PyExc_TypeError) + && !PyErr_ExceptionMatches(PyExc_AttributeError)) { Py_DECREF(it); return NULL; }