comparison src/if_python.c @ 2528:8bc2e8390c11 vim73

When building with both Python 2 and Python 3 don't use RTLD_GLOBAL, so that both may work.
author Bram Moolenaar <bram@vim.org>
date Mon, 09 Aug 2010 22:06:13 +0200
parents 84d353762845
children 7abef60aca22
comparison
equal deleted inserted replaced
2527:a89f8c036bc5 2528:8bc2e8390c11
91 #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x020300F0 91 #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x020300F0
92 /* Python 2.3: can invoke ":python" recursively. */ 92 /* Python 2.3: can invoke ":python" recursively. */
93 # define PY_CAN_RECURSE 93 # define PY_CAN_RECURSE
94 #endif 94 #endif
95 95
96 #if defined(DYNAMIC_PYTHON) || defined(PROTO) 96 # if defined(DYNAMIC_PYTHON) || defined(PROTO)
97 # ifndef DYNAMIC_PYTHON 97 # ifndef DYNAMIC_PYTHON
98 # define HINSTANCE long_u /* for generating prototypes */ 98 # define HINSTANCE long_u /* for generating prototypes */
99 # endif
100
101 # ifndef WIN3264
102 # include <dlfcn.h>
103 # define FARPROC void*
104 # define HINSTANCE void*
105 # ifdef FEAT_PYTHON3
106 /* Don't use RTLD_GLOBAL, it may cause a crash if both :python and :py3 are
107 * used. But without it importing may fail, e.g., for termios. */
108 # define load_dll(n) dlopen((n), RTLD_LAZY)
109 # else
110 # define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)
111 # endif
112 # define close_dll dlclose
113 # define symbol_from_dll dlsym
114 # else
115 # define load_dll LoadLibrary
116 # define close_dll FreeLibrary
117 # define symbol_from_dll GetProcAddress
99 # endif 118 # endif
100
101 #ifndef WIN3264
102 # include <dlfcn.h>
103 # define FARPROC void*
104 # define HINSTANCE void*
105 # define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)
106 # define close_dll dlclose
107 # define symbol_from_dll dlsym
108 #else
109 # define load_dll LoadLibrary
110 # define close_dll FreeLibrary
111 # define symbol_from_dll GetProcAddress
112 #endif
113 119
114 /* This makes if_python.c compile without warnings against Python 2.5 120 /* This makes if_python.c compile without warnings against Python 2.5
115 * on Win32 and Win64. */ 121 * on Win32 and Win64. */
116 #undef PyRun_SimpleString 122 # undef PyRun_SimpleString
117 #undef PyArg_Parse 123 # undef PyArg_Parse
118 #undef PyArg_ParseTuple 124 # undef PyArg_ParseTuple
119 #undef Py_BuildValue 125 # undef Py_BuildValue
120 #undef Py_InitModule4 126 # undef Py_InitModule4
121 #undef Py_InitModule4_64 127 # undef Py_InitModule4_64
122 128
123 /* 129 /*
124 * Wrapper defines 130 * Wrapper defines
125 */ 131 */
126 # define PyArg_Parse dll_PyArg_Parse 132 # define PyArg_Parse dll_PyArg_Parse
343 static int 349 static int
344 python_runtime_link_init(char *libname, int verbose) 350 python_runtime_link_init(char *libname, int verbose)
345 { 351 {
346 int i; 352 int i;
347 353
354 #if 0 /* this should be OK now that we don't use RTLD_GLOBAL */
348 #if defined(UNIX) && defined(FEAT_PYTHON3) 355 #if defined(UNIX) && defined(FEAT_PYTHON3)
349 /* Can't have Python and Python3 loaded at the same time, it may cause a 356 /* Can't have Python and Python3 loaded at the same time, it may cause a
350 * crash. */ 357 * crash. */
351 if (python3_loaded()) 358 if (python3_loaded())
352 { 359 {
353 EMSG(_("E999: Python: Cannot use :py and :py3 in one session")); 360 EMSG(_("E999: Python: Cannot use :py and :py3 in one session"));
354 return FAIL; 361 return FAIL;
355 } 362 }
363 #endif
356 #endif 364 #endif
357 365
358 if (hinstPython) 366 if (hinstPython)
359 return OK; 367 return OK;
360 hinstPython = load_dll(libname); 368 hinstPython = load_dll(libname);