diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2020-07-06 19:29:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-06 19:29:59 (GMT) |
commit | 54f115dd533653c43b3c5541bf5936b22e484474 (patch) | |
tree | 9fec888a0615b0de6fe7c25276f432a92ba42a69 | |
parent | 4981fe36c7477303de830e8dca929a02caaaffe4 (diff) | |
download | cpython-54f115dd533653c43b3c5541bf5936b22e484474.zip cpython-54f115dd533653c43b3c5541bf5936b22e484474.tar.gz cpython-54f115dd533653c43b3c5541bf5936b22e484474.tar.bz2 |
[3.9] bpo-41215: Don't use NULL by default in the PEG parser keyword list (GH-21355) (GH-21356)
(cherry picked from commit 39e76c0fb07e20acad454deb86a0457b279884a9)
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
Automerge-Triggered-By: @lysnikolaou
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2020-07-06-18-36-33.bpo-41215.vFGFIz.rst | 2 | ||||
-rw-r--r-- | Parser/pegen/parse.c | 14 | ||||
-rw-r--r-- | Parser/pegen/pegen.c | 7 | ||||
-rw-r--r-- | Tools/peg_generator/pegen/c_generator.py | 2 |
4 files changed, 15 insertions, 10 deletions
diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-07-06-18-36-33.bpo-41215.vFGFIz.rst b/Misc/NEWS.d/next/Core and Builtins/2020-07-06-18-36-33.bpo-41215.vFGFIz.rst new file mode 100644 index 0000000..7343da3 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-07-06-18-36-33.bpo-41215.vFGFIz.rst @@ -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.
diff --git a/Parser/pegen/parse.c b/Parser/pegen/parse.c index 9d3ac57..d9dd23c 100644 --- a/Parser/pegen/parse.c +++ b/Parser/pegen/parse.c @@ -9,8 +9,8 @@ extern int Py_DebugFlag; #endif static const int n_keyword_lists = 15; static KeywordToken *reserved_keywords[] = { - NULL, - NULL, + (KeywordToken[]) {{NULL, -1}}, + (KeywordToken[]) {{NULL, -1}}, (KeywordToken[]) { {"if", 510}, {"in", 518}, @@ -65,11 +65,11 @@ static KeywordToken *reserved_keywords[] = { {"nonlocal", 509}, {NULL, -1}, }, - NULL, - NULL, - NULL, - NULL, - NULL, + (KeywordToken[]) {{NULL, -1}}, + (KeywordToken[]) {{NULL, -1}}, + (KeywordToken[]) {{NULL, -1}}, + (KeywordToken[]) {{NULL, -1}}, + (KeywordToken[]) {{NULL, -1}}, (KeywordToken[]) { {"__peg_parser__", 531}, {NULL, -1}, diff --git a/Parser/pegen/pegen.c b/Parser/pegen/pegen.c index 895677b..0f33dcb 100644 --- a/Parser/pegen/pegen.c +++ b/Parser/pegen/pegen.c @@ -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; } diff --git a/Tools/peg_generator/pegen/c_generator.py b/Tools/peg_generator/pegen/c_generator.py index 58a44fb..aee668c 100644 --- a/Tools/peg_generator/pegen/c_generator.py +++ b/Tools/peg_generator/pegen/c_generator.py @@ -440,7 +440,7 @@ class CParserGenerator(ParserGenerator, GrammarVisitor): 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(): |