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

Skip to content

Commit 6caea37

Browse files
committed
Patch #794400: Let PYTHONSTARTUP influence the compiler flags.
1 parent b61982b commit 6caea37

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ What's New in Python 2.4 alpha 1?
1212
Core and builtins
1313
-----------------
1414

15+
- Compiler flags set in PYTHONSTARTUP are now active in __main__.
16+
1517
- Added two builtin types, set() and frozenset().
1618

1719
- Critical bugfix, for SF bug 840829: if cyclic garbage collection

Modules/main.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,19 @@ usage(int exitcode, char* program)
117117
/*NOTREACHED*/
118118
}
119119

120+
static void RunStartupFile(PyCompilerFlags *cf)
121+
{
122+
char *startup = Py_GETENV("PYTHONSTARTUP");
123+
if (startup != NULL && startup[0] != '\0') {
124+
FILE *fp = fopen(startup, "r");
125+
if (fp != NULL) {
126+
(void) PyRun_SimpleFileExFlags(fp, startup, 0, cf);
127+
PyErr_Clear();
128+
fclose(fp);
129+
}
130+
}
131+
}
132+
120133

121134
/* Main program */
122135

@@ -401,15 +414,7 @@ Py_Main(int argc, char **argv)
401414
}
402415
else {
403416
if (filename == NULL && stdin_is_interactive) {
404-
char *startup = Py_GETENV("PYTHONSTARTUP");
405-
if (startup != NULL && startup[0] != '\0') {
406-
FILE *fp = fopen(startup, "r");
407-
if (fp != NULL) {
408-
(void) PyRun_SimpleFile(fp, startup);
409-
PyErr_Clear();
410-
fclose(fp);
411-
}
412-
}
417+
RunStartupFile(&cf);
413418
}
414419
/* XXX */
415420
sts = PyRun_AnyFileExFlags(

0 commit comments

Comments
 (0)