Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7888d08

Browse files
committed
Merged revisions 65339-65340,65342 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent e2e36ba commit 7888d08

5 files changed

Lines changed: 20 additions & 11 deletions

File tree

Lib/test/test_builtin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def test_chr(self):
216216
self.assertEqual(chr(0x0010FFFF), "\U0010FFFF")
217217
self.assertRaises(ValueError, chr, -1)
218218
self.assertRaises(ValueError, chr, 0x00110000)
219+
self.assertRaises((OverflowError, ValueError), chr, 2**32)
219220

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

Lib/test/test_exceptions.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@
1212

1313
class ExceptionTests(unittest.TestCase):
1414

15-
def test00(self):
16-
try:
17-
sys.exit(ValueError('aaa'))
18-
except SystemExit:
19-
pass
20-
finally:
21-
pass
22-
2315
def raise_catch(self, exc, excname):
2416
try:
2517
raise exc("spam")

Lib/test/test_unicode.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,20 @@ def test_expandtabs_overflows_gracefully(self):
11561156
self.assertRaises(OverflowError, 't\tt\t'.expandtabs, sys.maxsize)
11571157

11581158

1159+
def test_raiseMemError(self):
1160+
# Ensure that the freelist contains a consistent object, even
1161+
# when a string allocation fails with a MemoryError.
1162+
# This used to crash the interpreter,
1163+
# or leak references when the number was smaller.
1164+
try:
1165+
"a" * (sys.maxsize // 2 - 100)
1166+
except MemoryError:
1167+
pass
1168+
try:
1169+
"a" * (sys.maxsize // 2 - 100)
1170+
except MemoryError:
1171+
pass
1172+
11591173
def test_main():
11601174
support.run_unittest(__name__)
11611175

Objects/unicodeobject.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ PyUnicodeObject *_PyUnicode_New(Py_ssize_t length)
322322
if ((unicode->length < length) &&
323323
unicode_resize(unicode, length) < 0) {
324324
PyObject_DEL(unicode->str);
325-
goto onError;
325+
unicode->str = NULL;
326326
}
327327
}
328328
else {
@@ -360,6 +360,8 @@ PyUnicodeObject *_PyUnicode_New(Py_ssize_t length)
360360
return unicode;
361361

362362
onError:
363+
/* XXX UNREF/NEWREF interface should be more symmetrical */
364+
_Py_DEC_REFTOTAL;
363365
_Py_ForgetReference((PyObject *)unicode);
364366
PyObject_Del(unicode);
365367
return NULL;

Python/bltinmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,9 @@ format_spec defaults to \"\"");
454454
static PyObject *
455455
builtin_chr(PyObject *self, PyObject *args)
456456
{
457-
long x;
457+
int x;
458458

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

462462
return PyUnicode_FromOrdinal(x);

0 commit comments

Comments
 (0)