summaryrefslogtreecommitdiffstats
path: root/Parser/asdl_c.py
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2022-05-31 23:00:47 (GMT)
committerGitHub <noreply@github.com>2022-05-31 23:00:47 (GMT)
commit705eaec28f7bee530b1c1635ba385a49a1feaf32 (patch)
treedd0697dbd8acd604e89cb20e9890850b9e8fe2cd /Parser/asdl_c.py
parentfc694364cc6745eefba0afc3ea2c5283bbb64a3b (diff)
downloadcpython-705eaec28f7bee530b1c1635ba385a49a1feaf32.zip
cpython-705eaec28f7bee530b1c1635ba385a49a1feaf32.tar.gz
cpython-705eaec28f7bee530b1c1635ba385a49a1feaf32.tar.bz2
gh-92597: Ensure that AST nodes without explicit end positions can be compiled (GH-93359)
Diffstat (limited to 'Parser/asdl_c.py')
-rwxr-xr-xParser/asdl_c.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index 3bfe320..1101a35 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -488,6 +488,12 @@ class Obj2ModPrototypeVisitor(PickleVisitor):
class Obj2ModVisitor(PickleVisitor):
+
+ attribute_special_defaults = {
+ "end_lineno": "lineno",
+ "end_col_offset": "col_offset",
+ }
+
@contextmanager
def recursive_call(self, node, level):
self.emit('if (_Py_EnterRecursiveCall(" while traversing \'%s\' node")) {' % node, level, reflow=False)
@@ -637,7 +643,13 @@ class Obj2ModVisitor(PickleVisitor):
self.emit("if (tmp == NULL || tmp == Py_None) {", depth)
self.emit("Py_CLEAR(tmp);", depth+1)
if self.isNumeric(field):
- self.emit("%s = 0;" % field.name, depth+1)
+ if field.name in self.attribute_special_defaults:
+ self.emit(
+ "%s = %s;" % (field.name, self.attribute_special_defaults[field.name]),
+ depth+1,
+ )
+ else:
+ self.emit("%s = 0;" % field.name, depth+1)
elif not self.isSimpleType(field):
self.emit("%s = NULL;" % field.name, depth+1)
else: