comparison Python/pythonrun.c @ 39131:7c09b66f04bd legacy-trunk

Handle more memory allocation failures without crashing.
author Neal Norwitz <nnorwitz@gmail.com>
date Fri, 21 Jul 2006 07:59:47 +0000
parents aa85791f5991
children 12e973bdfeee
comparison
equal deleted inserted replaced
39130:baa54337c3d9 39131:7c09b66f04bd
1202 PyRun_StringFlags(const char *str, int start, PyObject *globals, 1202 PyRun_StringFlags(const char *str, int start, PyObject *globals,
1203 PyObject *locals, PyCompilerFlags *flags) 1203 PyObject *locals, PyCompilerFlags *flags)
1204 { 1204 {
1205 PyObject *ret = NULL; 1205 PyObject *ret = NULL;
1206 PyArena *arena = PyArena_New(); 1206 PyArena *arena = PyArena_New();
1207 mod_ty mod = PyParser_ASTFromString(str, "<string>", start, flags, 1207 mod_ty mod;
1208 arena); 1208
1209 if (arena == NULL)
1210 return NULL;
1211
1212 mod = PyParser_ASTFromString(str, "<string>", start, flags, arena);
1209 if (mod != NULL) 1213 if (mod != NULL)
1210 ret = run_mod(mod, "<string>", globals, locals, flags, arena); 1214 ret = run_mod(mod, "<string>", globals, locals, flags, arena);
1211 PyArena_Free(arena); 1215 PyArena_Free(arena);
1212 return ret; 1216 return ret;
1213 } 1217 }
1216 PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals, 1220 PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals,
1217 PyObject *locals, int closeit, PyCompilerFlags *flags) 1221 PyObject *locals, int closeit, PyCompilerFlags *flags)
1218 { 1222 {
1219 PyObject *ret; 1223 PyObject *ret;
1220 PyArena *arena = PyArena_New(); 1224 PyArena *arena = PyArena_New();
1221 mod_ty mod = PyParser_ASTFromFile(fp, filename, start, 0, 0, 1225 mod_ty mod;
1222 flags, NULL, arena); 1226
1227 if (arena == NULL)
1228 return NULL;
1229
1230 mod = PyParser_ASTFromFile(fp, filename, start, 0, 0,
1231 flags, NULL, arena);
1223 if (mod == NULL) { 1232 if (mod == NULL) {
1224 PyArena_Free(arena); 1233 PyArena_Free(arena);
1225 return NULL; 1234 return NULL;
1226 } 1235 }
1227 if (closeit) 1236 if (closeit)