Index: Include/frameobject.h =================================================================== RCS file: /cvsroot/python/python/dist/src/Include/frameobject.h,v retrieving revision 2.37 diff -c -r2.37 frameobject.h *** Include/frameobject.h 11 Sep 2002 15:36:31 -0000 2.37 --- Include/frameobject.h 22 Jun 2004 20:58:48 -0000 *************** *** 19,25 **** PyCodeObject *f_code; /* code segment */ PyObject *f_builtins; /* builtin symbol table (PyDictObject) */ PyObject *f_globals; /* global symbol table (PyDictObject) */ ! PyObject *f_locals; /* local symbol table (PyDictObject) */ PyObject **f_valuestack; /* points after the last local */ /* Next free slot in f_valuestack. Frame creation sets to f_valuestack. Frame evaluation usually NULLs it, but a frame that yields sets it --- 19,25 ---- PyCodeObject *f_code; /* code segment */ PyObject *f_builtins; /* builtin symbol table (PyDictObject) */ PyObject *f_globals; /* global symbol table (PyDictObject) */ ! PyObject *f_locals; /* local symbol table (any mapping) */ PyObject **f_valuestack; /* points after the last local */ /* Next free slot in f_valuestack. Frame creation sets to f_valuestack. Frame evaluation usually NULLs it, but a frame that yields sets it Index: Objects/frameobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/frameobject.c,v retrieving revision 2.78 diff -c -r2.78 frameobject.c *** Objects/frameobject.c 20 Mar 2004 21:10:27 -0000 2.78 --- Objects/frameobject.c 22 Jun 2004 20:58:48 -0000 *************** *** 543,550 **** int extras, ncells, nfrees, i; #ifdef Py_DEBUG ! if (code == NULL || globals == NULL || !PyDict_Check(globals) || ! (locals != NULL && !PyDict_Check(locals))) { PyErr_BadInternalCall(); return NULL; } --- 543,549 ---- int extras, ncells, nfrees, i; #ifdef Py_DEBUG ! if (code == NULL || globals == NULL || !PyDict_Check(globals)) { PyErr_BadInternalCall(); return NULL; } *************** *** 688,698 **** if (deref) value = PyCell_GET(value); if (value == NULL) { ! if (PyDict_DelItem(dict, key) != 0) PyErr_Clear(); } else { ! if (PyDict_SetItem(dict, key, value) != 0) PyErr_Clear(); } } --- 687,697 ---- if (deref) value = PyCell_GET(value); if (value == NULL) { ! if (PyObject_DelItem(dict, key) != 0) PyErr_Clear(); } else { ! if (PyObject_SetItem(dict, key, value) != 0) PyErr_Clear(); } } *************** *** 705,711 **** int j; for (j = nmap; --j >= 0; ) { PyObject *key = PyTuple_GET_ITEM(map, j); ! PyObject *value = PyDict_GetItem(dict, key); if (deref) { if (value || clear) { if (PyCell_GET(values[j]) != value) { --- 704,712 ---- int j; for (j = nmap; --j >= 0; ) { PyObject *key = PyTuple_GET_ITEM(map, j); ! PyObject *value = PyObject_GetItem(dict, key); ! if (value == NULL) ! PyErr_Clear(); if (deref) { if (value || clear) { if (PyCell_GET(values[j]) != value) { *************** *** 720,725 **** --- 721,727 ---- values[j] = value; } } + Py_XDECREF(value); } } *************** *** 742,748 **** } } map = f->f_code->co_varnames; ! if (!PyDict_Check(locals) || !PyTuple_Check(map)) return; PyErr_Fetch(&error_type, &error_value, &error_traceback); fast = f->f_localsplus; --- 744,750 ---- } } map = f->f_code->co_varnames; ! if (!PyTuple_Check(map)) return; PyErr_Fetch(&error_type, &error_value, &error_traceback); fast = f->f_localsplus; *************** *** 780,786 **** map = f->f_code->co_varnames; if (locals == NULL) return; ! if (!PyDict_Check(locals) || !PyTuple_Check(map)) return; PyErr_Fetch(&error_type, &error_value, &error_traceback); fast = f->f_localsplus; --- 782,788 ---- map = f->f_code->co_varnames; if (locals == NULL) return; ! if (!PyTuple_Check(map)) return; PyErr_Fetch(&error_type, &error_value, &error_traceback); fast = f->f_localsplus; Index: Objects/object.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/object.c,v retrieving revision 2.217 diff -c -r2.217 object.c *** Objects/object.c 22 Apr 2004 17:23:49 -0000 2.217 --- Objects/object.c 22 Jun 2004 20:58:49 -0000 *************** *** 1621,1627 **** PyObject *locals = PyEval_GetLocals(); if (locals == NULL) goto error; ! result = PyDict_Keys(locals); if (result == NULL) goto error; } --- 1621,1627 ---- PyObject *locals = PyEval_GetLocals(); if (locals == NULL) goto error; ! result = PyMapping_Keys(locals); if (result == NULL) goto error; } Index: Python/bltinmodule.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v retrieving revision 2.309 diff -c -r2.309 bltinmodule.c *** Python/bltinmodule.c 29 Mar 2004 11:50:55 -0000 2.309 --- Python/bltinmodule.c 22 Jun 2004 20:58:49 -0000 *************** *** 455,472 **** char *str; PyCompilerFlags cf; ! if (!PyArg_ParseTuple(args, "O|O!O!:eval", ! &cmd, ! &PyDict_Type, &globals, ! &PyDict_Type, &locals)) return NULL; if (globals == Py_None) { globals = PyEval_GetGlobals(); if (locals == Py_None) locals = PyEval_GetLocals(); } ! else if (locals == Py_None) locals = globals; if (PyDict_GetItemString(globals, "__builtins__") == NULL) { if (PyDict_SetItemString(globals, "__builtins__", --- 455,487 ---- char *str; PyCompilerFlags cf; ! if (!PyArg_ParseTuple(args, "O|OO:eval", ! &cmd, &globals, &locals)) return NULL; if (globals == Py_None) { globals = PyEval_GetGlobals(); if (locals == Py_None) locals = PyEval_GetLocals(); } ! else if (locals == Py_None) { locals = globals; + /* eval("code", nondict) is automatically replaced with + eval("code", globals(), nondict), which is entierely + equivalent as far as "code" is concerned and works around + the limitation that globals have to be real dictionaries. */ + if (!PyDict_Check(globals)) + globals = PyEval_GetGlobals(); + } + else if (!PyDict_Check(globals)) { + PyErr_SetString(PyExc_TypeError, + "eval() globals must be a dict"); + return NULL; + } + if (globals == NULL || locals == NULL) { + PyErr_SetString(PyExc_SystemError, + "eval(): missing globals or locals"); + return NULL; + } if (PyDict_GetItemString(globals, "__builtins__") == NULL) { if (PyDict_SetItemString(globals, "__builtins__", *************** *** 531,540 **** PyCompilerFlags cf; int exists; ! if (!PyArg_ParseTuple(args, "s|O!O!:execfile", &filename, &PyDict_Type, &globals, ! &PyDict_Type, &locals)) return NULL; if (globals == Py_None) { globals = PyEval_GetGlobals(); --- 546,555 ---- PyCompilerFlags cf; int exists; ! if (!PyArg_ParseTuple(args, "s|O!O:execfile", &filename, &PyDict_Type, &globals, ! &locals)) return NULL; if (globals == Py_None) { globals = PyEval_GetGlobals(); Index: Python/ceval.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v retrieving revision 2.404 diff -c -r2.404 ceval.c *** Python/ceval.c 22 Jun 2004 15:37:51 -0000 2.404 --- Python/ceval.c 22 Jun 2004 20:58:50 -0000 *************** *** 1645,1651 **** w = GETITEM(names, oparg); v = POP(); if ((x = f->f_locals) != NULL) { ! err = PyDict_SetItem(x, w, v); Py_DECREF(v); if (err == 0) continue; break; --- 1645,1651 ---- w = GETITEM(names, oparg); v = POP(); if ((x = f->f_locals) != NULL) { ! err = PyObject_SetItem(x, w, v); Py_DECREF(v); if (err == 0) continue; break; *************** *** 1658,1664 **** case DELETE_NAME: w = GETITEM(names, oparg); if ((x = f->f_locals) != NULL) { ! if ((err = PyDict_DelItem(x, w)) != 0) format_exc_check_arg(PyExc_NameError, NAME_ERROR_MSG ,w); break; --- 1658,1664 ---- case DELETE_NAME: w = GETITEM(names, oparg); if ((x = f->f_locals) != NULL) { ! if ((err = PyObject_DelItem(x, w)) != 0) format_exc_check_arg(PyExc_NameError, NAME_ERROR_MSG ,w); break; *************** *** 1741,1748 **** PyObject_REPR(w)); break; } ! x = PyDict_GetItem(x, w); if (x == NULL) { x = PyDict_GetItem(f->f_globals, w); if (x == NULL) { x = PyDict_GetItem(f->f_builtins, w); --- 1741,1751 ---- PyObject_REPR(w)); break; } ! x = PyObject_GetItem(x, w); if (x == NULL) { + if (!PyErr_ExceptionMatches(PyExc_KeyError)) + break; + PyErr_Clear(); x = PyDict_GetItem(f->f_globals, w); if (x == NULL) { x = PyDict_GetItem(f->f_builtins, w); *************** *** 1753,1760 **** break; } } } - Py_INCREF(x); PUSH(x); continue; --- 1756,1763 ---- break; } } + Py_INCREF(x); } PUSH(x); continue; *************** *** 4138,4148 **** "exec: arg 2 must be a dictionary or None"); return -1; } - if (!PyDict_Check(locals)) { - PyErr_SetString(PyExc_TypeError, - "exec: arg 3 must be a dictionary or None"); - return -1; - } if (PyDict_GetItemString(globals, "__builtins__") == NULL) PyDict_SetItemString(globals, "__builtins__", f->f_builtins); if (PyCode_Check(prog)) { --- 4141,4146 ----