comparison Python/pythonrun.c @ 61274:95c400b9d74c legacy-trunk

Change to a Py_XDECREF and fix some whitespace. Found using Clang's static analyzer.
author Brett Cannon <bcannon@gmail.com>
date Wed, 05 May 2010 20:38:52 +0000
parents 4468666d01c4
children 435a8355dab6
comparison
equal deleted inserted replaced
61273:3fe4c34f78c0 61274:95c400b9d74c
136 { 136 {
137 PyInterpreterState *interp; 137 PyInterpreterState *interp;
138 PyThreadState *tstate; 138 PyThreadState *tstate;
139 PyObject *bimod, *sysmod; 139 PyObject *bimod, *sysmod;
140 char *p; 140 char *p;
141 char *icodeset = NULL; /* On Windows, input codeset may theoretically 141 char *icodeset = NULL; /* On Windows, input codeset may theoretically
142 differ from output codeset. */ 142 differ from output codeset. */
143 char *codeset = NULL; 143 char *codeset = NULL;
144 char *errors = NULL; 144 char *errors = NULL;
145 int free_codeset = 0; 145 int free_codeset = 0;
146 int overridden = 0; 146 int overridden = 0;
235 235
236 _PyImportHooks_Init(); 236 _PyImportHooks_Init();
237 237
238 if (install_sigs) 238 if (install_sigs)
239 initsigs(); /* Signal handling stuff, including initintr() */ 239 initsigs(); /* Signal handling stuff, including initintr() */
240 240
241 /* Initialize warnings. */ 241 /* Initialize warnings. */
242 _PyWarnings_Init(); 242 _PyWarnings_Init();
243 if (PySys_HasWarnOptions()) { 243 if (PySys_HasWarnOptions()) {
244 PyObject *warnings_module = PyImport_ImportModule("warnings"); 244 PyObject *warnings_module = PyImport_ImportModule("warnings");
245 if (!warnings_module) 245 if (!warnings_module)
337 337
338 sys_stream = PySys_GetObject("stdout"); 338 sys_stream = PySys_GetObject("stdout");
339 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); 339 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", "");
340 if (!sys_isatty) 340 if (!sys_isatty)
341 PyErr_Clear(); 341 PyErr_Clear();
342 if ((overridden || 342 if ((overridden ||
343 (sys_isatty && PyObject_IsTrue(sys_isatty))) && 343 (sys_isatty && PyObject_IsTrue(sys_isatty))) &&
344 PyFile_Check(sys_stream)) { 344 PyFile_Check(sys_stream)) {
345 if (!PyFile_SetEncodingAndErrors(sys_stream, codeset, errors)) 345 if (!PyFile_SetEncodingAndErrors(sys_stream, codeset, errors))
346 Py_FatalError("Cannot set codeset of stdout"); 346 Py_FatalError("Cannot set codeset of stdout");
347 } 347 }
349 349
350 sys_stream = PySys_GetObject("stderr"); 350 sys_stream = PySys_GetObject("stderr");
351 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); 351 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", "");
352 if (!sys_isatty) 352 if (!sys_isatty)
353 PyErr_Clear(); 353 PyErr_Clear();
354 if((overridden || 354 if((overridden ||
355 (sys_isatty && PyObject_IsTrue(sys_isatty))) && 355 (sys_isatty && PyObject_IsTrue(sys_isatty))) &&
356 PyFile_Check(sys_stream)) { 356 PyFile_Check(sys_stream)) {
357 if (!PyFile_SetEncodingAndErrors(sys_stream, codeset, errors)) 357 if (!PyFile_SetEncodingAndErrors(sys_stream, codeset, errors))
358 Py_FatalError("Cannot set codeset of stderr"); 358 Py_FatalError("Cannot set codeset of stderr");
359 } 359 }
699 if (PyDict_GetItemString(d, "__builtins__") == NULL) { 699 if (PyDict_GetItemString(d, "__builtins__") == NULL) {
700 PyObject *bimod = PyImport_ImportModule("__builtin__"); 700 PyObject *bimod = PyImport_ImportModule("__builtin__");
701 if (bimod == NULL || 701 if (bimod == NULL ||
702 PyDict_SetItemString(d, "__builtins__", bimod) != 0) 702 PyDict_SetItemString(d, "__builtins__", bimod) != 0)
703 Py_FatalError("can't add __builtins__ to __main__"); 703 Py_FatalError("can't add __builtins__ to __main__");
704 Py_DECREF(bimod); 704 Py_XDECREF(bimod);
705 } 705 }
706 } 706 }
707 707
708 /* Import the site module (not into __main__ though) */ 708 /* Import the site module (not into __main__ though) */
709 709
1295 PyObject *ret = NULL; 1295 PyObject *ret = NULL;
1296 mod_ty mod; 1296 mod_ty mod;
1297 PyArena *arena = PyArena_New(); 1297 PyArena *arena = PyArena_New();
1298 if (arena == NULL) 1298 if (arena == NULL)
1299 return NULL; 1299 return NULL;
1300 1300
1301 mod = PyParser_ASTFromString(str, "<string>", start, flags, arena); 1301 mod = PyParser_ASTFromString(str, "<string>", start, flags, arena);
1302 if (mod != NULL) 1302 if (mod != NULL)
1303 ret = run_mod(mod, "<string>", globals, locals, flags, arena); 1303 ret = run_mod(mod, "<string>", globals, locals, flags, arena);
1304 PyArena_Free(arena); 1304 PyArena_Free(arena);
1305 return ret; 1305 return ret;
1312 PyObject *ret; 1312 PyObject *ret;
1313 mod_ty mod; 1313 mod_ty mod;
1314 PyArena *arena = PyArena_New(); 1314 PyArena *arena = PyArena_New();
1315 if (arena == NULL) 1315 if (arena == NULL)
1316 return NULL; 1316 return NULL;
1317 1317
1318 mod = PyParser_ASTFromFile(fp, filename, start, 0, 0, 1318 mod = PyParser_ASTFromFile(fp, filename, start, 0, 0,
1319 flags, NULL, arena); 1319 flags, NULL, arena);
1320 if (closeit) 1320 if (closeit)
1321 fclose(fp); 1321 fclose(fp);
1322 if (mod == NULL) { 1322 if (mod == NULL) {
1802 /* alloca throws a stack overflow exception if there's 1802 /* alloca throws a stack overflow exception if there's
1803 not enough space left on the stack */ 1803 not enough space left on the stack */
1804 alloca(PYOS_STACK_MARGIN * sizeof(void*)); 1804 alloca(PYOS_STACK_MARGIN * sizeof(void*));
1805 return 0; 1805 return 0;
1806 } __except (GetExceptionCode() == STATUS_STACK_OVERFLOW ? 1806 } __except (GetExceptionCode() == STATUS_STACK_OVERFLOW ?
1807 EXCEPTION_EXECUTE_HANDLER : 1807 EXCEPTION_EXECUTE_HANDLER :
1808 EXCEPTION_CONTINUE_SEARCH) { 1808 EXCEPTION_CONTINUE_SEARCH) {
1809 int errcode = _resetstkoflw(); 1809 int errcode = _resetstkoflw();
1810 if (errcode == 0) 1810 if (errcode == 0)
1811 { 1811 {
1812 Py_FatalError("Could not reset the stack!"); 1812 Py_FatalError("Could not reset the stack!");