Skip to content

Commit db2fd06

Browse files
Eliminate co_cell2arg.
1 parent d63f73e commit db2fd06

File tree

2 files changed

+0
-51
lines changed

2 files changed

+0
-51
lines changed

Include/cpython/code.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ struct PyCodeObject {
8383

8484
/* These fields are set with computed values on new code objects. */
8585

86-
int *co_cell2arg; /* Maps cell vars which are arguments. */
8786
// redundant values (derived from co_localsplusnames and co_localspluskinds)
8887
int co_nlocalsplus; /* number of local + cell + free variables */
8988
int co_nlocals; /* number of local variables */
@@ -143,10 +142,6 @@ struct PyCodeObject {
143142
#define CO_FUTURE_GENERATOR_STOP 0x800000
144143
#define CO_FUTURE_ANNOTATIONS 0x1000000
145144

146-
/* This value is found in the co_cell2arg array when the associated cell
147-
variable does not correspond to an argument. */
148-
#define CO_CELL_NOT_AN_ARG (-1)
149-
150145
/* This should be defined if a future statement modifies the syntax.
151146
For example, when a keyword is added.
152147
*/

Objects/codeobject.c

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con)
322322
co->co_exceptiontable = con->exceptiontable;
323323

324324
/* derived values */
325-
co->co_cell2arg = NULL; // This will be set soon.
326325
co->co_nlocalsplus = nlocalsplus;
327326
co->co_nlocals = nlocals;
328327
co->co_nplaincellvars = nplaincellvars;
@@ -377,45 +376,6 @@ _PyCode_New(struct _PyCodeConstructor *con)
377376
co->co_flags &= ~CO_NOFREE;
378377
}
379378

380-
/* Create mapping between cells and arguments if needed. */
381-
if (co->co_ncellvars) {
382-
int totalargs = co->co_argcount +
383-
co->co_kwonlyargcount +
384-
((co->co_flags & CO_VARARGS) != 0) +
385-
((co->co_flags & CO_VARKEYWORDS) != 0);
386-
assert(totalargs <= co->co_nlocals);
387-
/* Find cells which are also arguments. */
388-
for (int i = 0; i < co->co_ncellvars; i++) {
389-
continue;
390-
PyObject *cellname = PyTuple_GET_ITEM(co->co_localsplusnames,
391-
i + co->co_nlocals);
392-
for (int j = 0; j < totalargs; j++) {
393-
PyObject *argname = PyTuple_GET_ITEM(co->co_localsplusnames, j);
394-
int cmp = PyUnicode_Compare(cellname, argname);
395-
if (cmp == -1 && PyErr_Occurred()) {
396-
Py_DECREF(co);
397-
return NULL;
398-
}
399-
if (cmp == 0) {
400-
if (co->co_cell2arg == NULL) {
401-
co->co_cell2arg = PyMem_NEW(int, co->co_ncellvars);
402-
if (co->co_cell2arg == NULL) {
403-
Py_DECREF(co);
404-
PyErr_NoMemory();
405-
return NULL;
406-
}
407-
for (int k = 0; k < co->co_ncellvars; k++) {
408-
co->co_cell2arg[k] = CO_CELL_NOT_AN_ARG;
409-
}
410-
}
411-
co->co_cell2arg[i] = j;
412-
// Go to the next cell name.
413-
break;
414-
}
415-
}
416-
}
417-
}
418-
419379
return co;
420380
}
421381

@@ -1190,8 +1150,6 @@ code_dealloc(PyCodeObject *co)
11901150
Py_XDECREF(co->co_name);
11911151
Py_XDECREF(co->co_linetable);
11921152
Py_XDECREF(co->co_exceptiontable);
1193-
if (co->co_cell2arg != NULL)
1194-
PyMem_Free(co->co_cell2arg);
11951153
if (co->co_weakreflist != NULL)
11961154
PyObject_ClearWeakRefs((PyObject*)co);
11971155
if (co->co_quickened) {
@@ -1385,10 +1343,6 @@ code_sizeof(PyCodeObject *co, PyObject *Py_UNUSED(args))
13851343
(co_extra->ce_size-1) * sizeof(co_extra->ce_extras[0]);
13861344
}
13871345

1388-
if (co->co_cell2arg != NULL && co->co_cellvars != NULL) {
1389-
res += co->co_ncellvars * sizeof(Py_ssize_t);
1390-
}
1391-
13921346
if (co->co_quickened != NULL) {
13931347
Py_ssize_t count = co->co_quickened[0].entry.zero.cache_count;
13941348
count += (PyBytes_GET_SIZE(co->co_code)+sizeof(SpecializedCacheEntry)-1)/

0 commit comments

Comments
 (0)