comparison Python/pythonrun.c @ 43777:0d462d789b18

Merging the py3k-pep3137 branch back into the py3k branch. No detailed change log; just check out the change log for the py3k-pep3137 branch. The most obvious changes: - str8 renamed to bytes (PyString at the C level); - bytes renamed to buffer (PyBytes at the C level); - PyString and PyUnicode are no longer compatible. I.e. we now have an immutable bytes type and a mutable bytes type. The behavior of PyString was modified quite a bit, to make it more bytes-like. Some changes are still on the to-do list.
author Guido van Rossum <guido@python.org>
date Tue, 06 Nov 2007 21:34:58 +0000
parents e510b716bd80
children ccceaec11442
comparison
equal deleted inserted replaced
43776:b310fd2b0184 43777:0d462d789b18
73 int Py_DebugFlag; /* Needed by parser.c */ 73 int Py_DebugFlag; /* Needed by parser.c */
74 int Py_VerboseFlag; /* Needed by import.c */ 74 int Py_VerboseFlag; /* Needed by import.c */
75 int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */ 75 int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */
76 int Py_InspectFlag; /* Needed to determine whether to exit at SystemError */ 76 int Py_InspectFlag; /* Needed to determine whether to exit at SystemError */
77 int Py_NoSiteFlag; /* Suppress 'import site' */ 77 int Py_NoSiteFlag; /* Suppress 'import site' */
78 int Py_BytesWarningFlag; /* Warn on str(bytes) and str(buffer) */
78 int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */ 79 int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */
79 int Py_FrozenFlag; /* Needed by getpath.c */ 80 int Py_FrozenFlag; /* Needed by getpath.c */
80 int Py_IgnoreEnvironmentFlag; /* e.g. PYTHONPATH, PYTHONHOME */ 81 int Py_IgnoreEnvironmentFlag; /* e.g. PYTHONPATH, PYTHONHOME */
81 82
82 /* Reference to 'warnings' module, to avoid importing it 83 /* Reference to 'warnings' module, to avoid importing it
232 infrastructure for the io module in place. */ 233 infrastructure for the io module in place. */
233 pstderr = PyFile_NewStdPrinter(fileno(stderr)); 234 pstderr = PyFile_NewStdPrinter(fileno(stderr));
234 if (pstderr == NULL) 235 if (pstderr == NULL)
235 Py_FatalError("Py_Initialize: can't set preliminary stderr"); 236 Py_FatalError("Py_Initialize: can't set preliminary stderr");
236 PySys_SetObject("stderr", pstderr); 237 PySys_SetObject("stderr", pstderr);
238 PySys_SetObject("__stderr__", pstderr);
237 239
238 _PyImport_Init(); 240 _PyImport_Init();
239 241
240 /* initialize builtin exceptions */ 242 /* initialize builtin exceptions */
241 _PyExc_Init(); 243 _PyExc_Init();
259 #ifdef WITH_THREAD 261 #ifdef WITH_THREAD
260 _PyGILState_Init(interp, tstate); 262 _PyGILState_Init(interp, tstate);
261 #endif /* WITH_THREAD */ 263 #endif /* WITH_THREAD */
262 264
263 warnings_module = PyImport_ImportModule("warnings"); 265 warnings_module = PyImport_ImportModule("warnings");
264 if (!warnings_module) 266 if (!warnings_module) {
265 PyErr_Clear(); 267 PyErr_Clear();
268 }
269 else {
270 PyObject *o;
271 char *action[8];
272
273 if (Py_BytesWarningFlag > 1)
274 *action = "error";
275 else if (Py_BytesWarningFlag)
276 *action = "default";
277 else
278 *action = "ignore";
279
280 o = PyObject_CallMethod(warnings_module,
281 "simplefilter", "sO",
282 *action, PyExc_BytesWarning);
283 if (o == NULL)
284 Py_FatalError("Py_Initialize: can't initialize"
285 "warning filter for BytesWarning.");
286 Py_DECREF(o);
287 }
266 288
267 #if defined(HAVE_LANGINFO_H) && defined(CODESET) 289 #if defined(HAVE_LANGINFO_H) && defined(CODESET)
268 /* On Unix, set the file system encoding according to the 290 /* On Unix, set the file system encoding according to the
269 user's preference, if the CODESET names a well-known 291 user's preference, if the CODESET names a well-known
270 Python codec, and Py_FileSystemDefaultEncoding isn't 292 Python codec, and Py_FileSystemDefaultEncoding isn't
741 } 763 }
742 PySys_SetObject("__stdout__", std); 764 PySys_SetObject("__stdout__", std);
743 PySys_SetObject("stdout", std); 765 PySys_SetObject("stdout", std);
744 Py_DECREF(std); 766 Py_DECREF(std);
745 767
768 #if 1 /* Disable this if you have trouble debugging bootstrap stuff */
746 /* Set sys.stderr, replaces the preliminary stderr */ 769 /* Set sys.stderr, replaces the preliminary stderr */
747 if (!(std = PyFile_FromFd(fileno(stderr), "<stderr>", "w", -1, 770 if (!(std = PyFile_FromFd(fileno(stderr), "<stderr>", "w", -1,
748 NULL, "\n", 0))) { 771 NULL, "\n", 0))) {
749 goto error; 772 goto error;
750 } 773 }
751 PySys_SetObject("__stderr__", std); 774 PySys_SetObject("__stderr__", std);
752 PySys_SetObject("stderr", std); 775 PySys_SetObject("stderr", std);
753 Py_DECREF(std); 776 Py_DECREF(std);
777 #endif
754 778
755 if (0) { 779 if (0) {
756 error: 780 error:
757 status = -1; 781 status = -1;
758 } 782 }
1337 PyObject *ret = NULL; 1361 PyObject *ret = NULL;
1338 mod_ty mod; 1362 mod_ty mod;
1339 PyArena *arena = PyArena_New(); 1363 PyArena *arena = PyArena_New();
1340 if (arena == NULL) 1364 if (arena == NULL)
1341 return NULL; 1365 return NULL;
1342 1366
1343 mod = PyParser_ASTFromString(str, "<string>", start, flags, arena); 1367 mod = PyParser_ASTFromString(str, "<string>", start, flags, arena);
1344 if (mod != NULL) 1368 if (mod != NULL)
1345 ret = run_mod(mod, "<string>", globals, locals, flags, arena); 1369 ret = run_mod(mod, "<string>", globals, locals, flags, arena);
1346 PyArena_Free(arena); 1370 PyArena_Free(arena);
1347 return ret; 1371 return ret;
1354 PyObject *ret; 1378 PyObject *ret;
1355 mod_ty mod; 1379 mod_ty mod;
1356 PyArena *arena = PyArena_New(); 1380 PyArena *arena = PyArena_New();
1357 if (arena == NULL) 1381 if (arena == NULL)
1358 return NULL; 1382 return NULL;
1359 1383
1360 mod = PyParser_ASTFromFile(fp, filename, NULL, start, 0, 0, 1384 mod = PyParser_ASTFromFile(fp, filename, NULL, start, 0, 0,
1361 flags, NULL, arena); 1385 flags, NULL, arena);
1362 if (closeit) 1386 if (closeit)
1363 fclose(fp); 1387 fclose(fp);
1364 if (mod == NULL) { 1388 if (mod == NULL) {
1703 } 1727 }
1704 1728
1705 static void 1729 static void
1706 call_py_exitfuncs(void) 1730 call_py_exitfuncs(void)
1707 { 1731 {
1708 if (pyexitfunc == NULL) 1732 if (pyexitfunc == NULL)
1709 return; 1733 return;
1710 1734
1711 (*pyexitfunc)(); 1735 (*pyexitfunc)();
1712 PyErr_Clear(); 1736 PyErr_Clear();
1713 } 1737 }