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

Skip to content

Commit ed52aac

Browse files
committed
This is no longer the real main program; it now defines Py_Main(), so
it can be placed in the library. Other, related changes: - Moved the inspection of some environment variables to Py_Initialize(). - Got rid of -s option. - Moved Py_GetProgramName() and related logic to pythonrun.c; call Py_SetProgramName() instead. - Print the version header *after* successful initialization.
1 parent ad6dfda commit ed52aac

1 file changed

Lines changed: 7 additions & 30 deletions

File tree

Modules/main.c

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ extern char *Py_GetPlatform();
5353
extern char *Py_GetCopyright();
5454

5555

56-
/* For Py_GetProgramName(); set by main() */
57-
static char *argv0;
58-
5956
/* For Py_GetArgcArgv(); set by main() */
6057
static char **orig_argv;
6158
static int orig_argc;
@@ -71,8 +68,7 @@ Options and arguments (and corresponding environment variables):\n\
7168
-i : inspect interactively after running script, (also PYTHONINSPECT=x)\n\
7269
and force prompts, even if stdin does not appear to be a terminal.\n\
7370
-O : optimize generated bytecode (a tad).\n\
74-
-s : suppress printing of top level expressions (also PYTHONSUPPRESS=x)\n\
75-
-u : unbuffered stdout and stderr (also PYTHONUNBUFFERED=x)\n\
71+
-u : unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x)\n\
7672
-v : verbose (trace import statements) (also PYTHONVERBOSE=x)\n\
7773
";
7874
static char *usage_bot = "\
@@ -93,7 +89,7 @@ PYTHONHOME : alternate <prefix> directory (or <prefix>:<exec_prefix>).\n\
9389
/* Main program */
9490

9591
int
96-
main(argc, argv)
92+
Py_Main(argc, argv)
9793
int argc;
9894
char **argv;
9995
{
@@ -109,20 +105,13 @@ main(argc, argv)
109105

110106
orig_argc = argc; /* For Py_GetArgcArgv() */
111107
orig_argv = argv;
112-
argv0 = argv[0]; /* For Py_GetProgramName() */
113-
114-
if ((p = getenv("PYTHONDEBUG")) && *p != '\0')
115-
Py_DebugFlag = 1;
116-
if ((p = getenv("PYTHONSUPPRESS")) && *p != '\0')
117-
Py_SuppressPrintingFlag = 1;
118-
if ((p = getenv("PYTHONVERBOSE")) && *p != '\0')
119-
Py_VerboseFlag = 1;
108+
120109
if ((p = getenv("PYTHONINSPECT")) && *p != '\0')
121110
inspect = 1;
122111
if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0')
123112
unbuffered = 1;
124113

125-
while ((c = getopt(argc, argv, "c:diOsuv")) != EOF) {
114+
while ((c = getopt(argc, argv, "c:diOuv")) != EOF) {
126115
if (c == 'c') {
127116
/* -c is the last option; following arguments
128117
that look like options are left for the
@@ -151,10 +140,6 @@ main(argc, argv)
151140
Py_OptimizeFlag++;
152141
break;
153142

154-
case 's':
155-
Py_SuppressPrintingFlag++;
156-
break;
157-
158143
case 'u':
159144
unbuffered++;
160145
break;
@@ -218,12 +203,14 @@ main(argc, argv)
218203
/* Leave stderr alone - it should be unbuffered anyway. */
219204
}
220205

206+
Py_SetProgramName(argv[0]);
207+
Py_Initialize();
208+
221209
if (Py_VerboseFlag ||
222210
(command == NULL && filename == NULL && stdin_is_interactive))
223211
fprintf(stderr, "Python %s on %s\n%s\n",
224212
Py_GetVersion(), Py_GetPlatform(), Py_GetCopyright());
225213

226-
Py_Initialize();
227214

228215
if (command != NULL) {
229216
/* Backup optind and force sys.argv[0] = '-c' */
@@ -264,16 +251,6 @@ main(argc, argv)
264251
}
265252

266253

267-
/* Return the program name -- some code out there needs this
268-
(currently _tkinter.c and importdl.c). */
269-
270-
char *
271-
Py_GetProgramName()
272-
{
273-
return argv0;
274-
}
275-
276-
277254
/* Make the *original* argc/argv available to other modules.
278255
This is rare, but it is needed by the secureware extension. */
279256

0 commit comments

Comments
 (0)