8000 jump_to_fail_pop return SUCCESS/ERROR · python/cpython@71e13c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 71e13c2

Browse files
committed
jump_to_fail_pop return SUCCESS/ERROR
1 parent 5d8f93b commit 71e13c2

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

Python/compile.c

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6506,11 +6506,9 @@ jump_to_fail_pop(struct compiler *c, location loc,
65066506
// Pop any items on the top of the stack, plus any objects we were going to
65076507
// capture on success:
65086508
Py_ssize_t pops = pc->on_top + PyList_GET_SIZE(pc->stores);
6509-
if (ensure_fail_pop(c, pc, pops) < 0) {
6510-
return 0;
6511-
}
6512-
_ADDOP_JUMP(c, loc, op, pc->fail_pop[pops]);
6513-
return 1;
6509+
RETURN_IF_ERROR(ensure_fail_pop(c, pc, pops));
6510+
ADDOP_JUMP(c, loc, op, pc->fail_pop[pops]);
6511+
return SUCCESS;
65146512
}
65156513

65166514
// Build all of the fail_pop blocks and reset fail_pop.
@@ -6775,7 +6773,9 @@ compiler_pattern_class(struct compiler *c, pattern_ty p, pattern_context *pc)
67756773
_ADDOP_I(c, LOC(p), IS_OP, 1);
67766774
// TOS is now a tuple of (nargs + nattrs) attributes (or None):
67776775
pc->on_top++;
6778-
RETURN_IF_FALSE(jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE));
6776+
if (jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE) < 0) {
6777+
return 0;
6778+
}
67796779
_ADDOP_I(c, LOC(p), UNPACK_SEQUENCE, nargs + nattrs);
67806780
pc->on_top += nargs + nattrs - 1;
67816781
for (i = 0; i < nargs + nattrs; i++) {
@@ -6819,7 +6819,9 @@ compiler_pattern_mapping(struct compiler *c, pattern_ty p,
68196819
// We need to keep the subject on top during the mapping and length checks:
68206820
pc->on_top++;
68216821
_ADDOP(c, LOC(p), MATCH_MAPPING);
6822-
RETURN_IF_FALSE(jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE));
6822+
if (jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE) < 0) {
6823+
return 0;
6824+
}
68236825
if (!size && !star_target) {
68246826
// If the pattern is just "{}", we're done! Pop the subject:
68256827
pc->on_top--;
@@ -6831,7 +6833,9 @@ compiler_pattern_mapping(struct compiler *c, pattern_ty p,
68316833
_ADDOP(c, LOC(p), GET_LEN);
68326834
_ADDOP_LOAD_CONST_NEW(c, LOC(p), PyLong_FromSsize_t(size));
68336835
_ADDOP_COMPARE(c, LOC(p), GtE);
6834-
RETURN_IF_FALSE(jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE));
6836+
if (jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE) < 0) {
6837+
return 0;
6838+
}
68356839
}
68366840
if (INT_MAX < size - 1) {
68376841
return compiler_error(c, LOC(p), "too many sub-patterns in mapping pattern");
@@ -6892,7 +6896,9 @@ compiler_pattern_mapping(struct compiler *c, pattern_ty p,
68926896
_ADDOP_I(c, LOC(p), COPY, 1);
68936897
_ADDOP_LOAD_CONST(c, LOC(p), Py_None);
68946898
_ADDOP_I(c, LOC(p), IS_OP, 1);
6895-
RETURN_IF_FALSE(jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE));
6899+
if (jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE) < 0) {
6900+
return 0;
6901+
}
68966902
// So far so good. Use that tuple of values on the stack to match
68976903
// sub-patterns against:
68986904
_ADDOP_I(c, LOC(p), UNPACK_SEQUENCE, size);
@@ -7037,7 +7043,7 @@ compiler_pattern_or(struct compiler *c, pattern_ty p, pattern_context *pc)
70377043
old_pc.fail_pop = NULL;
70387044
// No match. Pop the remaining copy of the subject and fail:
70397045
if ((cfg_builder_addop_noarg(CFG_BUILDER(c), POP_TOP, LOC(p)) < 0) ||
7040-
!jump_to_fail_pop(c, LOC(p), pc, JUMP)) {
7046+
jump_to_fail_pop(c, LOC(p), pc, JUMP) < 0) {
70417047
goto error;
70427048
}
70437049

@@ -7114,20 +7120,26 @@ compiler_pattern_sequence(struct compiler *c, pattern_ty p,
71147120
// We need to keep the subject on top during the sequence and length checks:
71157121
pc->on_top++;
71167122
_ADDOP(c, LOC(p), MATCH_SEQUENCE);
7117-
RETURN_IF_FALSE(jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE));
7123+
if (jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE) < 0) {
7124+
return 0;
7125+
}
71187126
if (star < 0) {
71197127
// No star: len(subject) == size
71207128
_ADDOP(c, LOC(p), GET_LEN);
71217129
_ADDOP_LOAD_CONST_NEW(c, LOC(p), PyLong_FromSsize_t(size));
71227130
_ADDOP_COMPARE(c, LOC(p), Eq);
7123-
RETURN_IF_FALSE(jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE));
7131+
if (jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE) < 0) {
7132+
return 0;
7133+
}
71247134
}
71257135
else if (size > 1) {
71267136
// Star: len(subject) >= size - 1
71277137
_ADDOP(c, LOC(p), GET_LEN);
71287138
_ADDOP_LOAD_CONST_NEW(c, LOC(p), PyLong_FromSsize_t(size - 1));
71297139
_ADDOP_COMPARE(c, LOC(p), GtE);
7130-
RETURN_IF_FALSE(jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE));
7140+
if (jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE) < 0) {
7141+
return 0;
7142+
}
71317143
}
71327144
// Whatever comes next should consume the subject:
71337145
pc->on_top--;
@@ -7155,7 +7167,9 @@ compiler_pattern_value(struct compiler *c, pattern_ty p, pattern_context *pc)
71557167
}
71567168
_VISIT(c, expr, value);
71577169
_ADDOP_COMPARE(c, LOC(p), Eq);
7158-
RETURN_IF_FALSE(jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE));
7170+
if (jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE) < 0) {
7171+
return 0;
7172+
}
71597173
return 1;
71607174
}
71617175

@@ -7165,7 +7179,9 @@ compiler_pattern_singleton(struct compiler *c, pattern_ty p, pattern_context *pc
71657179
assert(p->kind == MatchSingleton_kind);
71667180
_ADDOP_LOAD_CONST(c, LOC(p), p->v.MatchSingleton.value);
71677181
_ADDOP_COMPARE(c, LOC(p), Is);
7168-
RETURN_IF_FALSE(jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE));
7182+
if (jump_to_fail_pop(c, LOC(p), pc, POP_JUMP_IF_FALSE) < 0) {
7183+
return 0;
7184+
}
71697185
return 1;
71707186
}
71717187

0 commit comments

Comments
 (0)
0