Discussion:
[Python-3000-checkins] r65345 - in python/branches/py3k: Lib/test/test_builtin.py Lib/test/test_exceptions.py Lib/test/test_unicode.py Objects/unicodeobject.c Python/bltinmodule.c
amaury.forgeotdarc
2008-08-01 01:06:32 UTC
Permalink
Author: amaury.forgeotdarc
Date: Fri Aug 1 03:06:32 2008
New Revision: 65345

Log:
Merged revisions 65339-65340,65342 via svnmerge from
svn+ssh://pythondev at svn.python.org/python/trunk

........
r65339 | amaury.forgeotdarc | 2008-07-31 23:28:03 +0200 (jeu., 31 juil. 2008) | 5 lines

#3479: unichr(2**32) used to return u'\x00'.
The argument was fetched in a long, but PyUnicode_FromOrdinal takes an int.

(why doesn't gcc issue a truncation warning in this case?)
........
r65340 | amaury.forgeotdarc | 2008-07-31 23:35:03 +0200 (jeu., 31 juil. 2008) | 2 lines

Remove a dummy test that was checked in by mistake
........
r65342 | amaury.forgeotdarc | 2008-08-01 01:39:05 +0200 (ven., 01 ao?t 2008) | 8 lines

Correct a crash when two successive unicode allocations fail with a MemoryError:
the freelist contained half-initialized objects with freed pointers.

The comment
/* XXX UNREF/NEWREF interface should be more symmetrical */
was copied from tupleobject.c, and appears in some other places.
I sign the petition.
........


Modified:
python/branches/py3k/ (props changed)
python/branches/py3k/Lib/test/test_builtin.py
python/branches/py3k/Lib/test/test_exceptions.py
python/branches/py3k/Lib/test/test_unicode.py
python/branches/py3k/Objects/unicodeobject.c
python/branches/py3k/Python/bltinmodule.c

Modified: python/branches/py3k/Lib/test/test_builtin.py
==============================================================================
--- python/branches/py3k/Lib/test/test_builtin.py (original)
+++ python/branches/py3k/Lib/test/test_builtin.py Fri Aug 1 03:06:32 2008
@@ -216,6 +216,7 @@
self.assertEqual(chr(0x0010FFFF), "\U0010FFFF")
self.assertRaises(ValueError, chr, -1)
self.assertRaises(ValueError, chr, 0x00110000)
+ self.assertRaises((OverflowError, ValueError), chr, 2**32)

def test_cmp(self):
self.assertEqual(cmp(-1, 1), -1)

Modified: python/branches/py3k/Lib/test/test_exceptions.py
==============================================================================
--- python/branches/py3k/Lib/test/test_exceptions.py (original)
+++ python/branches/py3k/Lib/test/test_exceptions.py Fri Aug 1 03:06:32 2008
@@ -12,14 +12,6 @@

class ExceptionTests(unittest.TestCase):

- def test00(self):
- try:
- sys.exit(ValueError('aaa'))
- except SystemExit:
- pass
- finally:
- pass
-
def raise_catch(self, exc, excname):
try:
raise exc("spam")

Modified: python/branches/py3k/Lib/test/test_unicode.py
==============================================================================
--- python/branches/py3k/Lib/test/test_unicode.py (original)
+++ python/branches/py3k/Lib/test/test_unicode.py Fri Aug 1 03:06:32 2008
@@ -1156,6 +1156,20 @@
self.assertRaises(OverflowError, 't\tt\t'.expandtabs, sys.maxsize)


+ def test_raiseMemError(self):
+ # Ensure that the freelist contains a consistent object, even
+ # when a string allocation fails with a MemoryError.
+ # This used to crash the interpreter,
+ # or leak references when the number was smaller.
+ try:
+ "a" * (sys.maxsize // 2 - 100)
+ except MemoryError:
+ pass
+ try:
+ "a" * (sys.maxsize // 2 - 100)
+ except MemoryError:
+ pass
+
def test_main():
support.run_unittest(__name__)


Modified: python/branches/py3k/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k/Objects/unicodeobject.c (original)
+++ python/branches/py3k/Objects/unicodeobject.c Fri Aug 1 03:06:32 2008
@@ -322,7 +322,7 @@
if ((unicode->length < length) &&
unicode_resize(unicode, length) < 0) {
PyObject_DEL(unicode->str);
- goto onError;
+ unicode->str = NULL;
}
}
else {
@@ -360,6 +360,8 @@
return unicode;

onError:
+ /* XXX UNREF/NEWREF interface should be more symmetrical */
+ _Py_DEC_REFTOTAL;
_Py_ForgetReference((PyObject *)unicode);
PyObject_Del(unicode);
return NULL;

Modified: python/branches/py3k/Python/bltinmodule.c
==============================================================================
--- python/branches/py3k/Python/bltinmodule.c (original)
+++ python/branches/py3k/Python/bltinmodule.c Fri Aug 1 03:06:32 2008
@@ -454,9 +454,9 @@
static PyObject *
builtin_chr(PyObject *self, PyObject *args)
{
- long x;
+ int x;

- if (!PyArg_ParseTuple(args, "l:chr", &x))
+ if (!PyArg_ParseTuple(args, "i:chr", &x))
return NULL;

return PyUnicode_FromOrdinal(x);

Loading...