Skip to content

Commit f550d65

Browse files
committed
fixes
1 parent d1e1761 commit f550d65

File tree

5 files changed

+37
-22
lines changed

5 files changed

+37
-22
lines changed

Include/internal/pycore_instruction_sequence.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ _PyJumpTargetLabel _PyInstructionSequence_NewLabel(_PyInstructionSequence *seq);
6666
int _PyInstructionSequence_ApplyLabelMap(_PyInstructionSequence *seq);
6767
int _PyInstructionSequence_InsertInstruction(_PyInstructionSequence *seq, int pos,
6868
int opcode, int oparg, _Py_SourceLocation loc);
69-
int _PyInstructionSequence_PrependSequence(_PyInstructionSequence *seq, _PyInstructionSequence *nested);
69+
int _PyInstructionSequence_PrependSequence(_PyInstructionSequence *seq, int pos,
70+
_PyInstructionSequence *nested);
7071
int _PyInstructionSequence_AddNested(_PyInstructionSequence *seq, _PyInstructionSequence *nested);
7172
void PyInstructionSequence_Fini(_PyInstructionSequence *seq);
7273

Lib/test/test_dis.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -382,24 +382,36 @@ def wrap_func_w_kwargs():
382382
# leading newline is for a reason (tests lineno)
383383

384384
dis_annot_stmt_str = """\
385-
0 RESUME 0
385+
-- MAKE_CELL 0 (__conditional_annotations__)
386386
387-
2 LOAD_SMALL_INT 1
388-
STORE_NAME 0 (x)
387+
0 RESUME 0
389388
390-
4 LOAD_SMALL_INT 1
391-
LOAD_NAME 1 (lst)
392-
LOAD_NAME 2 (fun)
393-
PUSH_NULL
394-
LOAD_SMALL_INT 0
395-
CALL 1
396-
STORE_SUBSCR
389+
2 LOAD_CONST 1 (<code object __annotate__ at 0x..., file "<dis>", line 2>)
390+
MAKE_FUNCTION
391+
STORE_NAME 4 (__annotate__)
392+
BUILD_SET 0
393+
STORE_NAME 0 (__conditional_annotations__)
394+
LOAD_SMALL_INT 1
395+
STORE_NAME 1 (x)
396+
LOAD_NAME 0 (__conditional_annotations__)
397+
LOAD_SMALL_INT 0
398+
SET_ADD 1
399+
POP_TOP
397400
398-
2 LOAD_CONST 1 (<code object __annotate__ at 0x..., file "<dis>", line 2>)
399-
MAKE_FUNCTION
400-
STORE_NAME 3 (__annotate__)
401-
LOAD_CONST 2 (None)
402-
RETURN_VALUE
401+
3 LOAD_NAME 0 (__conditional_annotations__)
402+
LOAD_SMALL_INT 1
403+
SET_ADD 1
404+
POP_TOP
405+
406+
4 LOAD_SMALL_INT 1
407+
LOAD_NAME 2 (lst)
408+
LOAD_NAME 3 (fun)
409+
PUSH_NULL
410+
LOAD_SMALL_INT 0
411+
CALL 1
412+
STORE_SUBSCR
413+
LOAD_CONST 2 (None)
414+
RETURN_VALUE
403415
"""
404416

405417
fn_with_annotate_str = """

Makefile.pre.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2666,6 +2666,7 @@ TESTSUBDIRS= idlelib/idle_test \
26662666
test/translationdata/getopt \
26672667
test/translationdata/optparse \
26682668
test/typinganndata \
2669+
test/typinganndata/partialexecution \
26692670
test/wheeldata \
26702671
test/xmltestdata \
26712672
test/xmltestdata/c14n-20 \

Python/codegen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ codegen_process_deferred_annotations(compiler *c, location loc)
829829

830830
if (nested_instr_seq != NULL) {
831831
RETURN_IF_ERROR(
832-
_PyInstructionSequence_PrependSequence(old_instr_seq, nested_instr_seq));
832+
_PyInstructionSequence_PrependSequence(old_instr_seq, 1, nested_instr_seq));
833833
_PyCompile_SetInstrSequence(c, old_instr_seq);
834834
PyInstructionSequence_Fini(nested_instr_seq);
835835
}

Python/instruction_sequence.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,23 +160,24 @@ _PyInstructionSequence_InsertInstruction(instr_sequence *seq, int pos,
160160
}
161161

162162
int
163-
_PyInstructionSequence_PrependSequence(instr_sequence *seq,
163+
_PyInstructionSequence_PrependSequence(instr_sequence *seq, int pos,
164164
instr_sequence *nested)
165165
{
166+
assert(pos >= 0 && pos <= seq->s_used);
167+
// Merging labelmaps is not supported
168+
assert(nested->s_labelmap_size == 0 && nested->s_nested == NULL);
166169
if (nested->s_used == 0) {
167170
return SUCCESS;
168171
}
169-
// Merging labelmaps is not supported
170-
assert(nested->s_labelmap_size == 0 && nested->s_nested == NULL);
171172

172173
int last_idx = instr_sequence_grow(seq, nested->s_used);
173174

174175
RETURN_IF_ERROR(last_idx);
175-
for (int i = last_idx - nested->s_used; i >= 0; i--) {
176+
for (int i = last_idx - nested->s_used; i >= pos; i--) {
176177
seq->s_instrs[i + nested->s_used] = seq->s_instrs[i];
177178
}
178179
for (int i=0; i < nested->s_used; i++) {
179-
seq->s_instrs[i] = nested->s_instrs[i];
180+
seq->s_instrs[i + pos] = nested->s_instrs[i];
180181
}
181182
for(int lbl=0; lbl < seq->s_labelmap_size; lbl++) {
182183
seq->s_labelmap[lbl] += nested->s_used;

0 commit comments

Comments
 (0)