Skip to content

Instantly share code, notes, and snippets.

@koron
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koron/aa53ddf11510e9d8942d to your computer and use it in GitHub Desktop.
Save koron/aa53ddf11510e9d8942d to your computer and use it in GitHub Desktop.
Vim の if_python で Py_NoSiteFlag を立てるパッチ https://github.com/vim-jp/issues/issues/594
# HG changeset patch
# Parent 8ac1a3f3273929167574f064c810a1f4e3f851b9
diff -r 8ac1a3f32739 src/if_python.c
--- a/src/if_python.c Mon Jul 21 08:46:27 2014 +0900
+++ b/src/if_python.c Mon Jul 21 08:57:37 2014 +0900
@@ -295,6 +295,9 @@
# define PyCObject_FromVoidPtr dll_PyCObject_FromVoidPtr
# define PyCObject_AsVoidPtr dll_PyCObject_AsVoidPtr
# endif
+# if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000
+# define Py_NoSiteFlag (*dll_Py_NoSiteFlag)
+# endif
/*
* Pointers for dynamic link
@@ -440,6 +443,9 @@
static PyObject* (*dll_PyCObject_FromVoidPtr)(void *cobj, void (*destr)(void *));
static void* (*dll_PyCObject_AsVoidPtr)(PyObject *);
# endif
+# if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000
+static int* dll_Py_NoSiteFlag;
+# endif
static HINSTANCE hinstPython = 0; /* Instance of python.dll */
@@ -633,6 +639,9 @@
{"PyCObject_FromVoidPtr", (PYTHON_PROC*)&dll_PyCObject_FromVoidPtr},
{"PyCObject_AsVoidPtr", (PYTHON_PROC*)&dll_PyCObject_AsVoidPtr},
# endif
+# if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000
+ {"Py_NoSiteFlag", (PYTHON_PROC*)&dll_Py_NoSiteFlag},
+# endif
{"", NULL},
};
@@ -901,6 +910,10 @@
{
if (!initialised)
{
+#if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000
+ PyObject *site;
+#endif
+
#ifdef DYNAMIC_PYTHON
if (!python_enabled(TRUE))
{
@@ -915,11 +928,28 @@
init_structs();
+#if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000
+ /* Disable implicit 'import site'. */
+ Py_NoSiteFlag++;
+#endif
+
#if !defined(MACOS) || defined(MACOS_X_UNIX)
Py_Initialize();
#else
PyMac_Initialize();
#endif
+
+#if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000
+ /* 'import site' explicitly. */
+ site = PyImport_ImportModule("site");
+ if (site == NULL)
+ {
+ EMSG(_("EXXX: Sorry, this command is disabled, the Python's site module could not be loaded."));
+ goto fail;
+ }
+ Py_DECREF(site);
+#endif
+
/* Initialise threads, and below save the state using
* PyEval_SaveThread. Without the call to PyEval_SaveThread, thread
* specific state (such as the system trace hook), will be lost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment