Skip to content

Commit 2a25d18

Browse files
committed
updated for version 7.4.380
Problem: Loading python may cause Vim to exit. Solution: Avoid loading the "site" module. (Taro Muraoka)
1 parent 0a84b4d commit 2a25d18

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/if_python.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 *);
440443
static PyObject* (*dll_PyCObject_FromVoidPtr)(void *cobj, void (*destr)(void *));
441444
static 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

444450
static 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

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
380,
737739
/**/
738740
379,
739741
/**/

0 commit comments

Comments
 (0)