summaryrefslogtreecommitdiffstats
path: root/Grammar/python.gram
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2020-06-21 02:47:22 (GMT)
committerGitHub <noreply@github.com>2020-06-21 02:47:22 (GMT)
commit71bb921829c33c30b2e111e18948df8c2b6731e4 (patch)
treecdcfa2d0ffed021c046d3dbc355fdeefa583b025 /Grammar/python.gram
parentd301d9473e9a9b78d6e6678e9fe5ef66d46084e1 (diff)
downloadcpython-71bb921829c33c30b2e111e18948df8c2b6731e4.zip
cpython-71bb921829c33c30b2e111e18948df8c2b6731e4.tar.gz
cpython-71bb921829c33c30b2e111e18948df8c2b6731e4.tar.bz2
[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
Diffstat (limited to 'Grammar/python.gram')
-rw-r--r--Grammar/python.gram23
1 files changed, 4 insertions, 19 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram
index 314f1f5..8e6174f 100644
--- a/Grammar/python.gram
+++ b/Grammar/python.gram
@@ -655,9 +655,7 @@ invalid_assignment:
| a=expression ':' expression ['=' annotated_rhs] {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "illegal target for annotation") }
| (star_targets '=')* a=star_expressions '=' {
- RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
- GET_INVALID_TARGET(a),
- "cannot assign to %s", _PyPegen_get_expr_name(GET_INVALID_TARGET(a))) }
+ RAISE_SYNTAX_ERROR_INVALID_TARGET(STAR_TARGETS, a) }
| (star_targets '=')* a=yield_expr '=' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "assignment to yield expression not possible") }
| a=star_expressions augassign (yield_expr | star_expressions) {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
@@ -667,12 +665,7 @@ invalid_assignment:
)}
invalid_del_stmt:
| 'del' a=star_expressions {
- GET_INVALID_DEL_TARGET(a) != NULL ?
- RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
- GET_INVALID_DEL_TARGET(a),
- "cannot delete %s", _PyPegen_get_expr_name(GET_INVALID_DEL_TARGET(a))
- ) :
- RAISE_SYNTAX_ERROR("invalid syntax") }
+ RAISE_SYNTAX_ERROR_INVALID_TARGET(DEL_TARGETS, a) }
invalid_block:
| NEWLINE !INDENT { RAISE_INDENTATION_ERROR("expected an indented block") }
invalid_comprehension:
@@ -697,19 +690,11 @@ invalid_double_type_comments:
RAISE_SYNTAX_ERROR("Cannot have two type comments on def") }
invalid_with_item:
| expression 'as' a=expression {
- RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
- GET_INVALID_TARGET(a),
- "cannot assign to %s", _PyPegen_get_expr_name(GET_INVALID_TARGET(a))
- ) }
+ RAISE_SYNTAX_ERROR_INVALID_TARGET(STAR_TARGETS, a) }
invalid_for_target:
| ASYNC? 'for' a=star_expressions {
- GET_INVALID_FOR_TARGET(a) != NULL ?
- RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
- GET_INVALID_FOR_TARGET(a),
- "cannot assign to %s", _PyPegen_get_expr_name(GET_INVALID_FOR_TARGET(a))
- ) :
- RAISE_SYNTAX_ERROR("invalid syntax") }
+ RAISE_SYNTAX_ERROR_INVALID_TARGET(FOR_TARGETS, a) }
invalid_group:
| '(' a=starred_expression ')' {