comparison Python/Python-ast.c @ 84679:cf8f42eadbd0

Issue #18408: Fix Python-ast.c: handle init_types() failure (ex: MemoryError)
author Victor Stinner <victor.stinner@gmail.com>
date Wed, 17 Jul 2013 00:17:15 +0200
parents 12cbb5183d98
children 1b464f8453a4
comparison
equal deleted inserted replaced
84678:c8696ee49291 84679:cf8f42eadbd0
7186 } 7186 }
7187 7187
7188 7188
7189 PyObject* PyAST_mod2obj(mod_ty t) 7189 PyObject* PyAST_mod2obj(mod_ty t)
7190 { 7190 {
7191 init_types(); 7191 if (!init_types())
7192 return NULL;
7192 return ast2obj_mod(t); 7193 return ast2obj_mod(t);
7193 } 7194 }
7194 7195
7195 /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ 7196 /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
7196 mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) 7197 mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
7200 (PyObject*)Interactive_type}; 7201 (PyObject*)Interactive_type};
7201 char *req_name[] = {"Module", "Expression", "Interactive"}; 7202 char *req_name[] = {"Module", "Expression", "Interactive"};
7202 int isinstance; 7203 int isinstance;
7203 assert(0 <= mode && mode <= 2); 7204 assert(0 <= mode && mode <= 2);
7204 7205
7205 init_types(); 7206 if (!init_types())
7207 return NULL;
7206 7208
7207 isinstance = PyObject_IsInstance(ast, req_type[mode]); 7209 isinstance = PyObject_IsInstance(ast, req_type[mode]);
7208 if (isinstance == -1) 7210 if (isinstance == -1)
7209 return NULL; 7211 return NULL;
7210 if (!isinstance) { 7212 if (!isinstance) {
7218 return res; 7220 return res;
7219 } 7221 }
7220 7222
7221 int PyAST_Check(PyObject* obj) 7223 int PyAST_Check(PyObject* obj)
7222 { 7224 {
7223 init_types(); 7225 if (!init_types())
7226 return -1;
7224 return PyObject_IsInstance(obj, (PyObject*)&AST_type); 7227 return PyObject_IsInstance(obj, (PyObject*)&AST_type);
7225 } 7228 }
7226 7229
7227 7230