Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 5850:6f67a1bda15a legacy-trunk
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().
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Sat, 19 Jul 1997 19:17:22 +0000 |
| parents | 5ed3a21cc122 |
| children | 8d2194e22e67 |
comparison
equal
deleted
inserted
replaced
| 5849:0d7851b37ad2 | 5850:6f67a1bda15a |
|---|---|
| 71 static void err_input Py_PROTO((perrdetail *)); | 71 static void err_input Py_PROTO((perrdetail *)); |
| 72 static void initsigs Py_PROTO((void)); | 72 static void initsigs Py_PROTO((void)); |
| 73 | 73 |
| 74 int Py_DebugFlag; /* Needed by parser.c */ | 74 int Py_DebugFlag; /* Needed by parser.c */ |
| 75 int Py_VerboseFlag; /* Needed by import.c */ | 75 int Py_VerboseFlag; /* Needed by import.c */ |
| 76 int Py_SuppressPrintingFlag; /* Needed by ceval.c */ | |
| 77 int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */ | 76 int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */ |
| 78 | 77 |
| 79 /* Initialize the current interpreter; pass in the Python path. */ | 78 /* Initialize the current interpreter; pass in the Python path. */ |
| 80 | 79 |
| 81 void | 80 void |
| 105 void | 104 void |
| 106 Py_Initialize() | 105 Py_Initialize() |
| 107 { | 106 { |
| 108 PyThreadState *tstate; | 107 PyThreadState *tstate; |
| 109 PyInterpreterState *interp; | 108 PyInterpreterState *interp; |
| 109 char *p; | |
| 110 | |
| 110 if (PyThreadState_Get()) | 111 if (PyThreadState_Get()) |
| 111 return; | 112 return; |
| 113 | |
| 114 if ((p = getenv("PYTHONDEBUG")) && *p != '\0') | |
| 115 Py_DebugFlag = 1; | |
| 116 if ((p = getenv("PYTHONVERBOSE")) && *p != '\0') | |
| 117 Py_VerboseFlag = 1; | |
| 118 | |
| 112 interp = PyInterpreterState_New(); | 119 interp = PyInterpreterState_New(); |
| 113 if (interp == NULL) | 120 if (interp == NULL) |
| 114 Py_FatalError("PyInterpreterState_New() failed"); | 121 Py_FatalError("PyInterpreterState_New() failed"); |
| 122 | |
| 115 tstate = PyThreadState_New(interp); | 123 tstate = PyThreadState_New(interp); |
| 116 if (tstate == NULL) | 124 if (tstate == NULL) |
| 117 Py_FatalError("PyThreadState_New() failed"); | 125 Py_FatalError("PyThreadState_New() failed"); |
| 118 (void) PyThreadState_Swap(tstate); | 126 (void) PyThreadState_Swap(tstate); |
| 119 | 127 |
| 120 Py_Setup(); | 128 Py_Setup(); |
| 121 | 129 |
| 122 PySys_SetPath(Py_GetPath()); | 130 PySys_SetPath(Py_GetPath()); |
| 131 /* XXX Who should set the path -- Setup or Initialize? */ | |
| 132 } | |
| 133 | |
| 134 static char *progname = "python"; | |
| 135 | |
| 136 void | |
| 137 Py_SetProgramName(pn) | |
| 138 char *pn; | |
| 139 { | |
| 140 if (pn && *pn) | |
| 141 progname = pn; | |
| 142 } | |
| 143 | |
| 144 char * | |
| 145 Py_GetProgramName() | |
| 146 { | |
| 147 return progname; | |
| 123 } | 148 } |
| 124 | 149 |
| 125 /* | 150 /* |
| 126 Py_Initialize() | 151 Py_Initialize() |
| 127 -- do everything, no-op on second call, call fatal on failure, set path | 152 -- do everything, no-op on second call, call fatal on failure, set path |
