8000 pattern_helper_store_name returns SUCCESS/ERROR · python/cpython@cbb63b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit cbb63b0

Browse files
committed
pattern_helper_store_name returns SUCCESS/ERROR
1 parent a5d017d commit cbb63b0

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

Python/compile.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6558,27 +6558,30 @@ pattern_helper_store_name(struct compiler *c, location loc,
65586558
identifier n, pattern_context *pc)
65596559
{
65606560
if (n == NULL) {
6561-
_ADDOP(c, loc, POP_TOP);
6562-
return 1;
6561+
ADDOP(c, loc, POP_TOP);
6562+
return SUCCESS;
65636563
}
65646564
if (forbidden_name(c, loc, n, Store)) {
6565-
return 0;
6565+
return ERROR;
65666566
}
65676567
// Can't assign to the same name twice:
65686568
int duplicate = PySequence_Contains(pc->stores, n);
65696569
if (duplicate < 0) {
6570-
return 0;
6570+
return ERROR;
65716571
}
65726572
if (duplicate) {
65736573
compiler_error_duplicate_store(c, loc, n);
6574-
return 0;
6574+
return ERROR;
65756575
}
65766576
// Rotate this object underneath any items we need to preserve:
65776577
Py_ssize_t rotations = pc->on_top + PyList_GET_SIZE(pc->stores) + 1;
65786578
if (pattern_helper_rotate(c, loc, rotations) < 0) {
6579-
return 0;
6579+
return ERROR;
6580+
}
6581+
if (PyList_Append(pc->stores, n) < 0) {
6582+
return ERROR;
65806583
}
6581-
return !PyList_Append(pc->stores, n);
6584+
return SUCCESS;
65826585
}
65836586

65846587

@@ -6695,23 +6698,27 @@ compiler_pattern_as(struct compiler *c, pattern_ty p, pattern_context *pc)
66956698
const char *e = "wildcard makes remaining patterns unreachable";
66966699
return compiler_error(c, LOC(p), e);
66976700
}
6698-
return pattern_helper_store_name(c, LOC(p), p->v.MatchAs.name, pc);
6701+
return pattern_helper_store_name(c, LOC(p), p->v.MatchAs.name, pc) == SUCCESS ? 1 : 0;
66996702
}
67006703
// Need to make a copy for (possibly) storing later:
67016704
pc->on_top++;
67026705
_ADDOP_I(c, LOC(p), COPY, 1);
67036706
RETURN_IF_FALSE(compiler_pattern(c, p->v.MatchAs.pattern, pc));
67046707
// Success! Store it:
67056708
pc->on_top--;
6706-
RETURN_IF_FALSE(pattern_helper_store_name(c, LOC(p), p->v.MatchAs.name, pc));
6709+
if (pattern_helper_store_name(c, LOC(p), p->v.MatchAs.name, pc) < 0) {
6710+
return 0;
6711+
}
67076712
return 1;
67086713
}
67096714

67106715
static int
67116716
compiler_pattern_star(struct compiler *c, pattern_ty p, pattern_context *pc)
67126717
{
67136718
assert(p->kind == MatchStar_kind);
6714-
RETURN_IF_FALSE(pattern_helper_store_name(c, LOC(p), p->v.MatchStar.name, pc));
6719+
if (pattern_helper_store_name(c, LOC(p), p->v.MatchStar.name, pc) < 0) {
6720+
return 0;
6721+
}
67156722
return 1;
67166723
}
67176724

@@ -6931,7 +6938,9 @@ compiler_pattern_mapping(struct compiler *c, pattern_ty p,
69316938
_ADDOP_I(c, LOC(p), SWAP, 2); // [copy, keys..., copy, key]
69326939
_ADDOP(c, LOC(p), DELETE_SUBSCR); // [copy, keys...]
69336940
}
6934-
RETURN_IF_FALSE(pattern_helper_store_name(c, LOC(p), star_target, pc));
6941+
if (pattern_helper_store_name(c, LOC(p), star_target, pc) < 0) {
6942+
return 0;
6943+
}
69356944
}
69366945
else {
69376946
_ADDOP(c, LOC(p), POP_TOP); // Tuple of keys.

0 commit comments

Comments
 (0)
0