10000 bpo-41215: Don't use NULL by default in the PEG parser keyword list by pablogsal · Pull Request #21355 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-41215: Don't use NULL by default in the PEG parser keyword list #21355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Use non-NULL default values in the PEG parser keyword list to overcome a bug that was preventing
Python from being properly compiled when using the XLC compiler. Patch by Pablo Galindo.
4 changes: 2 additions & 2 deletions Parser/parser.c
10000
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ extern int Py_DebugFlag;
#endif
static const int n_keyword_lists = 9;
static KeywordToken *reserved_keywords[] = {
NULL,
NULL,
(KeywordToken[]) {{NULL, -1}},
(KeywordToken[]) {{NULL, -1}},
(KeywordToken[]) {
{"if", 510},
{"in", 518},
Expand Down
7 changes: 5 additions & 2 deletions Parser/pegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,13 @@ _PyPegen_dummy_name(Parser *p, ...)
static int
_get_keyword_or_name_type(Parser *p, const char *name, int name_len)
{
if (name_len >= p->n_keyword_lists || p->keywords[name_len] == NULL) {
assert(name_len != 0);
if (name_len >= p->n_keyword_lists ||
p->keywords[name_len] == NULL ||
p->keywords[name_len]->type == -1) {
return NAME;
}
for (KeywordToken *k = p->keywords[name_len]; k->type != -1; k++) {
for (KeywordToken *k = p->keywords[name_len]; k != NULL && k->type != -1; k++) {
if (strncmp(k->str, name, name_len) == 0) {
return k->type;
}
Expand Down
2 changes: 1 addition & 1 deletion Tools/peg_generator/pegen/c_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def _setup_keywords(self) -> None:
num_groups = max(groups) + 1 if groups else 1
for keywords_length in range(num_groups):
if keywords_length not in groups.keys():
self.print("NULL,")
self.print("(KeywordToken[]) {{NULL, -1}},")
else:
self.print("(KeywordToken[]) {")
with self.indent():
Expand Down
0