From 6caea370ac3e79e8295e456b566a04817eefb0fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Tue, 18 Nov 2003 19:46:25 +0000 Subject: [PATCH] Patch #794400: Let PYTHONSTARTUP influence the compiler flags. --- Misc/NEWS | 2 ++ Modules/main.c | 23 ++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index 444231e26ae..ecc242ab7dc 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,8 @@ What's New in Python 2.4 alpha 1? Core and builtins ----------------- +- Compiler flags set in PYTHONSTARTUP are now active in __main__. + - Added two builtin types, set() and frozenset(). - Critical bugfix, for SF bug 840829: if cyclic garbage collection diff --git a/Modules/main.c b/Modules/main.c index 2cb2b64465e..91818e0df74 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -117,6 +117,19 @@ usage(int exitcode, char* program) /*NOTREACHED*/ } +static void RunStartupFile(PyCompilerFlags *cf) +{ + char *startup = Py_GETENV("PYTHONSTARTUP"); + if (startup != NULL && startup[0] != '\0') { + FILE *fp = fopen(startup, "r"); + if (fp != NULL) { + (void) PyRun_SimpleFileExFlags(fp, startup, 0, cf); + PyErr_Clear(); + fclose(fp); + } + } +} + /* Main program */ @@ -401,15 +414,7 @@ Py_Main(int argc, char **argv) } else { if (filename == NULL && stdin_is_interactive) { - char *startup = Py_GETENV("PYTHONSTARTUP"); - if (startup != NULL && startup[0] != '\0') { - FILE *fp = fopen(startup, "r"); - if (fp != NULL) { - (void) PyRun_SimpleFile(fp, startup); - PyErr_Clear(); - fclose(fp); - } - } + RunStartupFile(&cf); } /* XXX */ sts = PyRun_AnyFileExFlags(