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

Skip to content

Commit 9fc8a29

Browse files
committed
Fix for SF bug 551412. When _PyType_Lookup() is called on a type
whose tp_mro hasn't been initialized, it would dump core. Fix this by checking for NULL and calling PyType_Ready(). Will fix this in 2.2.1 too.
1 parent a2a206b commit 9fc8a29

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

Lib/test/test_descr.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,7 +3019,23 @@ class MyStr(str):
30193019
except:
30203020
raise TestFailed, "string subclass allowed as exception"
30213021

3022+
def do_this_first():
3023+
if verbose:
3024+
print "Testing SF bug 551412 ..."
3025+
# This dumps core when SF bug 551412 isn't fixed --
3026+
# but only when test_descr.py is run separately.
3027+
# (That can't be helped -- as soon as PyType_Ready()
3028+
# is called for PyLong_Type, the bug is gone.)
3029+
class UserLong(object):
3030+
def __pow__(self, *args):
3031+
pass
3032+
try:
3033+
pow(0L, UserLong(), 0L)
3034+
except:
3035+
pass
3036+
30223037
def test_main():
3038+
do_this_first()
30233039
class_docstrings()
30243040
lists()
30253041
dicts()

Objects/typeobject.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,12 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name)
12211221

12221222
/* Look in tp_dict of types in MRO */
12231223
mro = type->tp_mro;
1224+
if (mro == NULL) {
1225+
if (PyType_Ready(type) < 0)
1226+
return NULL;
1227+
mro = type->tp_mro;
1228+
assert(mro != NULL);
1229+
}
12241230
assert(PyTuple_Check(mro));
12251231
n = PyTuple_GET_SIZE(mro);
12261232
for (i = 0; i < n; i++) {

0 commit comments

Comments
 (0)