[3.9] bpo-41215: Don't use NULL by default in the PEG parser keyword list (GH-21355) (GH-21356)

(cherry picked from commit 39e76c0fb0)

Co-authored-by: Pablo Galindo <pablogsal@gmail.com>

Automerge-Triggered-By: @lysnikolaou
This commit is contained in:
Pablo Galindo 2020-07-06 20:29:59 +01:00 committed by GitHub
parent 4981fe36c7
commit 54f115dd53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 10 deletions

View file

@ -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.

View file

@ -9,8 +9,8 @@ extern int Py_DebugFlag;
#endif #endif
static const int n_keyword_lists = 15; static const int n_keyword_lists = 15;
static KeywordToken *reserved_keywords[] = { static KeywordToken *reserved_keywords[] = {
NULL, (KeywordToken[]) {{NULL, -1}},
NULL, (KeywordToken[]) {{NULL, -1}},
(KeywordToken[]) { (KeywordToken[]) {
{"if", 510}, {"if", 510},
{"in", 518}, {"in", 518},
@ -65,11 +65,11 @@ static KeywordToken *reserved_keywords[] = {
{"nonlocal", 509}, {"nonlocal", 509},
{NULL, -1}, {NULL, -1},
}, },
NULL, (KeywordToken[]) {{NULL, -1}},
NULL, (KeywordToken[]) {{NULL, -1}},
NULL, (KeywordToken[]) {{NULL, -1}},
NULL, (KeywordToken[]) {{NULL, -1}},
NULL, (KeywordToken[]) {{NULL, -1}},
(KeywordToken[]) { (KeywordToken[]) {
{"__peg_parser__", 531}, {"__peg_parser__", 531},
{NULL, -1}, {NULL, -1},

View file

@ -525,10 +525,13 @@ _PyPegen_dummy_name(Parser *p, ...)
static int static int
_get_keyword_or_name_type(Parser *p, const char *name, int name_len) _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; 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) { if (strncmp(k->str, name, name_len) == 0) {
return k->type; return k->type;
} }

View file

@ -440,7 +440,7 @@ class CParserGenerator(ParserGenerator, GrammarVisitor):
num_groups = max(groups) + 1 if groups else 1 num_groups = max(groups) + 1 if groups else 1
for keywords_length in range(num_groups): for keywords_length in range(num_groups):
if keywords_length not in groups.keys(): if keywords_length not in groups.keys():
self.print("NULL,") self.print("(KeywordToken[]) {{NULL, -1}},")
else: else:
self.print("(KeywordToken[]) {") self.print("(KeywordToken[]) {")
with self.indent(): with self.indent():