@@ -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 );
@@ -1580,7 +1596,7 @@ expr_ty _PyPegen_interpolation(Parser *p, expr_ty expression, Token *debug, Resu
15801596 end_col_offset , arena
15811597 );
15821598
1583- if (!debug ) {
1599+ if (!interpolation || ! debug ) {
15841600 return interpolation ;
15851601 }
15861602
@@ -1591,6 +1607,9 @@ expr_ty _PyPegen_interpolation(Parser *p, expr_ty expression, Token *debug, Resu
15911607 }
15921608
15931609 asdl_expr_seq * values = _Py_asdl_expr_seq_new (2 , arena );
1610+ if (!values ) {
1611+ return NULL ;
1612+ }
15941613 asdl_seq_SET (values , 0 , debug_text );
15951614 asdl_seq_SET (values , 1 , interpolation );
15961615 return _PyAST_JoinedStr (values , lineno , col_offset , debug_end_line , debug_end_offset , p -> arena );
@@ -1607,7 +1626,7 @@ expr_ty _PyPegen_formatted_value(Parser *p, expr_ty expression, Token *debug, Re
16071626 end_col_offset , arena
16081627 );
16091628
1610- if (!debug ) {
1629+ if (!formatted_value || ! debug ) {
16111630 return formatted_value ;
16121631 }
16131632
@@ -1637,6 +1656,9 @@ expr_ty _PyPegen_formatted_value(Parser *p, expr_ty expression, Token *debug, Re
16371656 }
16381657
16391658 asdl_expr_seq * values = _Py_asdl_expr_seq_new (2 , arena );
1659+ if (!values ) {
1660+ return NULL ;
1661+ }
16401662 asdl_seq_SET (values , 0 , debug_text );
16411663 asdl_seq_SET (values , 1 , formatted_value );
16421664 return _PyAST_JoinedStr (values , lineno , col_offset , debug_end_line , debug_end_offset , p -> arena );
@@ -1904,6 +1926,9 @@ _build_concatenated_joined_str(Parser *p, asdl_expr_seq *strings,
19041926{
19051927 asdl_expr_seq * values = _build_concatenated_str (p , strings , lineno ,
19061928 col_offset , end_lineno , end_col_offset , arena );
1929+ if (!values ) {
1930+ return NULL ;
1931+ }
19071932 return _PyAST_JoinedStr (values , lineno , col_offset , end_lineno , end_col_offset , p -> arena );
19081933}
19091934
@@ -1914,6 +1939,9 @@ _PyPegen_concatenate_tstrings(Parser *p, asdl_expr_seq *strings,
19141939{
19151940 asdl_expr_seq * values = _build_concatenated_str (p , strings , lineno ,
19161941 col_offset , end_lineno , end_col_offset , arena );
1942+ if (!values ) {
1943+ return NULL ;
1944+ }
19171945 return _PyAST_TemplateStr (values , lineno , col_offset , end_lineno ,
19181946 end_col_offset , arena );
19191947}
0 commit comments