On Tue, Aug 10, 2010 at 11:15:41PM +0200, Bram Moolenaar wrote: > A configure check would help to decide whether everything works without > RTLD_GLOBAL global. If it does, then the current solution is best. If > it doesn't it might be better to switch to the other solution: do use > RTLD_GLOBAL but disallow using both python commands.
Attached is a configure check that determines if RTLD_GLOBAL is needed, when building with dynamic python. If so, it enables the "only one Python interface can be used per session" code. -- James GPG Key: 1024D/61326D40 2003-09-02 James Vega <[email protected]>
diff --git a/src/config.h.in b/src/config.h.in
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -343,6 +343,9 @@
/* Define for linking via dlopen() or LoadLibrary() */
#undef DYNAMIC_PYTHON3
+/* Define if dynamic python requires RTLD_GLOBAL */
+#undef PY_RTLD_GLOBAL
+
/* Define if you want to include the Ruby interpreter. */
#undef FEAT_RUBY
diff --git a/src/configure.in b/src/configure.in
--- a/src/configure.in
+++ b/src/configure.in
@@ -1109,6 +1109,31 @@
if test "$python_ok" = yes && test "$python3_ok" = yes; then
AC_DEFINE(DYNAMIC_PYTHON)
AC_DEFINE(DYNAMIC_PYTHON3)
+ AC_MSG_CHECKING(whether dynamic python requires RTLD_GLOBAL)
+ cflags_save=$CFLAGS
+ CFLAGS="$CFLAGS $PYTHON3_CFLAGS"
+ AC_RUN_IFELSE([
+ #include <Python.h>
+ #include <dlfcn.h>
+
+ int main(int argc, char** argv)
+ {
+ int needed = 0;
+ void* pylib = dlopen("${python3_INSTSONAME}", RTLD_LAZY);
+ if (pylib != NULL)
+ {
+ void (*init)(void) = dlsym(pylib, "Py_Initialize");
+ int (*simple)(char*) = dlsym(pylib, "PyRun_SimpleString");
+ void (*final)(void) = dlsym(pylib, "Py_Finalize");
+ (*init)();
+ needed = (*simple)("import termios") == -1;
+ (*final)();
+ dlclose(pylib);
+ }
+ return needed;
+ }],
+ [AC_MSG_RESULT(no)], [AC_MSG_RESULT(yes); AC_DEFINE(PY_RTLD_GLOBAL)])
+ CFLAGS=$cflags_save
PYTHON_SRC="if_python.c"
PYTHON_OBJ="objects/if_python.o"
PYTHON_CFLAGS="$PYTHON_CFLAGS -DDYNAMIC_PYTHON_DLL=\\\"${python_INSTSONAME}\\\""
diff --git a/src/if_python.c b/src/if_python.c
--- a/src/if_python.c
+++ b/src/if_python.c
@@ -102,9 +102,7 @@
# 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. */
+# ifndef PY_RTLD_GLOBAL
# define load_dll(n) dlopen((n), RTLD_LAZY)
# else
# define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)
@@ -351,7 +349,7 @@
{
int i;
-#if 0 /* this should be OK now that we don't use RTLD_GLOBAL */
+#ifdef PY_RTLD_GLOBAL
#if defined(UNIX) && defined(FEAT_PYTHON3)
/* Can't have Python and Python3 loaded at the same time, it may cause a
* crash. */
diff --git a/src/if_python3.c b/src/if_python3.c
--- a/src/if_python3.c
+++ b/src/if_python3.c
@@ -80,9 +80,7 @@
# include <dlfcn.h>
# define FARPROC void*
# define HINSTANCE void*
-# ifdef FEAT_PYTHON
- /* 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. */
+# ifndef PY_RTLD_GLOBAL
# define load_dll(n) dlopen((n), RTLD_LAZY)
# else
# define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)
@@ -338,7 +336,7 @@
int i;
void *ucs_from_string, *ucs_from_string_and_size;
-# if 0 /* this should be OK now that we don't use RTLD_GLOBAL */
+# ifdef PY_RTLD_GLOBAL
# if defined(UNIX) && defined(FEAT_PYTHON)
/* Can't have Python and Python3 loaded at the same time, it may cause a
* crash. */
signature.asc
Description: Digital signature
