0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

Add a configure check for RTLD_GLOBAL. (James Vega, Roland Puntaier)

This commit is contained in:
Bram Moolenaar
2010-08-13 16:22:57 +02:00
parent 2a988a162c
commit b744b2fa32
8 changed files with 162 additions and 36 deletions

View File

@@ -1,4 +1,4 @@
*if_pyth.txt* For Vim version 7.3f. Last change: 2010 Aug 10 *if_pyth.txt* For Vim version 7.3f. Last change: 2010 Aug 13
VIM REFERENCE MANUAL by Paul Moore VIM REFERENCE MANUAL by Paul Moore
@@ -348,8 +348,10 @@ Vim can be built in four ways (:version output):
3. Python 3 support only (-python, +python3 or +python3/dyn) 3. Python 3 support only (-python, +python3 or +python3/dyn)
4. Python 2 and 3 support (+python/dyn, +python3/dyn) 4. Python 2 and 3 support (+python/dyn, +python3/dyn)
*E836* *E837*
You can see that when Python 2 and Python 3 are both supported they must be You can see that when Python 2 and Python 3 are both supported they must be
loaded dynamically. loaded dynamically. Depending on how the libraries have been build it might
be impossible to use ":py3" and ":python" in one Vim session.
On Linux/Unix systems this can only be done without importing global symbols. On Linux/Unix systems this can only be done without importing global symbols.
In this case python's "import" might fail, if the library expects the symbols In this case python's "import" might fail, if the library expects the symbols

View File

@@ -30,15 +30,14 @@ be worked on, but only if you sponsor Vim development. See |sponsor|.
*known-bugs* *known-bugs*
-------------------- Known bugs and current work ----------------------- -------------------- Known bugs and current work -----------------------
Have a close look at :find completion, anything that could be wrong?
Patch for :python + :py3. (James Vega, Roland Puntaier, 2010 Aug 12) Patch for :python + :py3. (James Vega, Roland Puntaier, 2010 Aug 12)
Patch for crash with cmdline editing functions. (Dominique Pelle, 2010 Aug 12) Patch for crash with cmdline editing functions. (Dominique Pelle, 2010 Aug 12)
Test 73 fails on MS-Windows when compiled with DJGPP. Have a close look at :find completion, anything that could be wrong?
:find completion with 'path' set to "./**" results in full path for
"./subdir/file", should shorten to start with "./". Test 73 fails on MS-Windows when compiled with DJGPP and run twice. How to
delete the Xfind directory?
Before release 7.3: Before release 7.3:
- Rename vim73 branch to default (hints: Xavier de Gaye, 2010 May 23) - Rename vim73 branch to default (hints: Xavier de Gaye, 2010 May 23)

View File

