diff options
Diffstat (limited to 'Modules/main.c')
-rw-r--r-- | Modules/main.c | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/Modules/main.c b/Modules/main.c index 4d2e03a..2daefb8 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -22,15 +22,11 @@ #include <crtdbg.h> #endif -#if (defined(PYOS_OS2) && !defined(PYCC_GCC)) || defined(MS_WINDOWS) +#if defined(MS_WINDOWS) #define PYTHONHOMEHELP "<prefix>\\lib" #else -#if defined(PYOS_OS2) && defined(PYCC_GCC) -#define PYTHONHOMEHELP "<prefix>/Lib" -#else #define PYTHONHOMEHELP "<prefix>/pythonX.X" #endif -#endif #include "pygetopt.h" @@ -164,6 +160,32 @@ static void RunStartupFile(PyCompilerFlags *cf) } } +static void RunInteractiveHook(void) +{ + PyObject *sys, *hook, *result; + sys = PyImport_ImportModule("sys"); + if (sys == NULL) + goto error; + hook = PyObject_GetAttrString(sys, "__interactivehook__"); + Py_DECREF(sys); + if (hook == NULL) + PyErr_Clear(); + else { + result = PyObject_CallObject(hook, NULL); + Py_DECREF(hook); + if (result == NULL) + goto error; + else + Py_DECREF(result); + } + return; + +error: + PySys_WriteStderr("Failed calling sys.__interactivehook__\n"); + PyErr_Print(); + PyErr_Clear(); +} + static int RunModule(wchar_t *modname, int set_argv0) { @@ -171,17 +193,20 @@ static int RunModule(wchar_t *modname, int set_argv0) runpy = PyImport_ImportModule("runpy"); if (runpy == NULL) { fprintf(stderr, "Could not import runpy module\n"); + PyErr_Print(); return -1; } runmodule = PyObject_GetAttrString(runpy, "_run_module_as_main"); if (runmodule == NULL) { fprintf(stderr, "Could not access runpy._run_module_as_main\n"); + PyErr_Print(); Py_DECREF(runpy); return -1; } module = PyUnicode_FromWideChar(modname, wcslen(modname)); if (module == NULL) { fprintf(stderr, "Could not convert module name to unicode\n"); + PyErr_Print(); Py_DECREF(runpy); Py_DECREF(runmodule); return -1; @@ -190,6 +215,7 @@ static int RunModule(wchar_t *modname, int set_argv0) if (runargs == NULL) { fprintf(stderr, "Could not create arguments for runpy._run_module_as_main\n"); + PyErr_Print(); Py_DECREF(runpy); Py_DECREF(runmodule); Py_DECREF(module); @@ -690,6 +716,7 @@ Py_Main(int argc, wchar_t **argv) if (filename == NULL && stdin_is_interactive) { Py_InspectFlag = 0; /* do exit on SystemExit */ RunStartupFile(&cf); + RunInteractiveHook(); } /* XXX */ @@ -755,6 +782,7 @@ Py_Main(int argc, wchar_t **argv) if (Py_InspectFlag && stdin_is_interactive && (filename != NULL || command != NULL || module != NULL)) { Py_InspectFlag = 0; + RunInteractiveHook(); /* XXX */ sts = PyRun_AnyFileFlags(stdin, "<stdin>", &cf) != 0; } |