]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 71727 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Sat, 18 Apr 2009 21:10:48 +0000 (21:10 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sat, 18 Apr 2009 21:10:48 +0000 (21:10 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r71727 | benjamin.peterson | 2009-04-18 15:54:08 -0500 (Sat, 18 Apr 2009) | 9 lines

  Merged revisions 71722 via svnmerge from
  svn+ssh://pythondev@svn.python.org/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
  ........
................

Lib/test/test_descr.py
Misc/NEWS
Objects/frameobject.c
Objects/object.c

index 8d43d7ae36232801a31a37da67d3b85eaba7bfa3..8b27af050b1d7879bafbf0c33ce0eb415a5f1749 100644 (file)
@@ -1,3 +1,4 @@
+import builtins
 import types
 import unittest
 import warnings
@@ -3538,6 +3539,17 @@ order (MRO) for bases """
         else:
             self.fail("shouldn't be able to create inheritance cycles")
 
+    def test_builtin_bases(self):
+        # Make sure all the builtin types can have their base queried without
+        # segfaulting. See issue #5787.
+        builtin_types = [tp for tp in builtins.__dict__.values()
+                         if isinstance(tp, type)]
+        for tp in builtin_types:
+            object.__getattribute__(tp, "__bases__")
+            if tp is not object:
+                self.assertEqual(len(tp.__bases__), 1, tp)
+
+
     def test_mutable_bases_with_failing_mro(self):
         # Testing mutable bases with failing mro...
         class WorkOnce(type):
index 356d36aa7646ab204cf389c1499694537837cd1e..99d44cd62bd4c8e549a3db3371e4e783a3e3005c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -18,6 +18,9 @@ Core and Builtins
 
 - Issue #5759: float() didn't call __float__ on str subclasses.
 
+- Issue #5787: object.__getattribute__(some_type, "__bases__") segfaulted on
+  some builtin types.
+
 - Issue #5392: when a very low recursion limit was set, the interpreter would
   abort with a fatal error after the recursion limit was hit twice.
 
index 52898ccb023373f66b0edd491c9af1f069d05971..e29c64742c0bc3f924964a36d6c6a9b9e5118b63 100644 (file)
@@ -577,7 +577,9 @@ static PyObject *builtin_object;
 int _PyFrame_Init()
 {
        builtin_object = PyUnicode_InternFromString("__builtins__");
-       return (builtin_object != NULL);
+       if (builtin_object == NULL)
+               return 0;
+       return 1;
 }
 
 PyFrameObject *
index 298cacc1d758bd6f844786ffcb47e18fd0072c0a..5c0b06afe4aa82dd4e23fdd034eb7df7d87a0723 100644 (file)
@@ -1462,31 +1462,85 @@ void
 _Py_ReadyTypes(void)
 {
        if (PyType_Ready(&PyType_Type) < 0)
-               Py_FatalError("Can't initialize 'type'");
+               Py_FatalError("Can't initialize type type");
 
        if (PyType_Ready(&_PyWeakref_RefType) < 0)
-               Py_FatalError("Can't initialize 'weakref'");
+               Py_FatalError("Can't initialize weakref type");
 
        if (PyType_Ready(&PyBool_Type) < 0)
-               Py_FatalError("Can't initialize 'bool'");
+               Py_FatalError("Can't initialize bool type");
 
        if (PyType_Ready(&PyByteArray_Type) < 0)
-               Py_FatalError("Can't initialize 'bytes'");
+               Py_FatalError("Can't initialize bytearray");
 
        if (PyType_Ready(&PyBytes_Type) < 0)
                Py_FatalError("Can't initialize 'str'");
 
        if (PyType_Ready(&PyList_Type) < 0)
-               Py_FatalError("Can't initialize 'list'");
+               Py_FatalError("Can't initialize list");
 
        if (PyType_Ready(&PyNone_Type) < 0)
-               Py_FatalError("Can't initialize type(None)");
+               Py_FatalError("Can't initialize None type");
 
        if (PyType_Ready(Py_Ellipsis->ob_type) < 0)
                Py_FatalError("Can't initialize type(Ellipsis)");
 
        if (PyType_Ready(&PyNotImplemented_Type) < 0)
-               Py_FatalError("Can't initialize type(NotImplemented)");
+               Py_FatalError("Can't initialize NotImplemented type");
+
+       if (PyType_Ready(&PyTraceBack_Type) < 0)
+               Py_FatalError("Can't initialize traceback type");
+
+       if (PyType_Ready(&PySuper_Type) < 0)
+               Py_FatalError("Can't initialize super type");
+
+       if (PyType_Ready(&PyBaseObject_Type) < 0)
+               Py_FatalError("Can't initialize object type");
+
+       if (PyType_Ready(&PyRange_Type) < 0)
+               Py_FatalError("Can't initialize range type");
+
+       if (PyType_Ready(&PyDict_Type) < 0)
+               Py_FatalError("Can't initialize dict type");
+
+       if (PyType_Ready(&PySet_Type) < 0)
+               Py_FatalError("Can't initialize set type");
+
+       if (PyType_Ready(&PyUnicode_Type) < 0)
+               Py_FatalError("Can't initialize str type");
+
+       if (PyType_Ready(&PySlice_Type) < 0)
+               Py_FatalError("Can't initialize slice type");
+
+       if (PyType_Ready(&PyStaticMethod_Type) < 0)
+               Py_FatalError("Can't initialize static method type");
+
+       if (PyType_Ready(&PyComplex_Type) < 0)
+               Py_FatalError("Can't initialize complex type");
+
+       if (PyType_Ready(&PyFloat_Type) < 0)
+               Py_FatalError("Can't initialize float type");
+
+       if (PyType_Ready(&PyLong_Type) < 0)
+               Py_FatalError("Can't initialize int type");
+
+       if (PyType_Ready(&PyFrozenSet_Type) < 0)
+               Py_FatalError("Can't initialize frozenset type");
+
+       if (PyType_Ready(&PyProperty_Type) < 0)
+               Py_FatalError("Can't initialize property type");
+
+       if (PyType_Ready(&PyMemoryView_Type) < 0)
+               Py_FatalError("Can't initialize memoryview type");
+
+       if (PyType_Ready(&PyTuple_Type) < 0)
+               Py_FatalError("Can't initialize tuple type");
+
+       if (PyType_Ready(&PyEnum_Type) < 0)
+               Py_FatalError("Can't initialize enumerate type");
+
+       if (PyType_Ready(&PyReversed_Type) < 0)
+               Py_FatalError("Can't initialize reversed type");
 
        if (PyType_Ready(&PyCode_Type) < 0)
                Py_FatalError("Can't initialize 'code'");