summaryrefslogtreecommitdiffstats
path: root/Objects
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 /Objects
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 'Objects')
-rw-r--r--Objects/frameobject.c15
-rw-r--r--Objects/object.c2
2 files changed, 10 insertions, 7 deletions
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 81b3819..bc8cae9 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -544,7 +544,7 @@ PyFrame_New(PyThreadState *tstate, PyCodeObject *code, PyObject *globals,
#ifdef Py_DEBUG
if (code == NULL || globals == NULL || !PyDict_Check(globals) ||
- (locals != NULL && !PyDict_Check(locals))) {
+ (locals != NULL && !PyMapping_Check(locals))) {
PyErr_BadInternalCall();
return NULL;
}
@@ -688,11 +688,11 @@ map_to_dict(PyObject *map, int nmap, PyObject *dict, PyObject **values,
if (deref)
value = PyCell_GET(value);
if (value == NULL) {
- if (PyDict_DelItem(dict, key) != 0)
+ if (PyObject_DelItem(dict, key) != 0)
PyErr_Clear();
}
else {
- if (PyDict_SetItem(dict, key, value) != 0)
+ if (PyObject_SetItem(dict, key, value) != 0)
PyErr_Clear();
}
}
@@ -705,7 +705,9 @@ dict_to_map(PyObject *map, int nmap, PyObject *dict, PyObject **values,
int j;
for (j = nmap; --j >= 0; ) {
PyObject *key = PyTuple_GET_ITEM(map, j);
- PyObject *value = PyDict_GetItem(dict, key);
+ PyObject *value = PyObject_GetItem(dict, key);
+ if (value == NULL)
+ PyErr_Clear();
if (deref) {
if (value || clear) {
if (PyCell_GET(values[j]) != value) {
@@ -720,6 +722,7 @@ dict_to_map(PyObject *map, int nmap, PyObject *dict, PyObject **values,
values[j] = value;
}
}
+ Py_XDECREF(value);
}
}
@@ -742,7 +745,7 @@ PyFrame_FastToLocals(PyFrameObject *f)
}
}
map = f->f_code->co_varnames;
- if (!PyDict_Check(locals) || !PyTuple_Check(map))
+ if (!PyTuple_Check(map))
return;
PyErr_Fetch(&error_type, &error_value, &error_traceback);
fast = f->f_localsplus;
@@ -780,7 +783,7 @@ PyFrame_LocalsToFast(PyFrameObject *f, int clear)
map = f->f_code->co_varnames;
if (locals == NULL)
return;
- if (!PyDict_Check(locals) || !PyTuple_Check(map))
+ if (!PyTuple_Check(map))
return;
PyErr_Fetch(&error_type, &error_value, &error_traceback);
fast = f->f_localsplus;
diff --git a/Objects/object.c b/Objects/object.c
index 22196d7..1c0efdd 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -1621,7 +1621,7 @@ PyObject_Dir(PyObject *arg)
PyObject *locals = PyEval_GetLocals();
if (locals == NULL)
goto error;
- result = PyDict_Keys(locals);
+ result = PyMapping_Keys(locals);
if (result == NULL)
goto error;
}