Skip to content

Commit 526e23f

Browse files
authored
Refactor error handling code in Parser/pegen/pegen.c (GH-20440)
Set p->error_indicator in various places, where it's needed, but it's not done. Automerge-Triggered-By: @gvanrossum
1 parent 29a1384 commit 526e23f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Parser/pegen/pegen.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -775,15 +775,15 @@ _PyPegen_expect_soft_keyword(Parser *p, const char *keyword)
775775
if (t->type != NAME) {
776776
return NULL;
777777
}
778-
char* s = PyBytes_AsString(t->bytes);
778+
char *s = PyBytes_AsString(t->bytes);
779779
if (!s) {
780+
p->error_indicator = 1;
780781
return NULL;
781782
}
782783
if (strcmp(s, keyword) != 0) {
783784
return NULL;
784785
}
785-
expr_ty res = _PyPegen_name_token(p);
786-
return res;
786+
return _PyPegen_name_token(p);
787787
}
788788

789789
Token *
@@ -809,10 +809,12 @@ _PyPegen_name_token(Parser *p)
809809
}
810810
char* s = PyBytes_AsString(t->bytes);
811811
if (!s) {
812+
p->error_indicator = 1;
812813
return NULL;
813814
}
814815
PyObject *id = _PyPegen_new_identifier(p, s);
815816
if (id == NULL) {
817+
p->error_indicator = 1;
816818
return NULL;
817819
}
818820
return Name(id, Load, t->lineno, t->col_offset, t->end_lineno, t->end_col_offset,
@@ -905,6 +907,7 @@ _PyPegen_number_token(Parser *p)
905907

906908
char *num_raw = PyBytes_AsString(t->bytes);
907909
if (num_raw == NULL) {
910+
p->error_indicator = 1;
908911
return NULL;
909912
}
910913

@@ -917,11 +920,13 @@ _PyPegen_number_token(Parser *p)
917920
PyObject *c = parsenumber(num_raw);
918921

919922
if (c == NULL) {
923+
p->error_indicator = 1;
920924
return NULL;
921925
}
922926

923927
if (PyArena_AddPyObject(p->arena, c) < 0) {
924928
Py_DECREF(c);
929+
p->error_indicator = 1;
925930
return NULL;
926931
}
927932

0 commit comments

Comments
 (0)