[3.9] bpo-41060: Avoid SEGFAULT when calling GET_INVALID_TARGET in the grammar (GH-21020) (GH-21024)
`GET_INVALID_TARGET` might unexpectedly return `NULL`, which if not
caught will cause a SEGFAULT. Therefore, this commit introduces a new
inline function `RAISE_SYNTAX_ERROR_INVALID_TARGET` that always
checks for `GET_INVALID_TARGET` returning NULL and can be used in
the grammar, replacing the long C ternary operation used till now.
(cherry picked from commit 6c4e0bd974f2895d42b63d9d004587e74b286c88)
Automerge-Triggered-By: @pablogsal
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index b231f1c..e80a867 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -191,6 +191,10 @@
Traceback (most recent call last):
SyntaxError: invalid syntax
+>>> for a, b
+Traceback (most recent call last):
+SyntaxError: invalid syntax
+
>>> with a as b(): pass
Traceback (most recent call last):
SyntaxError: cannot assign to function call
@@ -215,6 +219,10 @@
Traceback (most recent call last):
SyntaxError: cannot assign to function call
+>>> with a as b
+Traceback (most recent call last):
+SyntaxError: invalid syntax
+
>>> p = p =
Traceback (most recent call last):
SyntaxError: invalid syntax