3ef2ca
To: vim_dev@googlegroups.com
3ef2ca
Subject: Patch 7.4.380
3ef2ca
Fcc: outbox
3ef2ca
From: Bram Moolenaar <Bram@moolenaar.net>
3ef2ca
Mime-Version: 1.0
3ef2ca
Content-Type: text/plain; charset=UTF-8
3ef2ca
Content-Transfer-Encoding: 8bit
3ef2ca
------------
3ef2ca
3ef2ca
Patch 7.4.380
3ef2ca
Problem:    Loading python may cause Vim to exit.
3ef2ca
Solution:   Avoid loading the "site" module. (Taro Muraoka)
3ef2ca
Files:	    src/if_python.c
3ef2ca
3ef2ca
3ef2ca
*** ../vim-7.4.379/src/if_python.c	2014-03-30 16:11:37.176530823 +0200
3ef2ca
--- src/if_python.c	2014-07-23 16:46:42.863880615 +0200
3ef2ca
***************
3ef2ca
*** 295,300 ****
3ef2ca
--- 295,303 ----
3ef2ca
  #  define PyCObject_FromVoidPtr dll_PyCObject_FromVoidPtr
3ef2ca
  #  define PyCObject_AsVoidPtr dll_PyCObject_AsVoidPtr
3ef2ca
  # endif
3ef2ca
+ # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000
3ef2ca
+ #  define Py_NoSiteFlag (*dll_Py_NoSiteFlag)
3ef2ca
+ # endif
3ef2ca
  
3ef2ca
  /*
3ef2ca
   * Pointers for dynamic link
3ef2ca
***************
3ef2ca
*** 440,445 ****
3ef2ca
--- 443,451 ----
3ef2ca
  static PyObject* (*dll_PyCObject_FromVoidPtr)(void *cobj, void (*destr)(void *));
3ef2ca
  static void* (*dll_PyCObject_AsVoidPtr)(PyObject *);
3ef2ca
  # endif
3ef2ca
+ # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000
3ef2ca
+ static int* dll_Py_NoSiteFlag;
3ef2ca
+ # endif
3ef2ca
  
3ef2ca
  static HINSTANCE hinstPython = 0; /* Instance of python.dll */
3ef2ca
  
3ef2ca
***************
3ef2ca
*** 633,638 ****
3ef2ca
--- 639,647 ----
3ef2ca
      {"PyCObject_FromVoidPtr", (PYTHON_PROC*)&dll_PyCObject_FromVoidPtr},
3ef2ca
      {"PyCObject_AsVoidPtr", (PYTHON_PROC*)&dll_PyCObject_AsVoidPtr},
3ef2ca
  # endif
3ef2ca
+ # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000
3ef2ca
+     {"Py_NoSiteFlag", (PYTHON_PROC*)&dll_Py_NoSiteFlag},
3ef2ca
+ # endif
3ef2ca
      {"", NULL},
3ef2ca
  };
3ef2ca
  
3ef2ca
***************
3ef2ca
*** 901,906 ****
3ef2ca
--- 910,919 ----
3ef2ca
  {
3ef2ca
      if (!initialised)
3ef2ca
      {
3ef2ca
+ #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000
3ef2ca
+ 	PyObject *site;
3ef2ca
+ #endif
3ef2ca
+ 
3ef2ca
  #ifdef DYNAMIC_PYTHON
3ef2ca
  	if (!python_enabled(TRUE))
3ef2ca
  	{
3ef2ca
***************
3ef2ca
*** 915,925 ****
3ef2ca
--- 928,956 ----
3ef2ca
  
3ef2ca
  	init_structs();
3ef2ca
  
3ef2ca
+ #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000
3ef2ca
+ 	/* Disable implicit 'import site', because it may cause Vim to exit
3ef2ca
+ 	 * when it can't be found. */
3ef2ca
+ 	Py_NoSiteFlag++;
3ef2ca
+ #endif
3ef2ca
+ 
3ef2ca
  #if !defined(MACOS) || defined(MACOS_X_UNIX)
3ef2ca
  	Py_Initialize();
3ef2ca
  #else
3ef2ca
  	PyMac_Initialize();
3ef2ca
  #endif
3ef2ca
+ 
3ef2ca
+ #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000
3ef2ca
+ 	/* 'import site' explicitly. */
3ef2ca
+ 	site = PyImport_ImportModule("site");
3ef2ca
+ 	if (site == NULL)
3ef2ca
+ 	{
3ef2ca
+ 	    EMSG(_("E887: Sorry, this command is disabled, the Python's site module could not be loaded."));
3ef2ca
+ 	    goto fail;
3ef2ca
+ 	}
3ef2ca
+ 	Py_DECREF(site);
3ef2ca
+ #endif
3ef2ca
+ 
3ef2ca
  	/* Initialise threads, and below save the state using
3ef2ca
  	 * PyEval_SaveThread.  Without the call to PyEval_SaveThread, thread
3ef2ca
  	 * specific state (such as the system trace hook), will be lost
3ef2ca
*** ../vim-7.4.379/src/version.c	2014-07-23 16:33:04.079886500 +0200
3ef2ca
--- src/version.c	2014-07-23 16:43:47.939881872 +0200
3ef2ca
***************
3ef2ca
*** 736,737 ****
3ef2ca
--- 736,739 ----
3ef2ca
  {   /* Add new patch number below this line */
3ef2ca
+ /**/
3ef2ca
+     380,
3ef2ca
  /**/
3ef2ca
3ef2ca
-- 
3ef2ca
Looking at Perl through Lisp glasses, Perl looks atrocious.
3ef2ca
3ef2ca
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
3ef2ca
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
3ef2ca
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
3ef2ca
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///