diff 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
line wrap: on
line diff
--- a/src/if_python.c
+++ b/src/if_python.c
@@ -93,32 +93,38 @@ struct PyMethodDef { Py_ssize_t a; };
 # define PY_CAN_RECURSE
 #endif
 
-#if defined(DYNAMIC_PYTHON) || defined(PROTO)
-# ifndef DYNAMIC_PYTHON
-#  define HINSTANCE long_u		/* for generating prototypes */
-# endif
+# if defined(DYNAMIC_PYTHON) || defined(PROTO)
+#  ifndef DYNAMIC_PYTHON
+#   define HINSTANCE long_u		/* for generating prototypes */
+#  endif
 
-#ifndef WIN3264
-# include <dlfcn.h>
-# define FARPROC void*
-# define HINSTANCE void*
-# define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)
-# define close_dll dlclose
-# define symbol_from_dll dlsym
-#else
-# define load_dll LoadLibrary
-# define close_dll FreeLibrary
-# define symbol_from_dll GetProcAddress
-#endif
+# ifndef WIN3264
+#  include <dlfcn.h>
+#  define FARPROC void*
+#  define HINSTANCE void*
+#  ifdef FEAT_PYTHON3
+   /* Don't use RTLD_GLOBAL, it may cause a crash if both :python and :py3 are
+    * used. But without it importing may fail, e.g., for termios. */
+#   define load_dll(n) dlopen((n), RTLD_LAZY)
+#  else
+#   define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)
+#  endif
+#  define close_dll dlclose
+#  define symbol_from_dll dlsym
+# else
+#  define load_dll LoadLibrary
+#  define close_dll FreeLibrary
+#  define symbol_from_dll GetProcAddress
+# endif
 
 /* This makes if_python.c compile without warnings against Python 2.5
  * on Win32 and Win64. */
-#undef PyRun_SimpleString
-#undef PyArg_Parse
-#undef PyArg_ParseTuple
-#undef Py_BuildValue
-#undef Py_InitModule4
-#undef Py_InitModule4_64
+# undef PyRun_SimpleString
+# undef PyArg_Parse
+# undef PyArg_ParseTuple
+# undef Py_BuildValue
+# undef Py_InitModule4
+# undef Py_InitModule4_64
 
 /*
  * Wrapper defines
@@ -345,6 +351,7 @@ python_runtime_link_init(char *libname, 
 {
     int i;
 
+#if 0  /* this should be OK now that we don't use RTLD_GLOBAL */
 #if defined(UNIX) && defined(FEAT_PYTHON3)
     /* Can't have Python and Python3 loaded at the same time, it may cause a
      * crash. */
@@ -354,6 +361,7 @@ python_runtime_link_init(char *libname, 
 	return FAIL;
     }
 #endif
+#endif
 
     if (hinstPython)
 	return OK;