]> git.proxmox.com Git - mirror_edk2.git/commitdiff
AppPkg: Add switch to cause stderr to be aliased to stdout.
authorDaryl McDaniel <edk2-lists@mc2research.org>
Mon, 19 Oct 2015 21:39:46 +0000 (21:39 +0000)
committerdarylm503 <darylm503@Edk2>
Mon, 19 Oct 2015 21:39:46 +0000 (21:39 +0000)
Python, as distributed, sends its prompts and other interactive output
to stderr, which uses the platforms STDERR device for output.  If STDERR output
is not visible, it may appear that Python has hung.  Several people have
reported problems on platforms that don't enable STDERR.  These include
platforms without a Setup utility and those without Setup options for STDERR.

This patch adds a command-line switch, -#, to Python.  If this switch
is present, stderr will be aliased to stdout.

AppPkg/Applications/Python/PyMod-2.7.2/Modules/main.c:  New file, modified
version of AppPkg/Applications/Python/Python-2.7.2/Modules/main.c.  Add the -#
option which causes stderr to be aliased to stdout.  Add a description of this
switch to the Help output.

AppPkg/Applications/Python/PythonCore.inf:  Reference main.c from PyMod-2.7.2
instead of from Python-2.7.2 so that the modified version is used.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Daryl McDaniel <edk2-lists@mc2research.org>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18649 6f19259b-4bc3-4df7-8a09-765794883524

AppPkg/Applications/Python/PyMod-2.7.2/Modules/main.c [new file with mode: 0644]
AppPkg/Applications/Python/PythonCore.inf

