Commit eda7b44d authored by Victor Stinner's avatar Victor Stinner

Issue #18408: Handle PyArena_AddPyObject() failure in ast.c

PyList_Append() (called by PyArena_AddPyObject()) can fail because of a
MemoryError for example.
parent c0432bcc
...@@ -560,7 +560,10 @@ new_identifier(const char *n, struct compiling *c) ...@@ -560,7 +560,10 @@ new_identifier(const char *n, struct compiling *c)
id = id2; id = id2;
} }
PyUnicode_InternInPlace(&id); PyUnicode_InternInPlace(&id);
PyArena_AddPyObject(c->c_arena, id); if (PyArena_AddPyObject(c->c_arena, id) < 0) {
Py_DECREF(id);
return NULL;
}
return id; return id;
} }
...@@ -1847,7 +1850,10 @@ ast_for_atom(struct compiling *c, const node *n) ...@@ -1847,7 +1850,10 @@ ast_for_atom(struct compiling *c, const node *n)
} }
return NULL; return NULL;
} }
PyArena_AddPyObject(c->c_arena, str); if (PyArena_AddPyObject(c->c_arena, str) < 0) {
Py_DECREF(str);
return NULL;
}
if (bytesmode) if (bytesmode)
return Bytes(str, LINENO(n), n->n_col_offset, c->c_arena); return Bytes(str, LINENO(n), n->n_col_offset, c->c_arena);
else else
...@@ -1858,7 +1864,10 @@ ast_for_atom(struct compiling *c, const node *n) ...@@ -1858,7 +1864,10 @@ ast_for_atom(struct compiling *c, const node *n)
if (!pynum) if (!pynum)
return NULL; return NULL;
PyArena_AddPyObject(c->c_arena, pynum); if (PyArena_AddPyObject(c->c_arena, pynum) < 0) {
Py_DECREF(pynum);
return NULL;
}
return Num(pynum, LINENO(n), n->n_col_offset, c->c_arena); return Num(pynum, LINENO(n), n->n_col_offset, c->c_arena);
} }
case ELLIPSIS: /* Ellipsis */ case ELLIPSIS: /* Ellipsis */
...@@ -2845,13 +2854,19 @@ alias_for_import_name(struct compiling *c, const node *n, int store) ...@@ -2845,13 +2854,19 @@ alias_for_import_name(struct compiling *c, const node *n, int store)
return NULL; return NULL;
str = uni; str = uni;
PyUnicode_InternInPlace(&str); PyUnicode_InternInPlace(&str);
PyArena_AddPyObject(c->c_arena, str); if (PyArena_AddPyObject(c->c_arena, str) < 0) {
Py_DECREF(str);
return NULL;
}
return alias(str, NULL, c->c_arena); return alias(str, NULL, c->c_arena);
} }
break; break;
case STAR: case STAR:
str = PyUnicode_InternFromString("*"); str = PyUnicode_InternFromString("*");
PyArena_AddPyObject(c->c_arena, str); if (PyArena_AddPyObject(c->c_arena, str) < 0) {
Py_DECREF(str);
return NULL;
}
return alias(str, NULL, c->c_arena); return alias(str, NULL, c->c_arena);
default: default:
PyErr_Format(PyExc_SystemError, PyErr_Format(PyExc_SystemError,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment