@@ -295,6 +295,9 @@ struct PyMethodDef { Py_ssize_t a; };
295295# define PyCObject_FromVoidPtr dll_PyCObject_FromVoidPtr
296296# define PyCObject_AsVoidPtr dll_PyCObject_AsVoidPtr
297297# endif
298+ # if defined(PY_VERSION_HEX ) && PY_VERSION_HEX >= 0x02070000
299+ # define Py_NoSiteFlag (*dll_Py_NoSiteFlag)
300+ # endif
298301
299302/*
300303 * Pointers for dynamic link
@@ -440,6 +443,9 @@ static void* (*dll_PyCapsule_GetPointer)(PyObject *, char *);
440443static PyObject * (* dll_PyCObject_FromVoidPtr )(void * cobj , void (* destr )(void * ));
441444static void * (* dll_PyCObject_AsVoidPtr )(PyObject * );
442445# endif
446+ # if defined(PY_VERSION_HEX ) && PY_VERSION_HEX >= 0x02070000
447+ static int * dll_Py_NoSiteFlag ;
448+ # endif
443449
444450static HINSTANCE hinstPython = 0 ; /* Instance of python.dll */
445451
@@ -632,6 +638,9 @@ static struct
632638# else
633639 {"PyCObject_FromVoidPtr" , (PYTHON_PROC * )& dll_PyCObject_FromVoidPtr },
634640 {"PyCObject_AsVoidPtr" , (PYTHON_PROC * )& dll_PyCObject_AsVoidPtr },
641+ # endif
642+ # if defined(PY_VERSION_HEX ) && PY_VERSION_HEX >= 0x02070000
643+ {"Py_NoSiteFlag" , (PYTHON_PROC * )& dll_Py_NoSiteFlag },
635644# endif
636645 {"" , NULL },
637646};
@@ -901,6 +910,10 @@ Python_Init(void)
901910{
902911 if (!initialised )
903912 {
913+ #if defined(PY_VERSION_HEX ) && PY_VERSION_HEX >= 0x02070000
914+ PyObject * site ;
915+ #endif
916+
904917#ifdef DYNAMIC_PYTHON
905918 if (!python_enabled (TRUE))
906919 {
@@ -915,11 +928,29 @@ Python_Init(void)
915928
916929 init_structs ();
917930
931+ #if defined(PY_VERSION_HEX ) && PY_VERSION_HEX >= 0x02070000
932+ /* Disable implicit 'import site', because it may cause Vim to exit
933+ * when it can't be found. */
934+ Py_NoSiteFlag ++ ;
935+ #endif
936+
918937#if !defined(MACOS ) || defined(MACOS_X_UNIX )
919938 Py_Initialize ();
920939#else
921940 PyMac_Initialize ();
922941#endif
942+
943+ #if defined(PY_VERSION_HEX ) && PY_VERSION_HEX >= 0x02070000
944+ /* 'import site' explicitly. */
945+ site = PyImport_ImportModule ("site" );
946+ if (site == NULL )
947+ {
948+ EMSG (_ ("E887: Sorry, this command is disabled, the Python's site module could not be loaded." ));
949+ goto fail ;
950+ }
951+ Py_DECREF (site );
952+ #endif
953+
923954 /* Initialise threads, and below save the state using
924955 * PyEval_SaveThread. Without the call to PyEval_SaveThread, thread
925956 * specific state (such as the system trace hook), will be lost
0 commit comments