Move the setting and resetting of the DL open flags to where 'import _openbabel' occurs in openbabel.py

This commit is contained in:
Noel O'Boyle
2018-02-11 08:31:02 +00:00
parent e287255158
commit 3b86b037b4
2 changed files with 15 additions and 9 deletions

View File

@@ -79,15 +79,6 @@ if (DO_PYTHON_BINDINGS)
else(WIN32)
add_custom_command(OUTPUT ${openbabel_SOURCE_DIR}/scripts/python/openbabel-python.cpp ${openbabel_SOURCE_DIR}/scripts/python/openbabel.py
COMMAND ${SWIG_EXECUTABLE} -python -c++ -small -O -templatereduce -naturalvar -I${openbabel_SOURCE_DIR}/include -I${openbabel_BINARY_DIR}/include -o ${openbabel_SOURCE_DIR}/scripts/python/openbabel-python.cpp ${eigen_define} -outdir ${openbabel_SOURCE_DIR}/scripts/python ${openbabel_SOURCE_DIR}/scripts/openbabel-python.i
COMMAND ${CMAKE_COMMAND} -E echo "import sys" > ob.py
COMMAND ${CMAKE_COMMAND} -E echo "if sys.platform.find('linux'\) != -1:" >> ob.py
COMMAND ${CMAKE_COMMAND} -E echo " import ctypes" >> ob.py
COMMAND ${CMAKE_COMMAND} -E echo " flags = sys.getdlopenflags()" >> ob.py
COMMAND ${CMAKE_COMMAND} -E echo " sys.setdlopenflags(sys.getdlopenflags() | ctypes.RTLD_GLOBAL)" >> ob.py
COMMAND ${CMAKE_COMMAND} -E echo " OBPlugin.LoadAllPlugins()" >> ob.py
COMMAND ${CMAKE_COMMAND} -E echo " sys.setdlopenflags(flags)" >> ob.py
COMMAND cat ob.py >> ${openbabel_SOURCE_DIR}/scripts/python/openbabel.py
COMMAND ${CMAKE_COMMAND} -E remove ob.py
MAIN_DEPENDENCY openbabel-python.i
VERBATIM
)

View File

@@ -64,6 +64,21 @@
#include <openbabel/stereo/squareplanar.h>
#include <openbabel/stereo/bindings.h>
%}
// Set and reset dlopenflags so that plugin loading works fine for "import _openbabel"
%pythonbegin %{
import sys
if sys.platform.find("linux") != -1:
dlflags = sys.getdlopenflags()
import ctypes
sys.setdlopenflags(dlflags | ctypes.RTLD_GLOBAL)
%}
%pythoncode %{
if sys.platform.find("linux") != -1:
sys.setdlopenflags(dlflags)
%}
// Ignore methods that require std::vector of OBAtom.
%ignore OpenBabel::OBMol::FindChildren(std::vector< OBAtom * > &, OBAtom *, OBAtom *);
%ignore OpenBabel::OBResidue::GetAtoms;