Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bdf630c

Browse files
committed
Issue #18408: Fix Python-ast.c: handle init_types() failure (ex: MemoryError)
1 parent 6684bdf commit bdf630c

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

Parser/asdl_c.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,8 @@ class PartingShots(StaticVisitor):
11911191
CODE = """
11921192
PyObject* PyAST_mod2obj(mod_ty t)
11931193
{
1194-
init_types();
1194+
if (!init_types())
1195+
return NULL;
11951196
return ast2obj_mod(t);
11961197
}
11971198
@@ -1205,7 +1206,8 @@ class PartingShots(StaticVisitor):
12051206
int isinstance;
12061207
assert(0 <= mode && mode <= 2);
12071208
1208-
init_types();
1209+
if (!init_types())
1210+
return NULL;
12091211
12101212
isinstance = PyObject_IsInstance(ast, req_type[mode]);
12111213
if (isinstance == -1)
@@ -1223,7 +1225,8 @@ class PartingShots(StaticVisitor):
12231225
12241226
int PyAST_Check(PyObject* obj)
12251227
{
1226-
init_types();
1228+
if (!init_types())
1229+
return -1;
12271230
return PyObject_IsInstance(obj, (PyObject*)&AST_type);
12281231
}
12291232
"""

Python/Python-ast.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7188,7 +7188,8 @@ PyInit__ast(void)
71887188

71897189
PyObject* PyAST_mod2obj(mod_ty t)
71907190
{
7191-
init_types();
7191+
if (!init_types())
7192+
return NULL;
71927193
return ast2obj_mod(t);
71937194
}
71947195

@@ -7202,7 +7203,8 @@ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
72027203
int isinstance;
72037204
assert(0 <= mode && mode <= 2);
72047205

7205-
init_types();
7206+
if (!init_types())
7207+
return NULL;
72067208

72077209
isinstance = PyObject_IsInstance(ast, req_type[mode]);
72087210
if (isinstance == -1)
@@ -7220,7 +7222,8 @@ mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
72207222

72217223
int PyAST_Check(PyObject* obj)
72227224
{
7223-
init_types();
7225+
if (!init_types())
7226+
return -1;
72247227
return PyObject_IsInstance(obj, (PyObject*)&AST_type);
72257228
}
72267229

0 commit comments

Comments
 (0)