8000 pattern_helper_sequence_subscr, compiler_pattern_subpattern return SU… · python/cpython@c8acddb · GitHub
[go: up one dir, main page]

Skip to content

Commit c8acddb

Browse files
committed
pattern_helper_sequence_subscr, compiler_pattern_subpattern return SUCCESS/ERROR
1 parent 0b84a46 commit c8acddb

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

Python/compile.c

Lines changed: 23 additions & 17 deletions
< 8000 tr class="diff-line-row">
Original file line numberDiff line numberDiff line change
@@ -6632,9 +6632,7 @@ pattern_helper_sequence_unpack(struct compiler *c, location loc,
66326632
// One less item to keep track of each time we loop through:
66336633
pc->on_top--;
66346634
pattern_ty pattern = asdl_seq_GET(patterns, i);
6635-
if (!compiler_pattern_subpattern(c, pattern, pc)) {
6636-
return ERROR;
6637-
}
6635+
RETURN_IF_ERROR(compiler_pattern_subpattern(c, pattern, pc));
66386636
}
66396637
return SUCCESS;
66406638
}
@@ -6659,24 +6657,24 @@ pattern_helper_sequence_subscr(struct compiler *c, location loc,
66596657
assert(WILDCARD_STAR_CHECK(pattern));
66606658
continue;
66616659
}
6662-
_ADDOP_I(c, loc, COPY, 1);
6660+
ADDOP_I(c, loc, COPY, 1);
66636661
if (i < star) {
6664-
_ADDOP_LOAD_CONST_NEW(c, loc, PyLong_FromSsize_t(i));
6662+
ADDOP_LOAD_CONST_NEW(c, loc, PyLong_FromSsize_t(i));
66656663
}
66666664
else {
66676665
// The subject may not support negative indexing! Compute a
66686666
// nonnegative index:
6669-
_ADDOP(c, loc, GET_LEN);
6670-
_ADDOP_LOAD_CONST_NEW(c, loc, PyLong_FromSsize_t(size - i));
6671-
_ADDOP_BINARY(c, loc, Sub);
6667+
ADDOP(c, loc, GET_LEN);
6668+
ADDOP_LOAD_CONST_NEW(c, loc, PyLong_FromSsize_t(size - i));
6669+
ADDOP_BINARY(c, loc, Sub);
66726670
}
6673-
_ADDOP(c, loc, BINARY_SUBSCR);
6674-
RETURN_IF_FALSE(compiler_pattern_subpattern(c, pattern, pc));
6671+
ADDOP(c, loc, BINARY_SUBSCR);
6672+
RETURN_IF_ERROR(compiler_pattern_subpattern(c, pattern, pc));
66756673
}
66766674
// Pop the subject, we're done with it:
66776675
pc->on_top--;
6678-
_ADDOP(c, loc, POP_TOP);
6679-
return 1;
6676+
ADDOP(c, loc, POP_TOP);
6677+
return SUCCESS;
66806678
}
66816679

66826680
// Like compiler_pattern, but turn off checks for irrefutability.
@@ -6686,9 +6684,11 @@ compiler_pattern_subpattern(struct compiler *c,
66866684
{
66876685
int allow_irrefutable = pc->allow_irrefutable;
66886686
pc->allow_irrefutable = 1;
6689-
RETURN_IF_FALSE(compiler_pattern(c, p, pc));
6687+
if (!compiler_pattern(c, p, pc)) {
6688+
return ERROR;
6689+
}
66906690
pc->allow_irrefutable = allow_irrefutable;
6691-
return 1;
6691+
return SUCCESS;
66926692
}
66936693

66946694
static int
@@ -6811,7 +6811,9 @@ compiler_pattern_class(struct compiler *c, pattern_ty p, pattern_context *pc)
68116811
_ADDOP(c, LOC(p), POP_TOP);
68126812
continue;
68136813
}
6814-
RETURN_IF_FALSE(compiler_pattern_subpattern(c, pattern, pc));
6814+
if (compiler_pattern_subpattern(c, pattern, pc) < 0) {
6815+
return 0;
6816+
}
68156817
}
68166818
// Success! Pop the tuple of attributes:
68176819
return 1;
@@ -6924,7 +6926,9 @@ compiler_pattern_mapping(struct compiler *c, pattern_ty p,
69246926
for (Py_ssize_t i = 0; i < size; i++) {
69256927
pc->on_top--;
69266928
pattern_ty pattern = asdl_seq_GET(patterns, i);
6927-
RETURN_IF_FALSE(compiler_pattern_subpattern(c, pattern, pc));
6929+
if (compiler_pattern_subpattern(c, pattern, pc) < 0) {
6930+
return 0;
6931+
}
69286932
}
69296933
// If we get this far, it's a match! Whatever happens next should consume
69306934
// the tuple of keys and the subject:
@@ -7168,7 +7172,9 @@ compiler_pattern_sequence(struct compiler *c, pattern_ty p,
71687172
_ADDOP(c, LOC(p), POP_TOP);
71697173
}
71707174
else if (star_wildcard) {
7171-
RETURN_IF_FALSE(pattern_helper_sequence_subscr(c, LOC(p), patterns, star, pc));
7175+
if (pattern_helper_sequence_subscr(c, LOC(p), patterns, star, pc) < 0) {
7176+
return 0;
7177+
}
71727178
}
71737179
else {
71747180
if (pattern_helper_sequence_unpack(c, LOC(p), patterns, star, pc) < 0) {

0 commit comments

Comments
 (0)
0