summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2013-04-30 13:41:40 (GMT)
committerBenjamin Peterson <benjamin@python.org>2013-04-30 13:41:40 (GMT)
commit3b0431dc6019d2f9ffa9adcaa78ddd3f7b76a2f5 (patch)
tree7f98ecba2e560776b91856eb74487c26c73d5d0d /Python/ceval.c
parentf256f5f3ebf6574a2708cfea36d857846893e71f (diff)
downloadcpython-3b0431dc6019d2f9ffa9adcaa78ddd3f7b76a2f5.zip
cpython-3b0431dc6019d2f9ffa9adcaa78ddd3f7b76a2f5.tar.gz
cpython-3b0431dc6019d2f9ffa9adcaa78ddd3f7b76a2f5.tar.bz2
check local class namespace before reaching for cells (closes #17853)
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 138c75d..cbc0fab 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -2260,6 +2260,39 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
DISPATCH();
}
+ TARGET(LOAD_CLASSDEREF) {
+ PyObject *name, *value, *locals = f->f_locals;
+ int idx;
+ assert(locals);
+ assert(oparg >= PyTuple_GET_SIZE(co->co_cellvars));
+ idx = oparg - PyTuple_GET_SIZE(co->co_cellvars);
+ assert(idx >= 0 && idx < PyTuple_GET_SIZE(co->co_freevars));
+ name = PyTuple_GET_ITEM(co->co_freevars, idx);
+ if (PyDict_CheckExact(locals)) {
+ value = PyDict_GetItem(locals, name);
+ Py_XINCREF(value);
+ }
+ else {
+ value = PyObject_GetItem(locals, name);
+ if (value == NULL && PyErr_Occurred()) {
+ if (!PyErr_ExceptionMatches(PyExc_KeyError))
+ goto error;
+ PyErr_Clear();
+ }
+ }
+ if (!value) {
+ PyObject *cell = freevars[oparg];
+ value = PyCell_GET(cell);
+ if (value == NULL) {
+ format_exc_unbound(co, oparg);
+ goto error;
+ }
+ Py_INCREF(value);
+ }
+ PUSH(value);
+ DISPATCH();
+ }
+
TARGET(LOAD_DEREF) {
PyObject *cell = freevars[oparg];
PyObject *value = PyCell_GET(cell);