diff --git a/AppPkg/Applications/Python/PyMod-2.7.2/Modules/main.c b/AppPkg/Applications/Python/PyMod-2.7.2/Modules/main.c
new file mode 100644 (file)
index 0000000..4b3ce11
--- /dev/null
@@ -0,0 +1,678 @@
+/** @file\r
+  Python interpreter main program.\r
+\r
+  Copyright (c) 2015, Daryl McDaniel. All rights reserved.<BR>\r
+**/\r
+\r
+#include "Python.h"\r
+#include "osdefs.h"\r
+#include "code.h" /* For CO_FUTURE_DIVISION */\r
+#include "import.h"\r
+\r
+#ifdef __VMS\r
+#include <unixlib.h>\r
+#endif\r
+\r
+#if defined(MS_WINDOWS) || defined(__CYGWIN__)\r
+#ifdef HAVE_FCNTL_H\r
+#include <fcntl.h>\r
+#endif\r
+#endif\r
+\r
+#if (defined(PYOS_OS2) && !defined(PYCC_GCC)) || defined(MS_WINDOWS)\r
+#define PYTHONHOMEHELP "<prefix>\\lib"\r
+#else\r
+#if defined(PYOS_OS2) && defined(PYCC_GCC)\r
+#define PYTHONHOMEHELP "<prefix>/Lib"\r
+#else\r
+#define PYTHONHOMEHELP "<prefix>/pythonX.X"\r
+#endif\r
+#endif\r
+\r
+#include "pygetopt.h"\r
+\r
+#define COPYRIGHT \\r
+    "Type \"help\", \"copyright\", \"credits\" or \"license\" " \\r
+    "for more information."\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/* For Py_GetArgcArgv(); set by main() */\r
+static char **orig_argv;\r
+static int  orig_argc;\r
+\r
+/* command line options */\r
+#define BASE_OPTS "#3bBc:dEhiJm:OQ:sStuUvVW:xX?"\r
+\r
+#ifndef RISCOS\r
+#define PROGRAM_OPTS BASE_OPTS\r
+#else /*RISCOS*/\r
+/* extra option saying that we are running under a special task window\r
+   frontend; especially my_readline will behave different */\r
+#define PROGRAM_OPTS BASE_OPTS "w"\r
+/* corresponding flag */\r
+extern int Py_RISCOSWimpFlag;\r
+#endif /*RISCOS*/\r
+\r
+/* Short usage message (with %s for argv0) */\r
+static char *usage_line =\r
+"usage: %s [option] ... [-c cmd | -m mod | file | -] [arg] ...\n";\r
+\r
+/* Long usage message, split into parts < 512 bytes */\r
+static char *usage_1 = "\\r
+Options and arguments (and corresponding environment variables):\n\\r
+-#     : alias stderr to stdout for platforms without STDERR output.\n\\r
+-B     : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x\n\\r
+-c cmd : program passed in as string (terminates option list)\n\\r
+-d     : debug output from parser; also PYTHONDEBUG=x\n\\r
+-E     : ignore PYTHON* environment variables (such as PYTHONPATH)\n\\r
+-h     : print this help message and exit (also --help)\n\\r
+-i     : inspect interactively after running script; forces a prompt even\n\\r
+";\r
+static char *usage_2 = "\\r
+         if stdin does not appear to be a terminal; also PYTHONINSPECT=x\n\\r
+-m mod : run library module as a script (terminates option list)\n\\r
+-O     : optimize generated bytecode slightly; also PYTHONOPTIMIZE=x\n\\r
+-OO    : remove doc-strings in addition to the -O optimizations\n\\r
+-Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew\n\\r
+-s     : don't add user site directory to sys.path; also PYTHONNOUSERSITE\n\\r
+-S     : don't imply 'import site' on initialization\n\\r
+-t     : issue warnings about inconsistent tab usage (-tt: issue errors)\n\\r
+";\r
+static char *usage_3 = "\\r
+-u     : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x\n\\r
+         see man page for details on internal buffering relating to '-u'\n\\r
+-v     : verbose (trace import statements); also PYTHONVERBOSE=x\n\\r
+         can be supplied multiple times to increase verbosity\n\\r
+-V     : print the Python version number and exit (also --version)\n\\r
+-W arg : warning control; arg is action:message:category:module:lineno\n\\r
+         also PYTHONWARNINGS=arg\n\\r
+-x     : skip first line of source, allowing use of non-Unix forms of #!cmd\n\\r
+";\r
+static char *usage_4 = "\\r
+-3     : warn about Python 3.x incompatibilities that 2to3 cannot trivially fix\n\\r
+file   : program read from script file\n\\r
+-      : program read from stdin (default; interactive mode if a tty)\n\\r
+arg ...: arguments passed to program in sys.argv[1:]\n\n\\r
+Other environment variables:\n\\r
+PYTHONSTARTUP: file executed on interactive startup (no default)\n\\r
+PYTHONPATH   : '%c'-separated list of directories prefixed to the\n\\r
+               default module search path.  The result is sys.path.\n\\r
+";\r
+static char *usage_5 = "\\r
+PYTHONHOME   : alternate <prefix> directory (or <prefix>%c<exec_prefix>).\n\\r
+               The default module search path uses %s.\n\\r
+PYTHONCASEOK : ignore case in 'import' statements (UEFI default).\n\\r
+PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.\n\\r
+";\r
+\r
+\r
+static int\r
+usage(int exitcode, char* program)\r
+{\r
+    FILE *f = exitcode ? stderr : stdout;\r
+\r
+    fprintf(f, usage_line, program);\r
+    if (exitcode)\r
+        fprintf(f, "Try `python -h' for more information.\n");\r
+    else {\r
+        fputs(usage_1, f);\r
+        fputs(usage_2, f);\r
+        fputs(usage_3, f);\r
+        fprintf(f, usage_4, DELIM);\r
+        fprintf(f, usage_5, DELIM, PYTHONHOMEHELP);\r
+    }\r
+#if defined(__VMS)\r
+    if (exitcode == 0) {\r
+        /* suppress 'error' message */\r
+        return 1;\r
+    }\r
+    else {\r
+        /* STS$M_INHIB_MSG + SS$_ABORT */\r
+        return 0x1000002c;\r
+    }\r
+#else\r
+    return exitcode;\r
+#endif\r
+    /*NOTREACHED*/\r
+}\r
+\r
+static void RunStartupFile(PyCompilerFlags *cf)\r
+{\r
+    char *startup = Py_GETENV("PYTHONSTARTUP");\r
+    if (startup != NULL && startup[0] != '\0') {\r
+        FILE *fp = fopen(startup, "r");\r
+        if (fp != NULL) {\r
+            (void) PyRun_SimpleFileExFlags(fp, startup, 0, cf);\r
+            PyErr_Clear();\r
+            fclose(fp);\r
+           } else {\r
+                    int save_errno;\r
+                    save_errno = errno;\r
+                    PySys_WriteStderr("Could not open PYTHONSTARTUP\n");\r
+                    errno = save_errno;\r
+                    PyErr_SetFromErrnoWithFilename(PyExc_IOError,\r
+                                                   startup);\r
+                    PyErr_Print();\r
+                    PyErr_Clear();\r
+        }\r
+    }\r
+}\r
+\r
+\r
+static int RunModule(char *module, int set_argv0)\r
+{\r
+    PyObject *runpy, *runmodule, *runargs, *result;\r
+    runpy = PyImport_ImportModule("runpy");\r
+    if (runpy == NULL) {\r
+        fprintf(stderr, "Could not import runpy module\n");\r
+        return -1;\r
+    }\r
+    runmodule = PyObject_GetAttrString(runpy, "_run_module_as_main");\r
+    if (runmodule == NULL) {\r
+        fprintf(stderr, "Could not access runpy._run_module_as_main\n");\r
+        Py_DECREF(runpy);\r
+        return -1;\r
+    }\r
+    runargs = Py_BuildValue("(si)", module, set_argv0);\r
+    if (runargs == NULL) {\r
+        fprintf(stderr,\r
+            "Could not create arguments for runpy._run_module_as_main\n");\r
+        Py_DECREF(runpy);\r
+        Py_DECREF(runmodule);\r
+        return -1;\r
+    }\r
+    result = PyObject_Call(runmodule, runargs, NULL);\r
+    if (result == NULL) {\r
+        PyErr_Print();\r
+    }\r
+    Py_DECREF(runpy);\r
+    Py_DECREF(runmodule);\r
+    Py_DECREF(runargs);\r
+    if (result == NULL) {\r
+        return -1;\r
+    }\r
+    Py_DECREF(result);\r
+    return 0;\r
+}\r
+\r
+static int RunMainFromImporter(char *filename)\r
+{\r
+    PyObject *argv0 = NULL, *importer = NULL;\r
+\r
+    if ((argv0 = PyString_FromString(filename)) &&\r
+        (importer = PyImport_GetImporter(argv0)) &&\r
+        (importer->ob_type != &PyNullImporter_Type))\r
+    {\r
+             /* argv0 is usable as an import source, so\r
+                    put it in sys.path[0] and import __main__ */\r
+        PyObject *sys_path = NULL;\r
+        if ((sys_path = PySys_GetObject("path")) &&\r
+            !PyList_SetItem(sys_path, 0, argv0))\r
+        {\r
+            Py_INCREF(argv0);\r
+            Py_DECREF(importer);\r
+            sys_path = NULL;\r
+            return RunModule("__main__", 0) != 0;\r
+        }\r
+    }\r
+    Py_XDECREF(argv0);\r
+    Py_XDECREF(importer);\r
+    if (PyErr_Occurred()) {\r
+        PyErr_Print();\r
+        return 1;\r
+    }\r
+    return -1;\r
+}\r
+\r
+\r
+/* Main program */\r
+\r
+int\r
+Py_Main(int argc, char **argv)\r
+{\r
+    int c;\r
+    int sts;\r
+    char *command = NULL;\r
+    char *filename = NULL;\r
+    char *module = NULL;\r
+    FILE *fp = stdin;\r
+    char *p;\r
+    int unbuffered = 0;\r
+    int skipfirstline = 0;\r
+    int stdin_is_interactive = 0;\r
+    int help = 0;\r
+    int version = 0;\r
+    int saw_unbuffered_flag = 0;\r
+    int saw_pound_flag = 0;\r
+    PyCompilerFlags cf;\r
+\r
+    cf.cf_flags = 0;\r
+\r
+    orig_argc = argc;           /* For Py_GetArgcArgv() */\r
+    orig_argv = argv;\r
+\r
+#ifdef RISCOS\r
+    Py_RISCOSWimpFlag = 0;\r
+#endif\r
+\r
+    PySys_ResetWarnOptions();\r
+\r
+    while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) {\r
+        if (c == 'c') {\r
+            /* -c is the last option; following arguments\r
+               that look like options are left for the\r
+               command to interpret. */\r
+            command = (char *)malloc(strlen(_PyOS_optarg) + 2);\r
+            if (command == NULL)\r
+                Py_FatalError(\r
+                   "not enough memory to copy -c argument");\r
+            strcpy(command, _PyOS_optarg);\r
+            strcat(command, "\n");\r
+            break;\r
+        }\r
+\r
+        if (c == 'm') {\r
+            /* -m is the last option; following arguments\r
+               that look like options are left for the\r
+               module to interpret. */\r
+            module = (char *)malloc(strlen(_PyOS_optarg) + 2);\r
+            if (module == NULL)\r
+                Py_FatalError(\r
+                   "not enough memory to copy -m argument");\r
+            strcpy(module, _PyOS_optarg);\r
+            break;\r
+        }\r
+\r
+        switch (c) {\r
+        case 'b':\r
+            Py_BytesWarningFlag++;\r
+            break;\r
+\r
+        case 'd':\r
+            Py_DebugFlag++;\r
+            break;\r
+\r
+        case '3':\r
+            Py_Py3kWarningFlag++;\r
+            if (!Py_DivisionWarningFlag)\r
+                Py_DivisionWarningFlag = 1;\r
+            break;\r
+\r
+        case 'Q':\r
+            if (strcmp(_PyOS_optarg, "old") == 0) {\r
+                Py_DivisionWarningFlag = 0;\r
+                break;\r
+            }\r
+            if (strcmp(_PyOS_optarg, "warn") == 0) {\r
+                Py_DivisionWarningFlag = 1;\r
+                break;\r
+            }\r
+            if (strcmp(_PyOS_optarg, "warnall") == 0) {\r
+                Py_DivisionWarningFlag = 2;\r
+                break;\r
+            }\r
+            if (strcmp(_PyOS_optarg, "new") == 0) {\r
+                /* This only affects __main__ */\r
+                cf.cf_flags |= CO_FUTURE_DIVISION;\r
+                /* And this tells the eval loop to treat\r
+                   BINARY_DIVIDE as BINARY_TRUE_DIVIDE */\r
+                _Py_QnewFlag = 1;\r
+                break;\r
+            }\r
+            fprintf(stderr,\r
+                "-Q option should be `-Qold', "\r
+                "`-Qwarn', `-Qwarnall', or `-Qnew' only\n");\r
+            return usage(2, argv[0]);\r
+            /* NOTREACHED */\r
+\r
+        case 'i':\r
+            Py_InspectFlag++;\r
+            Py_InteractiveFlag++;\r
+            break;\r
+\r
+        /* case 'J': reserved for Jython */\r
+\r
+        case 'O':\r
+            Py_OptimizeFlag++;\r
+            break;\r
+\r
+        case 'B':\r
+            Py_DontWriteBytecodeFlag++;\r
+            break;\r
+\r
+        case 's':\r
+            Py_NoUserSiteDirectory++;\r
+            break;\r
+\r
+        case 'S':\r
+            Py_NoSiteFlag++;\r
+            break;\r
+\r
+        case 'E':\r
+          Py_IgnoreEnvironmentFlag++;\r
+          break;\r
+\r
+        case 't':\r
+            Py_TabcheckFlag++;\r
+            break;\r
+\r
+        case 'u':\r
+            unbuffered++;\r
+            saw_unbuffered_flag = 1;\r
+            break;\r
+\r
+        case 'v':\r
+            Py_VerboseFlag++;\r
+            break;\r
+\r
+#ifdef RISCOS\r
+        case 'w':\r
+            Py_RISCOSWimpFlag = 1;\r
+            break;\r
+#endif\r
+\r
+        case 'x':\r
+            skipfirstline = 1;\r
+            break;\r
+\r
+        /* case 'X': reserved for implementation-specific arguments */\r
+\r
+        case 'U':\r
+            Py_UnicodeFlag++;\r
+            break;\r
+        case 'h':\r
+        case '?':\r
+            help++;\r
+            break;\r
+        case 'V':\r
+            version++;\r
+            break;\r
+\r
+        case 'W':\r
+            PySys_AddWarnOption(_PyOS_optarg);\r
+            break;\r
+\r
+        case '#':\r
+          if (saw_pound_flag == 0) {\r
+            if(freopen("stdout:", "w", stderr) == NULL) {\r
+              puts("ERROR: Unable to reopen stderr as an alias to stdout!");\r
+            }\r
+            saw_pound_flag = 0xFF;\r
+          }\r
+          break;\r
+\r
+        /* This space reserved for other options */\r
+\r
+        default:\r
+            return usage(2, argv[0]);\r
+            /*NOTREACHED*/\r
+\r
+        }\r
+    }\r
+\r
+    if (help)\r
+        return usage(0, argv[0]);\r
+\r
+    if (version) {\r
+        fprintf(stderr, "Python %s\n", PY_VERSION);\r
+        return 0;\r
+    }\r
+\r
+    if (Py_Py3kWarningFlag && !Py_TabcheckFlag)\r
+        /* -3 implies -t (but not -tt) */\r
+        Py_TabcheckFlag = 1;\r
+\r
+    if (!Py_InspectFlag &&\r
+        (p = Py_GETENV("PYTHONINSPECT")) && *p != '\0')\r
+        Py_InspectFlag = 1;\r
+    if (!saw_unbuffered_flag &&\r
+        (p = Py_GETENV("PYTHONUNBUFFERED")) && *p != '\0')\r
+        unbuffered = 1;\r
+\r
+    if (!Py_NoUserSiteDirectory &&\r
+        (p = Py_GETENV("PYTHONNOUSERSITE")) && *p != '\0')\r
+        Py_NoUserSiteDirectory = 1;\r
+\r
+    if ((p = Py_GETENV("PYTHONWARNINGS")) && *p != '\0') {\r
+        char *buf, *warning;\r
+\r
+        buf = (char *)malloc(strlen(p) + 1);\r
+        if (buf == NULL)\r
+            Py_FatalError(\r
+               "not enough memory to copy PYTHONWARNINGS");\r
+        strcpy(buf, p);\r
+        for (warning = strtok(buf, ",");\r
+             warning != NULL;\r
+             warning = strtok(NULL, ","))\r
+            PySys_AddWarnOption(warning);\r
+        free(buf);\r
+    }\r
+\r
+    if (command == NULL && module == NULL && _PyOS_optind < argc &&\r
+        strcmp(argv[_PyOS_optind], "-") != 0)\r
+    {\r
+#ifdef __VMS\r
+        filename = decc$translate_vms(argv[_PyOS_optind]);\r
+        if (filename == (char *)0 || filename == (char *)-1)\r
+            filename = argv[_PyOS_optind];\r
+\r
+#else\r
+        filename = argv[_PyOS_optind];\r
+#endif\r
+    }\r
+\r
+    stdin_is_interactive = Py_FdIsInteractive(stdin, (char *)0);\r
+\r
+    if (unbuffered) {\r
+#if defined(MS_WINDOWS) || defined(__CYGWIN__)\r
+        _setmode(fileno(stdin), O_BINARY);\r
+        _setmode(fileno(stdout), O_BINARY);\r
+#endif\r
+#ifdef HAVE_SETVBUF\r
+        setvbuf(stdin,  (char *)NULL, _IONBF, BUFSIZ);\r
+        setvbuf(stdout, (char *)NULL, _IONBF, BUFSIZ);\r
+        setvbuf(stderr, (char *)NULL, _IONBF, BUFSIZ);\r
+#else /* !HAVE_SETVBUF */\r
+        setbuf(stdin,  (char *)NULL);\r
+        setbuf(stdout, (char *)NULL);\r
+        setbuf(stderr, (char *)NULL);\r
+#endif /* !HAVE_SETVBUF */\r
+    }\r
+    else if (Py_InteractiveFlag) {\r
+#ifdef MS_WINDOWS\r
+        /* Doesn't have to have line-buffered -- use unbuffered */\r
+        /* Any set[v]buf(stdin, ...) screws up Tkinter :-( */\r
+        setvbuf(stdout, (char *)NULL, _IONBF, BUFSIZ);\r
+#else /* !MS_WINDOWS */\r
+#ifdef HAVE_SETVBUF\r
+        setvbuf(stdin,  (char *)NULL, _IOLBF, BUFSIZ);\r
+        setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ);\r
+#endif /* HAVE_SETVBUF */\r
+#endif /* !MS_WINDOWS */\r
+        /* Leave stderr alone - it should be unbuffered anyway. */\r
+    }\r
+#ifdef __VMS\r
+    else {\r
+        setvbuf (stdout, (char *)NULL, _IOLBF, BUFSIZ);\r
+    }\r
+#endif /* __VMS */\r
+\r
+#ifdef __APPLE__\r
+    /* On MacOS X, when the Python interpreter is embedded in an\r
+       application bundle, it gets executed by a bootstrapping script\r
+       that does os.execve() with an argv[0] that's different from the\r
+       actual Python executable. This is needed to keep the Finder happy,\r
+       or rather, to work around Apple's overly strict requirements of\r
+       the process name. However, we still need a usable sys.executable,\r
+       so the actual executable path is passed in an environment variable.\r
+       See Lib/plat-mac/bundlebuiler.py for details about the bootstrap\r
+       script. */\r
+    if ((p = Py_GETENV("PYTHONEXECUTABLE")) && *p != '\0')\r
+        Py_SetProgramName(p);\r
+    else\r
+        Py_SetProgramName(argv[0]);\r
+#else\r
+    Py_SetProgramName(argv[0]);\r
+#endif\r
+    Py_Initialize();\r
+\r
+    if (Py_VerboseFlag ||\r
+        (command == NULL && filename == NULL && module == NULL && stdin_is_interactive)) {\r
+        fprintf(stderr, "Python %s on %s\n",\r
+            Py_GetVersion(), Py_GetPlatform());\r
+        if (!Py_NoSiteFlag)\r
+            fprintf(stderr, "%s\n", COPYRIGHT);\r
+    }\r
+\r
+    if (command != NULL) {\r
+        /* Backup _PyOS_optind and force sys.argv[0] = '-c' */\r
+        _PyOS_optind--;\r
+        argv[_PyOS_optind] = "-c";\r
+    }\r
+\r
+    if (module != NULL) {\r
+        /* Backup _PyOS_optind and force sys.argv[0] = '-c'\r
+           so that PySys_SetArgv correctly sets sys.path[0] to ''\r
+           rather than looking for a file called "-m". See\r
+           tracker issue #8202 for details. */\r
+        _PyOS_optind--;\r
+        argv[_PyOS_optind] = "-c";\r
+    }\r
+\r
+    PySys_SetArgv(argc-_PyOS_optind, argv+_PyOS_optind);\r
+\r
+    if ((Py_InspectFlag || (command == NULL && filename == NULL && module == NULL)) &&\r
+        isatty(fileno(stdin))) {\r
+        PyObject *v;\r
+        v = PyImport_ImportModule("readline");\r
+        if (v == NULL)\r
+            PyErr_Clear();\r
+        else\r
+            Py_DECREF(v);\r
+    }\r
+\r
+    if (command) {\r
+        sts = PyRun_SimpleStringFlags(command, &cf) != 0;\r
+        free(command);\r
+    } else if (module) {\r
+        sts = (RunModule(module, 1) != 0);\r
+        free(module);\r
+    }\r
+    else {\r
+\r
+        if (filename == NULL && stdin_is_interactive) {\r
+            Py_InspectFlag = 0; /* do exit on SystemExit */\r
+            RunStartupFile(&cf);\r
+        }\r
+        /* XXX */\r
+\r
+        sts = -1;               /* keep track of whether we've already run __main__ */\r
+\r
+        if (filename != NULL) {\r
+            sts = RunMainFromImporter(filename);\r
+        }\r
+\r
+        if (sts==-1 && filename!=NULL) {\r
+            if ((fp = fopen(filename, "r")) == NULL) {\r
+                fprintf(stderr, "%s: can't open file '%s': [Errno %d] %s\n",\r
+                    argv[0], filename, errno, strerror(errno));\r
+\r
+                return 2;\r
+            }\r
+            else if (skipfirstline) {\r
+                int ch;\r
+                /* Push back first newline so line numbers\r
+                   remain the same */\r
+                while ((ch = getc(fp)) != EOF) {\r
+                    if (ch == '\n') {\r
+                        (void)ungetc(ch, fp);\r
+                        break;\r
+                    }\r
+                }\r
+            }\r
+            {\r
+                /* XXX: does this work on Win/Win64? (see posix_fstat) */\r
+                struct stat sb;\r
+                if (fstat(fileno(fp), &sb) == 0 &&\r
+                    S_ISDIR(sb.st_mode)) {\r
+                    fprintf(stderr, "%s: '%s' is a directory, cannot continue\n", argv[0], filename);\r
+                    fclose(fp);\r
+                    return 1;\r
+                }\r
+            }\r
+        }\r
+\r
+        if (sts==-1) {\r
+            /* call pending calls like signal handlers (SIGINT) */\r
+            if (Py_MakePendingCalls() == -1) {\r
+                PyErr_Print();\r
+                sts = 1;\r
+            } else {\r
+                sts = PyRun_AnyFileExFlags(\r
+                    fp,\r
+                    filename == NULL ? "<stdin>" : filename,\r
+                    filename != NULL, &cf) != 0;\r
+            }\r
+        }\r
+\r
+    }\r
+\r
+    /* Check this environment variable at the end, to give programs the\r
+     * opportunity to set it from Python.\r
+     */\r
+    if (!Py_InspectFlag &&\r
+        (p = Py_GETENV("PYTHONINSPECT")) && *p != '\0')\r
+    {\r
+        Py_InspectFlag = 1;\r
+    }\r
+\r
+    if (Py_InspectFlag && stdin_is_interactive &&\r
+        (filename != NULL || command != NULL || module != NULL)) {\r
+        Py_InspectFlag = 0;\r
+        /* XXX */\r
+        sts = PyRun_AnyFileFlags(stdin, "<stdin>", &cf) != 0;\r
+    }\r
+\r
+    Py_Finalize();\r
+#ifdef RISCOS\r
+    if (Py_RISCOSWimpFlag)\r
+        fprintf(stderr, "\x0cq\x0c"); /* make frontend quit */\r
+#endif\r
+\r
+#ifdef __INSURE__\r
+    /* Insure++ is a memory analysis tool that aids in discovering\r
+     * memory leaks and other memory problems.  On Python exit, the\r
+     * interned string dictionary is flagged as being in use at exit\r
+     * (which it is).  Under normal circumstances, this is fine because\r
+     * the memory will be automatically reclaimed by the system.  Under\r
+     * memory debugging, it's a huge source of useless noise, so we\r
+     * trade off slower shutdown for less distraction in the memory\r
+     * reports.  -baw\r
+     */\r
+    _Py_ReleaseInternedStrings();\r
+#endif /* __INSURE__ */\r
+\r
+    return sts;\r
+}\r
+\r
+/* this is gonna seem *real weird*, but if you put some other code between\r
+   Py_Main() and Py_GetArgcArgv() you will need to adjust the test in the\r
+   while statement in Misc/gdbinit:ppystack */\r
+\r
+/* Make the *original* argc/argv available to other modules.\r
+   This is rare, but it is needed by the secureware extension. */\r
+\r
+void\r
+Py_GetArgcArgv(int *argc, char ***argv)\r
+{\r
+    *argc = orig_argc;\r
+    *argv = orig_argv;\r
+}\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
index ece84378fe4b5e8ef66bb1aeb3fdf98bf96222b7..94c735d013730f2ab3b6106d1380f7c1df16b110 100644 (file)
@@ -1,6 +1,7 @@
 ## @file\r
 # PythonCore.inf\r
 #\r
+#  Copyright (c) 2015, Daryl McDaniel. All rights reserved.<BR>\r
 #  Copyright (c) 2011-2012, Intel Corporation. All rights reserved.<BR>\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
   Python-$(PYTHON_VERSION)/Modules/_functoolsmodule.c\r
   Python-$(PYTHON_VERSION)/Modules/gcmodule.c\r
   Python-$(PYTHON_VERSION)/Modules/getbuildinfo.c\r
-  Python-$(PYTHON_VERSION)/Modules/main.c\r
+  PyMod-$(PYTHON_VERSION)/Modules/main.c\r
   Python-$(PYTHON_VERSION)/Modules/python.c\r
 \r
   # Optional Modules -- See Python/Efi/config.c\r