summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-07-02 06:41:07 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-07-02 06:41:07 (GMT)
commit214b1c3aaea3e83302df9ea37a37b3c7548b92b1 (patch)
tree4ddeda01308aec48c7edda3188a4aad84dc9435b /Python/ceval.c
parent78bace7442bb89aa005950a1e37f71d4704d4cb6 (diff)
downloadcpython-214b1c3aaea3e83302df9ea37a37b3c7548b92b1.zip
cpython-214b1c3aaea3e83302df9ea37a37b3c7548b92b1.tar.gz
cpython-214b1c3aaea3e83302df9ea37a37b3c7548b92b1.tar.bz2
SF Bug #215126: Over restricted type checking on eval() function
The builtin eval() function now accepts any mapping for the locals argument. Time sensitive steps guarded by PyDict_CheckExact() to keep from slowing down the normal case. My timings so no measurable impact.
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index ca7cea8..0c3a93d 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1643,7 +1643,10 @@ PyEval_EvalFrame(PyFrameObject *f)
w = GETITEM(names, oparg);
v = POP();
if ((x = f->f_locals) != NULL) {
- err = PyDict_SetItem(x, w, v);
+ if (PyDict_CheckExact(v))
+ err = PyDict_SetItem(x, w, v);
+ else
+ err = PyObject_SetItem(x, w, v);
Py_DECREF(v);
if (err == 0) continue;
break;
@@ -1656,7 +1659,7 @@ PyEval_EvalFrame(PyFrameObject *f)
case DELETE_NAME:
w = GETITEM(names, oparg);
if ((x = f->f_locals) != NULL) {
- if ((err = PyDict_DelItem(x, w)) != 0)
+ if ((err = PyObject_DelItem(x, w)) != 0)
format_exc_check_arg(PyExc_NameError,
NAME_ERROR_MSG ,w);
break;
@@ -1733,13 +1736,22 @@ PyEval_EvalFrame(PyFrameObject *f)
case LOAD_NAME:
w = GETITEM(names, oparg);
- if ((x = f->f_locals) == NULL) {
+ if ((v = f->f_locals) == NULL) {
PyErr_Format(PyExc_SystemError,
"no locals when loading %s",
PyObject_REPR(w));
break;
}
- x = PyDict_GetItem(x, w);
+ if (PyDict_CheckExact(v))
+ x = PyDict_GetItem(v, w);
+ else {
+ x = PyObject_GetItem(v, w);
+ if (x == NULL && PyErr_Occurred()) {
+ if (!PyErr_ExceptionMatches(PyExc_KeyError))
+ break;
+ PyErr_Clear();
+ }
+ }
if (x == NULL) {
x = PyDict_GetItem(f->f_globals, w);
if (x == NULL) {