]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41215: Don't use NULL by default in the PEG parser keyword list
authorPablo Galindo <pablogsal@gmail.com>
Mon, 6 Jul 2020 18:34:32 +0000 (19:34 +0100)
committerPablo Galindo <pablogsal@gmail.com>
Mon, 6 Jul 2020 18:40:50 +0000 (19:40 +0100)
Misc/NEWS.d/next/Core and Builtins/2020-07-06-18-36-33.bpo-41215.vFGFIz.rst [new file with mode: 0644]
Parser/parser.c
Parser/pegen.c
Tools/peg_generator/pegen/c_generator.py

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 (file)
index 0000000..3d374a8
--- /dev/null
@@ -0,0 +1,2 @@
+Use non-NULL default values in the PEG parser keyword list to overcome a bug that was preventing\r
+Python to be properly compiled when using the XLC compiler. Patch by Pablo Galindo.
\ No newline at end of file
index bfd5c47caf07e1b34bf1e7bf9bc25fff2e640e5a..75dc7176a5e756d87a286f86e70c043f9fc5e228 100644 (file)
@@ -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},
index 53e3d4913830689099af2153466e884f328dc9c7..42f9e0c41bf49881ac51ef1037e46f03c16674bc 100644 (file)
@@ -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;
         }
index 58a44fbe67e8badcec2be0baa1a6bc3872c3d040..aee668c3f329ababa04d826c14452786e0752a84 100644 (file)
@@ -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():