@@ -254,7 +254,11 @@ _set_seq_context(Parser *p, asdl_expr_seq *seq, expr_context_ty ctx)
254254 }
255255 for (Py_ssize_t i = 0 ; i < len ; i ++ ) {
256256 expr_ty e = asdl_seq_GET (seq , i );
257- asdl_seq_SET (new_seq , i , _PyPegen_set_expr_context (p , e , ctx ));
257+ expr_ty new_e = _PyPegen_set_expr_context (p , e , ctx );
258+ if (!new_e ) {
259+ return NULL ;
260+ }
261+ asdl_seq_SET (new_seq , i , new_e );
258262 }
259263 return new_seq ;
260264}
@@ -268,19 +272,21 @@ _set_name_context(Parser *p, expr_ty e, expr_context_ty ctx)
268272static expr_ty
269273_set_tuple_context (Parser * p , expr_ty e , expr_context_ty ctx )
270274{
271- return _PyAST_Tuple (
272- _set_seq_context (p , e -> v .Tuple .elts , ctx ),
273- ctx ,
274- EXTRA_EXPR (e , e ));
275+ asdl_expr_seq * seq = _set_seq_context (p , e -> v .Tuple .elts , ctx );
276+ if (!seq && PyErr_Occurred ()) {
277+ return NULL ;
278+ }
279+ return _PyAST_Tuple (seq , ctx , EXTRA_EXPR (e , e ));
275280}
276281
277282static expr_ty
278283_set_list_context (Parser * p , expr_ty e , expr_context_ty ctx )
279284{
280- return _PyAST_List (
281- _set_seq_context (p , e -> v .List .elts , ctx ),
282- ctx ,
283- EXTRA_EXPR (e , e ));
285+ asdl_expr_seq * seq = _set_seq_context (p , e -> v .List .elts , ctx );
286+ if (!seq && PyErr_Occurred ()) {
287+ return NULL ;
288+ }
289+ return _PyAST_List (seq , ctx , EXTRA_EXPR (e , e ));
284290}
285291
286292static expr_ty
@@ -300,8 +306,11 @@ _set_attribute_context(Parser *p, expr_ty e, expr_context_ty ctx)
300306static expr_ty
301307_set_starred_context (Parser * p , expr_ty e , expr_context_ty ctx )
302308{
303- return _PyAST_Starred (_PyPegen_set_expr_context (p , e -> v .Starred .value , ctx ),
304- ctx , EXTRA_EXPR (e , e ));
309+ expr_ty inner = _PyPegen_set_expr_context (p , e -> v .Starred .value , ctx );
310+ if (!inner ) {
311+ return NULL ;
312+ }
313+ return _PyAST_Starred (inner , ctx , EXTRA_EXPR (e , e ));
305314}
306315
307316/* Creates an `expr_ty` equivalent to `expr` but with `ctx` as context */
@@ -1168,7 +1177,14 @@ expr_ty _PyPegen_collect_call_seqs(Parser *p, asdl_expr_seq *a, asdl_seq *b,
11681177 }
11691178
11701179 asdl_expr_seq * starreds = _PyPegen_seq_extract_starred_exprs (p , b );
1180+ if (!starreds && PyErr_Occurred ()) {
1181+ return NULL ;
1182+ }
1183+
11711184 asdl_keyword_seq * keywords = _PyPegen_seq_delete_starred_exprs (p , b );
1185+ if (!keywords && PyErr_Occurred ()) {
1186+ return NULL ;
1187+ }
11721188
11731189 if (starreds ) {
11741190 total_len += asdl_seq_LEN (starreds );
@@ -1416,6 +1432,9 @@ expr_ty
14161432_PyPegen_template_str (Parser * p , Token * a , asdl_expr_seq * raw_expressions , Token * b ) {
14171433
14181434 asdl_expr_seq * resized_exprs = _get_resized_exprs (p , a , raw_expressions , b , TSTRING );
1435+ if (!resized_exprs && PyErr_Occurred ()) {
1436+ return NULL ;
1437+ }
14191438 return _PyAST_TemplateStr (resized_exprs , a -> lineno , a -> col_offset ,
14201439 b -> end_lineno , b -> end_col_offset ,
14211440 p -> arena );
@@ -1425,6 +1444,9 @@ expr_ty
14251444_PyPegen_joined_str (Parser * p , Token * a , asdl_expr_seq * raw_expressions , Token * b ) {
14261445
14271446 asdl_expr_seq * resized_exprs = _get_resized_exprs (p , a , raw_expressions , b , FSTRING );
1447+ if (!resized_exprs && PyErr_Occurred ()) {
1448+ return NULL ;
1449+ }
14281450 return _PyAST_JoinedStr (resized_exprs , a -> lineno , a -> col_offset ,
14291451 b -> end_lineno , b -> end_col_offset ,
14301452 p -> arena );
@@ -1574,7 +1596,7 @@ expr_ty _PyPegen_interpolation(Parser *p, expr_ty expression, Token *debug, Resu
15741596 end_col_offset , arena
15751597 );
15761598
1577- if (!debug ) {
1599+ if (!interpolation || ! debug ) {
15781600 return interpolation ;
15791601 }
15801602
@@ -1585,6 +1607,9 @@ expr_ty _PyPegen_interpolation(Parser *p, expr_ty expression, Token *debug, Resu
15851607 }
15861608
15871609 asdl_expr_seq * values = _Py_asdl_expr_seq_new (2 , arena );
1610+ if (!values ) {
1611+ return NULL ;
1612+ }
15881613 asdl_seq_SET (values , 0 , debug_text );
15891614 asdl_seq_SET (values , 1 , interpolation );
15901615 return _PyAST_JoinedStr (values , lineno , col_offset , debug_end_line , debug_end_offset , p -> arena );
@@ -1601,7 +1626,7 @@ expr_ty _PyPegen_formatted_value(Parser *p, expr_ty expression, Token *debug, Re
16011626 end_col_offset , arena
16021627 );
16031628
1604- if (!debug ) {
1629+ if (!formatted_value || ! debug ) {
16051630 return formatted_value ;
16061631 }
16071632
@@ -1631,6 +1656,9 @@ expr_ty _PyPegen_formatted_value(Parser *p, expr_ty expression, Token *debug, Re
16311656 }
16321657
16331658 asdl_expr_seq * values = _Py_asdl_expr_seq_new (2 , arena );
1659+ if (!values ) {
1660+ return NULL ;
1661+ }
16341662 asdl_seq_SET (values , 0 , debug_text );
16351663 asdl_seq_SET (values , 1 , formatted_value );
16361664 return _PyAST_JoinedStr (values , lineno , col_offset , debug_end_line , debug_end_offset , p -> arena );
@@ -1898,6 +1926,9 @@ _build_concatenated_joined_str(Parser *p, asdl_expr_seq *strings,
18981926{
18991927 asdl_expr_seq * values = _build_concatenated_str (p , strings , lineno ,
19001928 col_offset , end_lineno , end_col_offset , arena );
1929+ if (!values ) {
1930+ return NULL ;
1931+ }
19011932 return _PyAST_JoinedStr (values , lineno , col_offset , end_lineno , end_col_offset , p -> arena );
19021933}
19031934
@@ -1908,6 +1939,9 @@ _PyPegen_concatenate_tstrings(Parser *p, asdl_expr_seq *strings,
19081939{
19091940 asdl_expr_seq * values = _build_concatenated_str (p , strings , lineno ,
19101941 col_offset , end_lineno , end_col_offset , arena );
1942+ if (!values ) {
1943+ return NULL ;
1944+ }
19111945 return _PyAST_TemplateStr (values , lineno , col_offset , end_lineno ,
19121946 end_col_offset , arena );
19131947}
0 commit comments