summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/Python/compile.c b/Python/compile.c
index b0c9f3c..1104250 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -7435,6 +7435,24 @@ guarantee_lineno_for_exits(struct assembler *a, int firstlineno) {
}
}
+static void
+offset_derefs(basicblock *entryblock, int nlocals)
+{
+ for (basicblock *b = entryblock; b != NULL; b = b->b_next) {
+ for (int i = 0; i < b->b_iused; i++) {
+ struct instr *inst = &b->b_instr[i];
+ switch(inst->i_opcode) {
+ case LOAD_CLOSURE:
+ case LOAD_DEREF:
+ case STORE_DEREF:
+ case DELETE_DEREF:
+ case LOAD_CLASSDEREF:
+ inst->i_oparg += nlocals;
+ }
+ }
+ }
+}
+
static PyCodeObject *
assemble(struct compiler *c, int addNone)
{
@@ -7490,6 +7508,9 @@ assemble(struct compiler *c, int addNone)
a.a_entry = entryblock;
a.a_nblocks = nblocks;
+ assert(PyDict_GET_SIZE(c->u->u_varnames) < INT_MAX);
+ offset_derefs(entryblock, (int)PyDict_GET_SIZE(c->u->u_varnames));
+
consts = consts_dict_keys_inorder(c->u->u_consts);
if (consts == NULL) {
goto error;