Mercurial > vim
comparison src/if_python.c @ 6083:7cfbad4a78bf v7.4.380
updated for version 7.4.380
Problem: Loading python may cause Vim to exit.
Solution: Avoid loading the "site" module. (Taro Muraoka)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Wed, 23 Jul 2014 16:57:00 +0200 |
parents | 3ee5808a293c |
children | 38add5a3d617 |
comparison
equal
deleted
inserted
replaced
6082:99f3d2a4f60a | 6083:7cfbad4a78bf |
---|---|
293 # define PyCapsule_GetPointer dll_PyCapsule_GetPointer | 293 # define PyCapsule_GetPointer dll_PyCapsule_GetPointer |
294 # else | 294 # else |
295 # define PyCObject_FromVoidPtr dll_PyCObject_FromVoidPtr | 295 # define PyCObject_FromVoidPtr dll_PyCObject_FromVoidPtr |
296 # define PyCObject_AsVoidPtr dll_PyCObject_AsVoidPtr | 296 # define PyCObject_AsVoidPtr dll_PyCObject_AsVoidPtr |
297 # endif | 297 # endif |
298 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 | |
299 # define Py_NoSiteFlag (*dll_Py_NoSiteFlag) | |
300 # endif | |
298 | 301 |
299 /* | 302 /* |
300 * Pointers for dynamic link | 303 * Pointers for dynamic link |
301 */ | 304 */ |
302 static int(*dll_PyArg_Parse)(PyObject *, char *, ...); | 305 static int(*dll_PyArg_Parse)(PyObject *, char *, ...); |
438 static void* (*dll_PyCapsule_GetPointer)(PyObject *, char *); | 441 static void* (*dll_PyCapsule_GetPointer)(PyObject *, char *); |
439 # else | 442 # else |
440 static PyObject* (*dll_PyCObject_FromVoidPtr)(void *cobj, void (*destr)(void *)); | 443 static PyObject* (*dll_PyCObject_FromVoidPtr)(void *cobj, void (*destr)(void *)); |
441 static void* (*dll_PyCObject_AsVoidPtr)(PyObject *); | 444 static void* (*dll_PyCObject_AsVoidPtr)(PyObject *); |
442 # endif | 445 # endif |
446 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 | |
447 static int* dll_Py_NoSiteFlag; | |
448 # endif | |
443 | 449 |
444 static HINSTANCE hinstPython = 0; /* Instance of python.dll */ | 450 static HINSTANCE hinstPython = 0; /* Instance of python.dll */ |
445 | 451 |
446 /* Imported exception objects */ | 452 /* Imported exception objects */ |
447 static PyObject *imp_PyExc_AttributeError; | 453 static PyObject *imp_PyExc_AttributeError; |
631 {"PyCapsule_GetPointer", (PYTHON_PROC*)&dll_PyCapsule_GetPointer}, | 637 {"PyCapsule_GetPointer", (PYTHON_PROC*)&dll_PyCapsule_GetPointer}, |
632 # else | 638 # else |
633 {"PyCObject_FromVoidPtr", (PYTHON_PROC*)&dll_PyCObject_FromVoidPtr}, | 639 {"PyCObject_FromVoidPtr", (PYTHON_PROC*)&dll_PyCObject_FromVoidPtr}, |
634 {"PyCObject_AsVoidPtr", (PYTHON_PROC*)&dll_PyCObject_AsVoidPtr}, | 640 {"PyCObject_AsVoidPtr", (PYTHON_PROC*)&dll_PyCObject_AsVoidPtr}, |
635 # endif | 641 # endif |
642 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 | |
643 {"Py_NoSiteFlag", (PYTHON_PROC*)&dll_Py_NoSiteFlag}, | |
644 # endif | |
636 {"", NULL}, | 645 {"", NULL}, |
637 }; | 646 }; |
638 | 647 |
639 /* | 648 /* |
640 * Free python.dll | 649 * Free python.dll |
899 static int | 908 static int |
900 Python_Init(void) | 909 Python_Init(void) |
901 { | 910 { |
902 if (!initialised) | 911 if (!initialised) |
903 { | 912 { |
913 #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 | |
914 PyObject *site; | |
915 #endif | |
916 | |
904 #ifdef DYNAMIC_PYTHON | 917 #ifdef DYNAMIC_PYTHON |
905 if (!python_enabled(TRUE)) | 918 if (!python_enabled(TRUE)) |
906 { | 919 { |
907 EMSG(_("E263: Sorry, this command is disabled, the Python library could not be loaded.")); | 920 EMSG(_("E263: Sorry, this command is disabled, the Python library could not be loaded.")); |
908 goto fail; | 921 goto fail; |
913 Py_SetPythonHome(PYTHON_HOME); | 926 Py_SetPythonHome(PYTHON_HOME); |
914 #endif | 927 #endif |
915 | 928 |
916 init_structs(); | 929 init_structs(); |
917 | 930 |
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 | |
918 #if !defined(MACOS) || defined(MACOS_X_UNIX) | 937 #if !defined(MACOS) || defined(MACOS_X_UNIX) |
919 Py_Initialize(); | 938 Py_Initialize(); |
920 #else | 939 #else |
921 PyMac_Initialize(); | 940 PyMac_Initialize(); |
922 #endif | 941 #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 | |
923 /* Initialise threads, and below save the state using | 954 /* Initialise threads, and below save the state using |
924 * PyEval_SaveThread. Without the call to PyEval_SaveThread, thread | 955 * PyEval_SaveThread. Without the call to PyEval_SaveThread, thread |
925 * specific state (such as the system trace hook), will be lost | 956 * specific state (such as the system trace hook), will be lost |
926 * between invocations of Python code. */ | 957 * between invocations of Python code. */ |
927 PyEval_InitThreads(); | 958 PyEval_InitThreads(); |