From 39e76c0fb07e20acad454deb86a0457b279884a9 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Mon, 6 Jul 2020 19:34:32 +0100 Subject: [PATCH 1/2] bpo-41215: Don't use NULL by default in the PEG parser keyword list --- .../2020-07-06-18-36-33.bpo-41215.vFGFIz.rst | 2 ++ Parser/parser.c | 4 ++-- Parser/pegen.c | 7 +++++-- Tools/peg_generator/pegen/c_generator.py | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2020-07-06-18-36-33.bpo-41215.vFGFIz.rst 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 00000000000000..3d374a8e9a531f --- /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 to be properly compiled when using the XLC compiler. Patch by Pablo Galindo. \ No newline at end of file diff --git a/Parser/parser.c b/Parser/parser.c index bfd5c47caf07e1..75dc7176a5e756 100644 --- a/Parser/parser.c +++ b/Parser/parser.c @@ -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}, diff --git a/Parser/pegen.c b/Parser/pegen.c index 53e3d491383068..42f9e0c41bf498 100644 --- a/Parser/pegen.c +++ b/Parser/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 58a44fbe67e8ba..aee668c3f329ab 100644 --- a/Tools/peg_generator/pegen/c_generator.py +++ b/Tools/peg_generator/pegen/c_generator.py @@ -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(): From 668965433fa3b4ce5ac7ba7fb72b094b30621d0a Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Mon, 6 Jul 2020 20:09:39 +0100 Subject: [PATCH 2/2] Update Misc/NEWS.d/next/Core and Builtins/2020-07-06-18-36-33.bpo-41215.vFGFIz.rst Co-authored-by: Lysandros Nikolaou --- .../Core and Builtins/2020-07-06-18-36-33.bpo-41215.vFGFIz.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 3d374a8e9a531f..7343da31e94f78 100644 --- 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 @@ -1,2 +1,2 @@ Use non-NULL default values in the PEG parser keyword list to overcome a bug that was preventing -Python to be properly compiled when using the XLC compiler. Patch by Pablo Galindo. \ No newline at end of file +Python from being properly compiled when using the XLC compiler. Patch by Pablo Galindo.