Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a61691e

Browse files
committed
Ehm, three unrelated changes.
- Add Py_FrozenFlag, intended to suppress error messages fron getpath.c in frozen binaries. - Add Py_GetPythonHome() and Py_SetPythonHome(), intended to allow embedders to force a different PYTHONHOME. - Add new interface PyErr_PrintEx(flag); same as PyErr_Print() but flag determines whether sys.last_* are set or not. PyErr_Print() now simply calls PyErr_PrintEx(1).
1 parent 31c4ed7 commit a61691e

1 file changed

Lines changed: 31 additions & 3 deletions

File tree

Python/pythonrun.c

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ int Py_VerboseFlag; /* Needed by import.c */
7777
int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */
7878
int Py_NoSiteFlag; /* Suppress 'import site' */
7979
int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c */
80+
int Py_FrozenFlag; /* Needed by getpath.c */
8081

8182
static int initialized = 0;
8283

@@ -367,6 +368,24 @@ Py_GetProgramName()
367368
return progname;
368369
}
369370

371+
static char *default_home = NULL;
372+
373+
void
374+
Py_SetPythonHome(home)
375+
char *home;
376+
{
377+
default_home = home;
378+
}
379+
380+
char *
381+
Py_GetPythonHome()
382+
{
383+
char *home = default_home;
384+
if (home == NULL)
385+
home = getenv("PYTHONHOME");
386+
return home;
387+
}
388+
370389
/* Create __main__ module */
371390

372391
static void
@@ -640,6 +659,13 @@ parse_syntax_error(err, message, filename, lineno, offset, text)
640659

641660
void
642661
PyErr_Print()
662+
{
663+
PyErr_PrintEx(1);
664+
}
665+
666+
void
667+
PyErr_PrintEx(set_sys_last_vars)
668+
int set_sys_last_vars;
643669
{
644670
int err = 0;
645671
PyObject *exception, *v, *tb, *f;
@@ -679,9 +705,11 @@ PyErr_Print()
679705
Py_Exit(1);
680706
}
681707
}
682-
PySys_SetObject("last_type", exception);
683-
PySys_SetObject("last_value", v);
684-
PySys_SetObject("last_traceback", tb);
708+
if (set_sys_last_vars) {
709+
PySys_SetObject("last_type", exception);
710+
PySys_SetObject("last_value", v);
711+
PySys_SetObject("last_traceback", tb);
712+
}
685713
f = PySys_GetObject("stderr");
686714
if (f == NULL)
687715
fprintf(stderr, "lost sys.stderr\n");

0 commit comments

Comments
 (0)