[Python-checkins] python/dist/src/Objects frameobject.c,2.72,2.73
jhylton@users.sourceforge.net
jhylton@users.sourceforge.net
2003年2月05日 14:39:32 -0800
Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv21960/Objects
Modified Files:
frameobject.c
Log Message:
Refactor the logic for setting f_builtins.
For the case where the current globals match the previous frame's
globals, eliminates three tests in two if statements. For the case
where we just get __builtins__ from a module, eliminate a couple of
tests.
Index: frameobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/frameobject.c,v
retrieving revision 2.72
retrieving revision 2.73
diff -C2 -d -r2.72 -r2.73
*** frameobject.c 31 Dec 2002 03:42:13 -0000 2.72
--- frameobject.c 5 Feb 2003 22:39:29 -0000 2.73
***************
*** 555,560 ****
if (back == NULL || back->f_globals != globals) {
builtins = PyDict_GetItem(globals, builtin_object);
! if (builtins != NULL && PyModule_Check(builtins))
! builtins = PyModule_GetDict(builtins);
}
else {
--- 555,578 ----
if (back == NULL || back->f_globals != globals) {
builtins = PyDict_GetItem(globals, builtin_object);
! if (builtins) {
! if (PyModule_Check(builtins)) {
! 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
! Give them 'None', at least. */
! builtins = PyDict_New();
! if (builtins == NULL ||
! PyDict_SetItemString(
! builtins, "None", Py_None) < 0)
! return NULL;
! }
! else
! Py_INCREF(builtins);
!
}
else {
***************
*** 562,568 ****
Save a lookup and a call. */
builtins = back->f_builtins;
}
- if (builtins != NULL && !PyDict_Check(builtins))
- builtins = NULL;
if (free_list == NULL) {
f = PyObject_GC_NewVar(PyFrameObject, &PyFrame_Type, extras);
--- 580,586 ----
Save a lookup and a call. */
builtins = back->f_builtins;
+ assert(builtins != NULL && PyDict_Check(builtins));
+ Py_INCREF(builtins);
}
if (free_list == NULL) {
f = PyObject_GC_NewVar(PyFrameObject, &PyFrame_Type, extras);
***************
*** 582,596 ****
_Py_NewReference((PyObject *)f);
}
- if (builtins == NULL) {
- /* No builtins! Make up a minimal one. */
- builtins = PyDict_New();
- if (builtins == NULL || /* Give them 'None', at least. */
- PyDict_SetItemString(builtins, "None", Py_None) < 0) {
- Py_DECREF(f);
- return NULL;
- }
- }
- else
- Py_INCREF(builtins);
f->f_builtins = builtins;
Py_XINCREF(back);
--- 600,603 ----
***************
*** 600,612 ****
Py_INCREF(globals);
f->f_globals = globals;
! if (code->co_flags & CO_NEWLOCALS) {
! if (code->co_flags & CO_OPTIMIZED)
! locals = NULL; /* Let fast_2_locals handle it */
! else {
! locals = PyDict_New();
! if (locals == NULL) {
! Py_DECREF(f);
! return NULL;
! }
}
}
--- 607,619 ----
Py_INCREF(globals);
f->f_globals = globals;
! /* Most functions have CO_NEWLOCALS and CO_OPTIMIZED set. */
! if ((code->co_flags & (CO_NEWLOCALS | CO_OPTIMIZED)) ==
! (CO_NEWLOCALS | CO_OPTIMIZED))
! locals = NULL; /* PyFrame_Fast2Locals() will set. */
! else if (code->co_flags & CO_NEWLOCALS) {
! locals = PyDict_New();
! if (locals == NULL) {
! Py_DECREF(f);
! return NULL;
}
}