Mercurial > cpython-lru_cache-weakref
diff Python/ceval.c @ 83572:cf65c7a75f55
check local class namespace before reaching for cells (closes #17853)
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Tue, 30 Apr 2013 09:41:40 -0400 |
| parents | 6297fcddf912 |
| children | 847692b9902a |
line wrap: on
line diff
--- a/Python/ceval.c Tue Apr 30 16:34:30 2013 +0300 +++ b/Python/ceval.c Tue Apr 30 09:41:40 2013 -0400 @@ -2260,6 +2260,39 @@ 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);
