diff -r e9497423de7a Include/pythonrun.h --- a/Include/pythonrun.h Tue Sep 06 14:08:24 2011 +0100 +++ b/Include/pythonrun.h Tue Sep 06 16:51:39 2011 +0200 @@ -167,6 +167,7 @@ PyAPI_FUNC(wchar_t *) Py_GetPrefix(void); PyAPI_FUNC(wchar_t *) Py_GetExecPrefix(void); PyAPI_FUNC(wchar_t *) Py_GetPath(void); +PyAPI_FUNC(void) Py_ImportLandmark(void); PyAPI_FUNC(void) Py_SetPath(const wchar_t *); #ifdef MS_WINDOWS int _Py_CheckPython3(); diff -r e9497423de7a Modules/getpath.c --- a/Modules/getpath.c Tue Sep 06 14:08:24 2011 +0100 +++ b/Modules/getpath.c Tue Sep 06 16:51:39 2011 +0200 @@ -51,7 +51,7 @@ * pybuilddir.txt. If the landmark is found, we're done. * * For the remaining steps, the prefix landmark will always be - * lib/python$VERSION/os.py and the exec_prefix will always be + * lib/python$VERSION/stdlib_landmark.py and the exec_prefix will always be * lib/python$VERSION/lib-dynload, where $VERSION is Python's version * number as supplied by the Makefile. Note that this means that no more * build directory checking is performed; if the first step did not find @@ -127,7 +127,12 @@ #endif #ifndef LANDMARK -#define LANDMARK L"os.py" +#define LANDMARK L"stdlib_landmark.py" +#define LANDMARK_MODULE "stdlib_landmark" +#else +#ifndef LANDMARK_MODULE +#error LANDMARK defined but not LANDMARK_MODULE +#endif #endif static wchar_t prefix[MAXPATHLEN+1]; @@ -778,6 +783,31 @@ return progpath; } +void +Py_ImportLandmark(void) +{ + PyObject *m = PyImport_ImportModule(LANDMARK_MODULE); + if (m == NULL) { + PyObject *f = PySys_GetObject("stderr"); + if (Py_VerboseFlag) { + PyFile_WriteString( + "'import " LANDMARK_MODULE "' failed; traceback:\n", f); + PyErr_Print(); + } + else { + /* Ignore a missing landmark module; if the stdlib wasn't + * properly located the next import (of 'site') will have + * instructions to run Python with '-v', which will show the + * above traceback. If it *was* properly located, the landmark + * module probably isn't important anymore. + */ + PyErr_Clear(); + } + } + else { + Py_DECREF(m); + } +} #ifdef __cplusplus } diff -r e9497423de7a Python/pythonrun.c --- a/Python/pythonrun.c Tue Sep 06 14:08:24 2011 +0100 +++ b/Python/pythonrun.c Tue Sep 06 16:51:39 2011 +0200 @@ -314,6 +314,9 @@ if (install_sigs) initsigs(); /* Signal handling stuff, including initintr() */ + /* Make sure the stdlib is available by importing the landmark. */ + Py_ImportLandmark(); + initmain(); /* Module __main__ */ if (initstdio() < 0) Py_FatalError( @@ -640,6 +643,7 @@ if (initstdio() < 0) Py_FatalError( "Py_Initialize: can't initialize sys standard streams"); + Py_ImportLandmark(); initmain(); if (!Py_NoSiteFlag) initsite();