summaryrefslogtreecommitdiff
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index ec9ed02ab9..0b3935ab69 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -75,6 +75,7 @@ int Py_VerboseFlag; /* Needed by import.c */
int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */
int Py_InspectFlag; /* Needed to determine whether to exit at SystemError */
int Py_NoSiteFlag; /* Suppress 'import site' */
+int Py_BytesWarningFlag; /* Warn on str(bytes) and str(buffer) */
int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */
int Py_FrozenFlag; /* Needed by getpath.c */
int Py_IgnoreEnvironmentFlag; /* e.g. PYTHONPATH, PYTHONHOME */
@@ -234,6 +235,7 @@ Py_InitializeEx(int install_sigs)
if (pstderr == NULL)
Py_FatalError("Py_Initialize: can't set preliminary stderr");
PySys_SetObject("stderr", pstderr);
+ PySys_SetObject("__stderr__", pstderr);
_PyImport_Init();
@@ -261,8 +263,28 @@ Py_InitializeEx(int install_sigs)
#endif /* WITH_THREAD */
warnings_module = PyImport_ImportModule("warnings");
- if (!warnings_module)
+ if (!warnings_module) {
PyErr_Clear();
+ }
+ else {
+ PyObject *o;
+ char *action[8];
+
+ if (Py_BytesWarningFlag > 1)
+ *action = "error";
+ else if (Py_BytesWarningFlag)
+ *action = "default";
+ else
+ *action = "ignore";
+
+ o = PyObject_CallMethod(warnings_module,
+ "simplefilter", "sO",
+ *action, PyExc_BytesWarning);
+ if (o == NULL)
+ Py_FatalError("Py_Initialize: can't initialize"
+ "warning filter for BytesWarning.");
+ Py_DECREF(o);
+ }
#if defined(HAVE_LANGINFO_H) && defined(CODESET)
/* On Unix, set the file system encoding according to the
@@ -743,6 +765,7 @@ initstdio(void)
PySys_SetObject("stdout", std);
Py_DECREF(std);
+#if 1 /* Disable this if you have trouble debugging bootstrap stuff */
/* Set sys.stderr, replaces the preliminary stderr */
if (!(std = PyFile_FromFd(fileno(stderr), "<stderr>", "w", -1,
NULL, "\n", 0))) {
@@ -751,6 +774,7 @@ initstdio(void)
PySys_SetObject("__stderr__", std);
PySys_SetObject("stderr", std);
Py_DECREF(std);
+#endif
if (0) {
error:
@@ -1339,7 +1363,7 @@ PyRun_StringFlags(const char *str, int start, PyObject *globals,
PyArena *arena = PyArena_New();
if (arena == NULL)
return NULL;
-
+
mod = PyParser_ASTFromString(str, "<string>", start, flags, arena);
if (mod != NULL)
ret = run_mod(mod, "<string>", globals, locals, flags, arena);
@@ -1356,7 +1380,7 @@ PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals,
PyArena *arena = PyArena_New();
if (arena == NULL)
return NULL;
-
+
mod = PyParser_ASTFromFile(fp, filename, NULL, start, 0, 0,
flags, NULL, arena);
if (closeit)
@@ -1705,7 +1729,7 @@ void _Py_PyAtExit(void (*func)(void))
static void
call_py_exitfuncs(void)
{
- if (pyexitfunc == NULL)
+ if (pyexitfunc == NULL)
return;
(*pyexitfunc)();