@@ -2255,6 +2255,7 @@ clean celan: testclean
-rm -f *.o objects/* core $(VIMTARGET).core $(VIMTARGET) vim xxd/*.o -rm -f *.o objects/* core $(VIMTARGET).core $(VIMTARGET) vim xxd/*.o
-rm -f $(TOOLS) auto/osdef.h auto/pathdef.c auto/if_perl.c -rm -f $(TOOLS) auto/osdef.h auto/pathdef.c auto/if_perl.c
-rm -f conftest* *~ auto/link.sed -rm -f conftest* *~ auto/link.sed
-rm -f runtime pixmaps
-rm -rf $(APPDIR) -rm -rf $(APPDIR)
-rm -rf mzscheme_base.c -rm -rf mzscheme_base.c
if test -d $(PODIR); then \ if test -d $(PODIR); then \

87
src/auto/configure vendored
View File

@@ -1424,8 +1424,8 @@ Optional Features:
--enable-luainterp=OPTS Include Lua interpreter. default=no OPTS=no/yes/dynamic --enable-luainterp=OPTS Include Lua interpreter. default=no OPTS=no/yes/dynamic
--enable-mzschemeinterp Include MzScheme interpreter. --enable-mzschemeinterp Include MzScheme interpreter.
--enable-perlinterp=OPTS Include Perl interpreter. default=no OPTS=no/yes/dynamic --enable-perlinterp=OPTS Include Perl interpreter. default=no OPTS=no/yes/dynamic
--enable-pythoninterp Include Python interpreter. --enable-pythoninterp=OPTS Include Python interpreter. default=no OPTS=no/yes/dynamic
--enable-python3interp Include Python3 interpreter. --enable-python3interp=OPTS Include Python3 interpreter. default=no OPTS=no/yes/dynamic
--enable-tclinterp Include Tcl interpreter. --enable-tclinterp Include Tcl interpreter.
--enable-rubyinterp Include Ruby interpreter. --enable-rubyinterp Include Ruby interpreter.
--enable-cscope Include cscope interface. --enable-cscope Include cscope interface.
@@ -5118,7 +5118,7 @@ fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_pythoninterp" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_pythoninterp" >&5
$as_echo "$enable_pythoninterp" >&6; } $as_echo "$enable_pythoninterp" >&6; }
if test "$enable_pythoninterp" = "yes"; then if test "$enable_pythoninterp" = "yes" -o "$enable_pythoninterp" = "dynamic"; then
# Extract the first word of "python", so it can be a program name with args. # Extract the first word of "python", so it can be a program name with args.
set dummy python; ac_word=$2 set dummy python; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
@@ -5409,7 +5409,7 @@ fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_python3interp" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_python3interp" >&5
$as_echo "$enable_python3interp" >&6; } $as_echo "$enable_python3interp" >&6; }
if test "$enable_python3interp" = "yes"; then if test "$enable_python3interp" = "yes" -o "$enable_python3interp" = "dynamic"; then
# Extract the first word of "python3", so it can be a program name with args. # Extract the first word of "python3", so it can be a program name with args.
set dummy python3; ac_word=$2 set dummy python3; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
@@ -5614,8 +5614,8 @@ rm -f core conftest.err conftest.$ac_objext \
$as_echo "no" >&6; } $as_echo "no" >&6; }
fi fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if compile and link flags for Python are sane" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking if compile and link flags for Python 3 are sane" >&5
$as_echo_n "checking if compile and link flags for Python are sane... " >&6; } $as_echo_n "checking if compile and link flags for Python 3 are sane... " >&6; }
cflags_save=$CFLAGS cflags_save=$CFLAGS
libs_save=$LIBS libs_save=$LIBS
CFLAGS="$CFLAGS $PYTHON3_CFLAGS" CFLAGS="$CFLAGS $PYTHON3_CFLAGS"
@@ -5667,10 +5667,85 @@ if test "$python_ok" = yes && test "$python3_ok" = yes; then
$as_echo "#define DYNAMIC_PYTHON3 1" >>confdefs.h $as_echo "#define DYNAMIC_PYTHON3 1" >>confdefs.h
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we can do without RTLD_GLOBAL" >&5
$as_echo_n "checking whether we can do without RTLD_GLOBAL... " >&6; }
cflags_save=$CFLAGS
CFLAGS="$CFLAGS $PYTHON3_CFLAGS"
ldflags_save=$LDFLAGS
LDFLAGS="$LDFLAGS -ldl"
if test "$cross_compiling" = yes; then :
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error "cannot run test program while cross compiling
See \`config.log' for more details." "$LINENO" 5; }
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <dlfcn.h>
/* If this program fails, then RTLD_GLOBAL is needed.
* RTLD_GLOBAL will be used and then it is not possible to
* have both python versions enabled in the same vim instance.
* Only the first pyhton version used will be switched on.
*/
int no_rtl_global_needed_for(char *python_instsoname)
{
int needed = 0;
void* pylib = dlopen(python_instsoname, RTLD_LAZY);
if (pylib != 0)
{
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;
}
int main(int argc, char** argv)
{
int not_needed = 0;
if (no_rtl_global_needed_for("libpython2.7.so.1.0") && no_rtl_global_needed_for("libpython3.1.so.1.0"))
not_needed = 1;
return !not_needed;
}
_ACEOF
if ac_fn_c_try_run "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; };$as_echo "#define PY_NO_RTLD_GLOBAL 1" >>confdefs.h
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
conftest.$ac_objext conftest.beam conftest.$ac_ext
fi
CFLAGS=$cflags_save
LDFLAGS=$ldflags_save
PYTHON_SRC="if_python.c" PYTHON_SRC="if_python.c"
PYTHON_OBJ="objects/if_python.o" PYTHON_OBJ="objects/if_python.o"
PYTHON_CFLAGS="$PYTHON_CFLAGS -DDYNAMIC_PYTHON_DLL=\\\"${python_INSTSONAME}\\\"" PYTHON_CFLAGS="$PYTHON_CFLAGS -DDYNAMIC_PYTHON_DLL=\\\"${python_INSTSONAME}\\\""
PYTHON_LIBS= PYTHON_LIBS=
PYTHON3_SRC="if_python3.c"
PYTHON3_OBJ="objects/if_python3.o"
PYTHON3_CFLAGS="$PYTHON3_CFLAGS -DDYNAMIC_PYTHON3_DLL=\\\"${python3_INSTSONAME}\\\""
PYTHON3_LIBS=
elif test "$python_ok" = yes && test "$enable_pythoninterp" = "dynamic"; then
$as_echo "#define DYNAMIC_PYTHON 1" >>confdefs.h
PYTHON_SRC="if_python.c"
PYTHON_OBJ="objects/if_python.o"
PYTHON_CFLAGS="$PYTHON_CFLAGS -DDYNAMIC_PYTHON_DLL=\\\"${python_INSTSONAME}\\\""
PYTHON_LIBS=
elif test "$python3_ok" = yes && test "$enable_python3interp" = "dynamic"; then
$as_echo "#define DYNAMIC_PYTHON3 1" >>confdefs.h
PYTHON3_SRC="if_python3.c" PYTHON3_SRC="if_python3.c"
PYTHON3_OBJ="objects/if_python3.o" PYTHON3_OBJ="objects/if_python3.o"
PYTHON3_CFLAGS="$PYTHON3_CFLAGS -DDYNAMIC_PYTHON3_DLL=\\\"${python3_INSTSONAME}\\\"" PYTHON3_CFLAGS="$PYTHON3_CFLAGS -DDYNAMIC_PYTHON3_DLL=\\\"${python3_INSTSONAME}\\\""

View File

@@ -343,6 +343,9 @@
/* Define for linking via dlopen() or LoadLibrary() */ /* Define for linking via dlopen() or LoadLibrary() */
#undef DYNAMIC_PYTHON3 #undef DYNAMIC_PYTHON3
/* Define if dynamic python does not require RTLD_GLOBAL */
#undef PY_NO_RTLD_GLOBAL
/* Define if you want to include the Ruby interpreter. */ /* Define if you want to include the Ruby interpreter. */
#undef FEAT_RUBY #undef FEAT_RUBY

View File

@@ -757,10 +757,10 @@ AC_SUBST(PERL_LIBS)
AC_MSG_CHECKING(--enable-pythoninterp argument) AC_MSG_CHECKING(--enable-pythoninterp argument)
AC_ARG_ENABLE(pythoninterp, AC_ARG_ENABLE(pythoninterp,
[ --enable-pythoninterp Include Python interpreter.], , [ --enable-pythoninterp[=OPTS] Include Python interpreter. [default=no] [OPTS=no/yes/dynamic]], ,
[enable_pythoninterp="no"]) [enable_pythoninterp="no"])
AC_MSG_RESULT($enable_pythoninterp) AC_MSG_RESULT($enable_pythoninterp)
if test "$enable_pythoninterp" = "yes"; then if test "$enable_pythoninterp" = "yes" -o "$enable_pythoninterp" = "dynamic"; then
dnl -- find the python executable dnl -- find the python executable
AC_PATH_PROG(vi_cv_path_python, python) AC_PATH_PROG(vi_cv_path_python, python)
if test "X$vi_cv_path_python" != "X"; then if test "X$vi_cv_path_python" != "X"; then
@@ -944,10 +944,10 @@ AC_SUBST(PYTHON_OBJ)
AC_MSG_CHECKING(--enable-python3interp argument) AC_MSG_CHECKING(--enable-python3interp argument)
AC_ARG_ENABLE(python3interp, AC_ARG_ENABLE(python3interp,
[ --enable-python3interp Include Python3 interpreter.], , [ --enable-python3interp[=OPTS] Include Python3 interpreter. [default=no] [OPTS=no/yes/dynamic]], ,
[enable_python3interp="no"]) [enable_python3interp="no"])
AC_MSG_RESULT($enable_python3interp) AC_MSG_RESULT($enable_python3interp)
if test "$enable_python3interp" = "yes"; then if test "$enable_python3interp" = "yes" -o "$enable_python3interp" = "dynamic"; then
dnl -- find the python3 executable dnl -- find the python3 executable
AC_PATH_PROG(vi_cv_path_python3, python3) AC_PATH_PROG(vi_cv_path_python3, python3)
if test "X$vi_cv_path_python3" != "X"; then if test "X$vi_cv_path_python3" != "X"; then
@@ -1075,7 +1075,7 @@ eof
dnl check that compiling a simple program still works with the flags dnl check that compiling a simple program still works with the flags
dnl added for Python. dnl added for Python.
AC_MSG_CHECKING([if compile and link flags for Python are sane]) AC_MSG_CHECKING([if compile and link flags for Python 3 are sane])
cflags_save=$CFLAGS cflags_save=$CFLAGS
libs_save=$LIBS libs_save=$LIBS
CFLAGS="$CFLAGS $PYTHON3_CFLAGS" CFLAGS="$CFLAGS $PYTHON3_CFLAGS"
@@ -1109,6 +1109,46 @@ dnl with dlopen(), dlsym(), dlclose()
if test "$python_ok" = yes && test "$python3_ok" = yes; then if test "$python_ok" = yes && test "$python3_ok" = yes; then
AC_DEFINE(DYNAMIC_PYTHON) AC_DEFINE(DYNAMIC_PYTHON)
AC_DEFINE(DYNAMIC_PYTHON3) AC_DEFINE(DYNAMIC_PYTHON3)
AC_MSG_CHECKING(whether we can do without RTLD_GLOBAL)
cflags_save=$CFLAGS
CFLAGS="$CFLAGS $PYTHON3_CFLAGS"
ldflags_save=$LDFLAGS
LDFLAGS="$LDFLAGS -ldl"
AC_RUN_IFELSE([
#include <dlfcn.h>
/* If this program fails, then RTLD_GLOBAL is needed.
* RTLD_GLOBAL will be used and then it is not possible to
* have both python versions enabled in the same vim instance.
* Only the first pyhton version used will be switched on.
*/
int no_rtl_global_needed_for(char *python_instsoname)
{
int needed = 0;
void* pylib = dlopen(python_instsoname, RTLD_LAZY);
if (pylib != 0)
{
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;
}
int main(int argc, char** argv)
{
int not_needed = 0;
if (no_rtl_global_needed_for("libpython2.7.so.1.0") && no_rtl_global_needed_for("libpython3.1.so.1.0"))
not_needed = 1;
return !not_needed;
}],
[AC_MSG_RESULT(yes);AC_DEFINE(PY_NO_RTLD_GLOBAL)], [AC_MSG_RESULT(no)])
CFLAGS=$cflags_save
LDFLAGS=$ldflags_save
PYTHON_SRC="if_python.c" PYTHON_SRC="if_python.c"
PYTHON_OBJ="objects/if_python.o" PYTHON_OBJ="objects/if_python.o"
PYTHON_CFLAGS="$PYTHON_CFLAGS -DDYNAMIC_PYTHON_DLL=\\\"${python_INSTSONAME}\\\"" PYTHON_CFLAGS="$PYTHON_CFLAGS -DDYNAMIC_PYTHON_DLL=\\\"${python_INSTSONAME}\\\""
@@ -1117,6 +1157,18 @@ if test "$python_ok" = yes && test "$python3_ok" = yes; then
PYTHON3_OBJ="objects/if_python3.o" PYTHON3_OBJ="objects/if_python3.o"
PYTHON3_CFLAGS="$PYTHON3_CFLAGS -DDYNAMIC_PYTHON3_DLL=\\\"${python3_INSTSONAME}\\\"" PYTHON3_CFLAGS="$PYTHON3_CFLAGS -DDYNAMIC_PYTHON3_DLL=\\\"${python3_INSTSONAME}\\\""
PYTHON3_LIBS= PYTHON3_LIBS=
elif test "$python_ok" = yes && test "$enable_pythoninterp" = "dynamic"; then
AC_DEFINE(DYNAMIC_PYTHON)
PYTHON_SRC="if_python.c"
PYTHON_OBJ="objects/if_python.o"
PYTHON_CFLAGS="$PYTHON_CFLAGS -DDYNAMIC_PYTHON_DLL=\\\"${python_INSTSONAME}\\\""
PYTHON_LIBS=
elif test "$python3_ok" = yes && test "$enable_python3interp" = "dynamic"; then
AC_DEFINE(DYNAMIC_PYTHON3)
PYTHON3_SRC="if_python3.c"
PYTHON3_OBJ="objects/if_python3.o"
PYTHON3_CFLAGS="$PYTHON3_CFLAGS -DDYNAMIC_PYTHON3_DLL=\\\"${python3_INSTSONAME}\\\""
PYTHON3_LIBS=
fi fi
AC_MSG_CHECKING(--enable-tclinterp argument) AC_MSG_CHECKING(--enable-tclinterp argument)

View File

@@ -102,9 +102,7 @@ struct PyMethodDef { Py_ssize_t a; };
# include <dlfcn.h> # include <dlfcn.h>
# define FARPROC void* # define FARPROC void*
# define HINSTANCE void* # define HINSTANCE void*
# ifdef FEAT_PYTHON3 # ifdef PY_NO_RTLD_GLOBAL
/* 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) # define load_dll(n) dlopen((n), RTLD_LAZY)
# else # else
# define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL) # define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)
@@ -351,16 +349,15 @@ python_runtime_link_init(char *libname, int verbose)
{ {
int i; int i;
#if 0 /* this should be OK now that we don't use RTLD_GLOBAL */ #if !defined(PY_NO_RTLD_GLOBAL) && defined(UNIX) && defined(FEAT_PYTHON3)
#if defined(UNIX) && defined(FEAT_PYTHON3) /* Can't have Python and Python3 loaded at the same time.
/* Can't have Python and Python3 loaded at the same time, it may cause a * It cause a crash, because RTLD_GLOBAL is needed for
* crash. */ * standard C extension libraries of one or both python versions. */
if (python3_loaded()) if (python3_loaded())
{ {
EMSG(_("E999: Python: Cannot use :py and :py3 in one session")); EMSG(_("E836: This Vim cannot execute :python after using :py3"));
return FAIL; return FAIL;
} }
#endif
#endif #endif
if (hinstPython) if (hinstPython)

View File

@@ -80,9 +80,7 @@ static void init_structs(void);
# include <dlfcn.h> # include <dlfcn.h>
# define FARPROC void* # define FARPROC void*
# define HINSTANCE void* # define HINSTANCE void*
# ifdef FEAT_PYTHON # ifdef PY_NO_RTLD_GLOBAL
/* 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) # define load_dll(n) dlopen((n), RTLD_LAZY)
# else # else
# define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL) # define load_dll(n) dlopen((n), RTLD_LAZY|RTLD_GLOBAL)
@@ -338,16 +336,15 @@ py3_runtime_link_init(char *libname, int verbose)
int i; int i;
void *ucs_from_string, *ucs_from_string_and_size; void *ucs_from_string, *ucs_from_string_and_size;
# if 0 /* this should be OK now that we don't use RTLD_GLOBAL */ # if !defined(PY_NO_RTLD_GLOBAL) && defined(UNIX) && defined(FEAT_PYTHON)
# if defined(UNIX) && defined(FEAT_PYTHON) /* Can't have Python and Python3 loaded at the same time.
/* Can't have Python and Python3 loaded at the same time, it may cause a * It cause a crash, because RTLD_GLOBAL is needed for
* crash. */ * standard C extension libraries of one or both python versions. */
if (python_loaded()) if (python_loaded())
{ {
EMSG(_("E999: Python: Cannot use :py and :py3 in one session")); EMSG(_("E837: This Vim cannot execute :py3 after using :python"));
return FAIL; return FAIL;
} }
# endif
# endif # endif
if (hinstPy3 != 0) if (hinstPy3 != 0)