summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2021-05-26 19:15:40 (GMT)
committerGitHub <noreply@github.com>2021-05-26 19:15:40 (GMT)
commit6cc800d3634fdd002b986c3ffe6a3d5540f311a0 (patch)
treec6e67a6f76549102011931f2ee929b455ab40918 /Python
parente6c815d2e34be5fdf6dbe773f0781691746d2289 (diff)
downloadcpython-6cc800d3634fdd002b986c3ffe6a3d5540f311a0.zip
cpython-6cc800d3634fdd002b986c3ffe6a3d5540f311a0.tar.gz
cpython-6cc800d3634fdd002b986c3ffe6a3d5540f311a0.tar.bz2
bpo-43693: Clean up the PyCodeObject fields. (GH-26364)
* Move up the comment about fields using in hashing/comparision. * Group the fields more clearly. * Add co_ncellvars and co_nfreevars. * Raise ValueError if nlocals != len(varnames), rather than aborting.
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index e4a6a65..3bbcfe9 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -3081,9 +3081,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
PyObject *name, *value, *locals = LOCALS();
Py_ssize_t 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));
+ assert(oparg >= co->co_ncellvars);
+ idx = oparg - co->co_ncellvars;
+ assert(idx >= 0 && idx < co->co_nfreevars);
name = PyTuple_GET_ITEM(co->co_freevars, idx);
if (PyDict_CheckExact(locals)) {
value = PyDict_GetItemWithError(locals, name);
@@ -5062,7 +5062,7 @@ initialize_locals(PyThreadState *tstate, PyFrameConstructor *con,
/* Allocate and initialize storage for cell vars, and copy free
vars into frame. */
- for (i = 0; i < PyTuple_GET_SIZE(co->co_cellvars); ++i) {
+ for (i = 0; i < co->co_ncellvars; ++i) {
PyObject *c;
Py_ssize_t arg;
/* Possibly account for the cell variable being an argument. */
@@ -5081,10 +5081,10 @@ initialize_locals(PyThreadState *tstate, PyFrameConstructor *con,
}
/* Copy closure variables to free variables */
- for (i = 0; i < PyTuple_GET_SIZE(co->co_freevars); ++i) {
+ for (i = 0; i < co->co_nfreevars; ++i) {
PyObject *o = PyTuple_GET_ITEM(con->fc_closure, i);
Py_INCREF(o);
- freevars[PyTuple_GET_SIZE(co->co_cellvars) + i] = o;
+ freevars[co->co_ncellvars + i] = o;
}
return 0;
@@ -6417,7 +6417,7 @@ format_exc_unbound(PyThreadState *tstate, PyCodeObject *co, int oparg)
/* Don't stomp existing exception */
if (_PyErr_Occurred(tstate))
return;
- if (oparg < PyTuple_GET_SIZE(co->co_cellvars)) {
+ if (oparg < co->co_ncellvars) {
name = PyTuple_GET_ITEM(co->co_cellvars,
oparg);
format_exc_check_arg(tstate,
@@ -6425,8 +6425,7 @@ format_exc_unbound(PyThreadState *tstate, PyCodeObject *co, int oparg)
UNBOUNDLOCAL_ERROR_MSG,
name);
} else {
- name = PyTuple_GET_ITEM(co->co_freevars, oparg -
- PyTuple_GET_SIZE(co->co_cellvars));
+ name = PyTuple_GET_ITEM(co->co_freevars, oparg - co->co_ncellvars);
format_exc_check_arg(tstate, PyExc_NameError,
UNBOUNDFREE_ERROR_MSG, name);
}