diff -r b8184dbc9572 Objects/frameobject.c --- a/Objects/frameobject.c Thu Mar 22 02:17:35 2012 +0100 +++ b/Objects/frameobject.c Thu Mar 22 02:35:10 2012 +0100 @@ -614,8 +614,6 @@ PyFrame_New(PyThreadState *tstate, PyCod builtins = PyModule_GetDict(builtins); assert(!builtins || PyDict_Check(builtins)); } - else if (!PyDict_Check(builtins)) - builtins = NULL; } if (builtins == NULL) { /* No builtins! Make up a minimal one @@ -634,7 +632,7 @@ PyFrame_New(PyThreadState *tstate, PyCod /* If we share the globals, we share the builtins. Save a lookup and a call. */ builtins = back->f_builtins; - assert(builtins != NULL && PyDict_Check(builtins)); + assert(builtins != NULL); Py_INCREF(builtins); } if (code->co_zombieframe != NULL) { diff -r b8184dbc9572 Python/ceval.c --- a/Python/ceval.c Thu Mar 22 02:17:35 2012 +0100 +++ b/Python/ceval.c Thu Mar 22 02:35:10 2012 +0100 @@ -1930,7 +1930,15 @@ PyEval_EvalFrameEx(PyFrameObject *f, int TARGET(LOAD_BUILD_CLASS) { _Py_IDENTIFIER(__build_class__); - x = _PyDict_GetItemId(f->f_builtins, &PyId___build_class__); + + if (PyDict_CheckExact(f->f_builtins)) + x = _PyDict_GetItemId(f->f_builtins, &PyId___build_class__); + else { + PyObject *build_class_str = _PyUnicode_FromId(&PyId___build_class__); + if (build_class_str == NULL) + break; + x = PyObject_GetItem(f->f_builtins, build_class_str); + } if (x == NULL) { PyErr_SetString(PyExc_ImportError, "__build_class__ not found"); @@ -2076,7 +2084,10 @@ PyEval_EvalFrameEx(PyFrameObject *f, int if (x == NULL) { x = PyDict_GetItem(f->f_globals, w); if (x == NULL) { - x = PyDict_GetItem(f->f_builtins, w); + if (PyDict_CheckExact(f->f_builtins)) + x = PyDict_GetItem(f->f_builtins, w); + else + x = PyObject_GetItem(f->f_builtins, w); if (x == NULL) { format_exc_check_arg( PyExc_NameError, @@ -2091,7 +2102,9 @@ PyEval_EvalFrameEx(PyFrameObject *f, int TARGET(LOAD_GLOBAL) w = GETITEM(names, oparg); - if (PyUnicode_CheckExact(w)) { + if (PyDict_CheckExact(f->f_globals) + && PyDict_CheckExact(f->f_builtins) + && PyUnicode_CheckExact(w)) { /* Inline the PyDict_GetItem() calls. WARNING: this is an extreme speed hack. Do not try this at home. */ @@ -2123,21 +2136,25 @@ PyEval_EvalFrameEx(PyFrameObject *f, int PUSH(x); DISPATCH(); } - goto load_global_error; - } - } - /* This is the un-inlined version of the code above */ - x = PyDict_GetItem(f->f_globals, w); - if (x == NULL) { - x = PyDict_GetItem(f->f_builtins, w); - if (x == NULL) { - load_global_error: format_exc_check_arg( PyExc_NameError, GLOBAL_NAME_ERROR_MSG, w); break; } } + else { + /* This is the un-inlined version of the code above */ + x = PyDict_GetItem(f->f_globals, w); + if (x == NULL) { + x = PyDict_GetItem(f->f_builtins, w); + if (x == NULL) { + format_exc_check_arg( + PyExc_NameError, + GLOBAL_NAME_ERROR_MSG, w); + break; + } + } + } Py_INCREF(x); PUSH(x); DISPATCH();