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

Skip to content

Commit ae937c0

Browse files
committed
Merged revisions 71722 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r71722 | benjamin.peterson | 2009-04-18 15:12:47 -0500 (Sat, 18 Apr 2009) | 1 line try to initalize all builtin types with PyType_Ready to avoid problems like #5787 ........
1 parent 3324247 commit ae937c0

4 files changed

Lines changed: 79 additions & 8 deletions

File tree

Lib/test/test_descr.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import builtins
12
import types
23
import unittest
34
import warnings
@@ -3586,6 +3587,17 @@ class L(list):
35863587
else:
35873588
self.fail("shouldn't be able to create inheritance cycles")
35883589

3590+
def test_builtin_bases(self):
3591+
# Make sure all the builtin types can have their base queried without
3592+
# segfaulting. See issue #5787.
3593+
builtin_types = [tp for tp in builtins.__dict__.values()
3594+
if isinstance(tp, type)]
3595+
for tp in builtin_types:
3596+
object.__getattribute__(tp, "__bases__")
3597+
if tp is not object:
3598+
self.assertEqual(len(tp.__bases__), 1, tp)
3599+
3600+
35893601
def test_mutable_bases_with_failing_mro(self):
35903602
# Testing mutable bases with failing mro...
35913603
class WorkOnce(type):

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Core and Builtins
1717
from Python/dtoa.c. As a consequence, (e.g.) round(x, 2) now
1818
consistently agrees with format(x, '.2f').
1919

20+
- Issue #5787: object.__getattribute__(some_type, "__bases__") segfaulted on
21+
some builtin types.
22+
2023
- Issue #5772: format(1e100, '<') produces '1e+100', not '1.0e+100'.
2124

2225
- Issue #5515: str.format() type 'n' combined with commas and leading

Objects/frameobject.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,9 @@ static PyObject *builtin_object;
577577
int _PyFrame_Init()
578578
{
579579
builtin_object = PyUnicode_InternFromString("__builtins__");
580-
return (builtin_object != NULL);
580+
if (builtin_object == NULL)
581+
return 0;
582+
return 1;
581583
}
582584

583585
PyFrameObject *

Objects/object.c

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,31 +1479,85 @@ void
14791479
_Py_ReadyTypes(void)
14801480
{
14811481
if (PyType_Ready(&PyType_Type) < 0)
1482-
Py_FatalError("Can't initialize 'type'");
1482+
Py_FatalError("Can't initialize type type");
14831483

14841484
if (PyType_Ready(&_PyWeakref_RefType) < 0)
1485-
Py_FatalError("Can't initialize 'weakref'");
1485+
Py_FatalError("Can't initialize weakref type");
14861486

14871487
if (PyType_Ready(&PyBool_Type) < 0)
1488-
Py_FatalError("Can't initialize 'bool'");
1488+
Py_FatalError("Can't initialize bool type");
14891489

14901490
if (PyType_Ready(&PyByteArray_Type) < 0)
1491-
Py_FatalError("Can't initialize 'bytes'");
1491+
Py_FatalError("Can't initialize bytearray");
14921492

14931493
if (PyType_Ready(&PyBytes_Type) < 0)
14941494
Py_FatalError("Can't initialize 'str'");
14951495

14961496
if (PyType_Ready(&PyList_Type) < 0)
1497-
Py_FatalError("Can't initialize 'list'");
1497+
Py_FatalError("Can't initialize list");
14981498

14991499
if (PyType_Ready(&PyNone_Type) < 0)
1500-
Py_FatalError("Can't initialize type(None)");
1500+
Py_FatalError("Can't initialize None type");
15011501

15021502
if (PyType_Ready(Py_Ellipsis->ob_type) < 0)
15031503
Py_FatalError("Can't initialize type(Ellipsis)");
15041504

15051505
if (PyType_Ready(&PyNotImplemented_Type) < 0)
1506-
Py_FatalError("Can't initialize type(NotImplemented)");
1506+
Py_FatalError("Can't initialize NotImplemented type");
1507+
1508+
if (PyType_Ready(&PyTraceBack_Type) < 0)
1509+
Py_FatalError("Can't initialize traceback type");
1510+
1511+
if (PyType_Ready(&PySuper_Type) < 0)
1512+
Py_FatalError("Can't initialize super type");
1513+
1514+
if (PyType_Ready(&PyBaseObject_Type) < 0)
1515+
Py_FatalError("Can't initialize object type");
1516+
1517+
if (PyType_Ready(&PyRange_Type) < 0)
1518+
Py_FatalError("Can't initialize range type");
1519+
1520+
if (PyType_Ready(&PyDict_Type) < 0)
1521+
Py_FatalError("Can't initialize dict type");
1522+
1523+
if (PyType_Ready(&PySet_Type) < 0)
1524+
Py_FatalError("Can't initialize set type");
1525+
1526+
if (PyType_Ready(&PyUnicode_Type) < 0)
1527+
Py_FatalError("Can't initialize str type");
1528+
1529+
if (PyType_Ready(&PySlice_Type) < 0)
1530+
Py_FatalError("Can't initialize slice type");
1531+
1532+
if (PyType_Ready(&PyStaticMethod_Type) < 0)
1533+
Py_FatalError("Can't initialize static method type");
1534+
1535+
if (PyType_Ready(&PyComplex_Type) < 0)
1536+
Py_FatalError("Can't initialize complex type");
1537+
1538+
if (PyType_Ready(&PyFloat_Type) < 0)
1539+
Py_FatalError("Can't initialize float type");
1540+
1541+
if (PyType_Ready(&PyLong_Type) < 0)
1542+
Py_FatalError("Can't initialize int type");
1543+
1544+
if (PyType_Ready(&PyFrozenSet_Type) < 0)
1545+
Py_FatalError("Can't initialize frozenset type");
1546+
1547+
if (PyType_Ready(&PyProperty_Type) < 0)
1548+
Py_FatalError("Can't initialize property type");
1549+
1550+
if (PyType_Ready(&PyMemoryView_Type) < 0)
1551+
Py_FatalError("Can't initialize memoryview type");
1552+
1553+
if (PyType_Ready(&PyTuple_Type) < 0)
1554+
Py_FatalError("Can't initialize tuple type");
1555+
1556+
if (PyType_Ready(&PyEnum_Type) < 0)
1557+
Py_FatalError("Can't initialize enumerate type");
1558+
1559+
if (PyType_Ready(&PyReversed_Type) < 0)
1560+
Py_FatalError("Can't initialize reversed type");
15071561

15081562
if (PyType_Ready(&PyCode_Type) < 0)
15091563
Py_FatalError("Can't initialize 'code'");

0 commit comments

Comments
 (0)