mirror of
https://github.com/python/cpython.git
synced 2025-10-22 06:32:43 +00:00
Moved some stuff here from main.c (part of a big restructuring - wait
for more!). - The global flags that can be set from environment variables are now set in Py_Initialize (except the silly Py_SuppressPrint, which no longer exists). This saves duplicate code in frozenmain.c and main.c. - Py_GetProgramName() is now here; added Py_SetProgramName(). An embedding program should no longer provide Py_GetProgramName(), instead it should call Py_SetProgramName() *before* calling Py_Initialize().
This commit is contained in:
parent
0c88e1fd96
commit
ad6dfda9af
1 changed files with 26 additions and 1 deletions
|
@ -73,7 +73,6 @@ static void initsigs Py_PROTO((void));
|
||||||
|
|
||||||
int Py_DebugFlag; /* Needed by parser.c */
|
int Py_DebugFlag; /* Needed by parser.c */
|
||||||
int Py_VerboseFlag; /* Needed by import.c */
|
int Py_VerboseFlag; /* Needed by import.c */
|
||||||
int Py_SuppressPrintingFlag; /* Needed by ceval.c */
|
|
||||||
int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */
|
int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */
|
||||||
|
|
||||||
/* Initialize the current interpreter; pass in the Python path. */
|
/* Initialize the current interpreter; pass in the Python path. */
|
||||||
|
@ -107,11 +106,20 @@ Py_Initialize()
|
||||||
{
|
{
|
||||||
PyThreadState *tstate;
|
PyThreadState *tstate;
|
||||||
PyInterpreterState *interp;
|
PyInterpreterState *interp;
|
||||||
|
char *p;
|
||||||
|
|
||||||
if (PyThreadState_Get())
|
if (PyThreadState_Get())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if ((p = getenv("PYTHONDEBUG")) && *p != '\0')
|
||||||
|
Py_DebugFlag = 1;
|
||||||
|
if ((p = getenv("PYTHONVERBOSE")) && *p != '\0')
|
||||||
|
Py_VerboseFlag = 1;
|
||||||
|
|
||||||
interp = PyInterpreterState_New();
|
interp = PyInterpreterState_New();
|
||||||
if (interp == NULL)
|
if (interp == NULL)
|
||||||
Py_FatalError("PyInterpreterState_New() failed");
|
Py_FatalError("PyInterpreterState_New() failed");
|
||||||
|
|
||||||
tstate = PyThreadState_New(interp);
|
tstate = PyThreadState_New(interp);
|
||||||
if (tstate == NULL)
|
if (tstate == NULL)
|
||||||
Py_FatalError("PyThreadState_New() failed");
|
Py_FatalError("PyThreadState_New() failed");
|
||||||
|
@ -120,6 +128,23 @@ Py_Initialize()
|
||||||
Py_Setup();
|
Py_Setup();
|
||||||
|
|
||||||
PySys_SetPath(Py_GetPath());
|
PySys_SetPath(Py_GetPath());
|
||||||
|
/* XXX Who should set the path -- Setup or Initialize? */
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *progname = "python";
|
||||||
|
|
||||||
|
void
|
||||||
|
Py_SetProgramName(pn)
|
||||||
|
char *pn;
|
||||||
|
{
|
||||||
|
if (pn && *pn)
|
||||||
|
progname = pn;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
Py_GetProgramName()
|
||||||
|
{
|
||||||
|
return progname;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue