Hi list and Bram.

I wrote a patch to fix a problem related if_python.
Please check attached.


Problem:
When python 2.7 can't find "site" module, vim is exit.
For example, on Windows which not installed official python 2.7,
but installed Mecurial or so (py2exe'ed binary),
Vim will try to load python27.dll of Mercurial,
but it failed to load "site" module, and exit.

The cause:
Python try to load "site" module, and if it is failed, call exit().
See at line 718 in 
http://svn.python.org/view/python/branches/release27-maint/Python/pythonrun.c?revision=85905&view=markup

Solution:
Suppress to load "site" module by setting Py_NoSiteFlag before Py_Initialize(),
then load it explicitly.

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
# HG changeset patch
# Parent d15bda4b3b0ae67e263b2fd3def95c1575140a14

diff -r d15bda4b3b0a src/if_python.c
--- a/src/if_python.c	Mon Jul 21 02:26:09 2014 +0900
+++ b/src/if_python.c	Mon Jul 21 02:39:19 2014 +0900
@@ -295,6 +295,7 @@
 #  define PyCObject_FromVoidPtr dll_PyCObject_FromVoidPtr
 #  define PyCObject_AsVoidPtr dll_PyCObject_AsVoidPtr
 # endif
+# define Py_NoSiteFlag (*dll_Py_NoSiteFlag)
 
 /*
  * Pointers for dynamic link
@@ -440,6 +441,7 @@
 static PyObject* (*dll_PyCObject_FromVoidPtr)(void *cobj, void (*destr)(void *));
 static void* (*dll_PyCObject_AsVoidPtr)(PyObject *);
 # endif
+static int* dll_Py_NoSiteFlag;
 
 static HINSTANCE hinstPython = 0; /* Instance of python.dll */
 
@@ -633,6 +635,7 @@
     {"PyCObject_FromVoidPtr", (PYTHON_PROC*)&dll_PyCObject_FromVoidPtr},
     {"PyCObject_AsVoidPtr", (PYTHON_PROC*)&dll_PyCObject_AsVoidPtr},
 # endif
+    {"Py_NoSiteFlag", (PYTHON_PROC*)&dll_Py_NoSiteFlag},
     {"", NULL},
 };
 
@@ -901,6 +904,8 @@
 {
     if (!initialised)
     {
+	PyObject *site;
+
 #ifdef DYNAMIC_PYTHON
 	if (!python_enabled(TRUE))
 	{
@@ -915,11 +920,24 @@
 
 	init_structs();
 
+	/* Disable implicit 'import site'. */
+	Py_NoSiteFlag++;
+
 #if !defined(MACOS) || defined(MACOS_X_UNIX)
 	Py_Initialize();
 #else
 	PyMac_Initialize();
 #endif
+
+	/* '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);
+
 	/* 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

Raspunde prin e-mail lui