Skip to content

Commit 0f5cf1a

Browse files
committed
Attempt to remove the RTLD_GLOBAL hack.
1 parent 78648f1 commit 0f5cf1a

File tree

1 file changed

+2
-36
lines changed

1 file changed

+2
-36
lines changed

heyoka/__init__.py

+2-36
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,11 @@
99
# Version setup.
1010
from ._version import __version__
1111

12-
import os as _os
1312
import cloudpickle as _cloudpickle
1413
from threading import Lock as _Lock
1514

16-
if _os.name == "posix":
17-
# NOTE: on some platforms Python by default opens extensions
18-
# with the RTLD_LOCAL flag, which creates problems because
19-
# public symbols used by heyoka (e.g., sleef functions, quad
20-
# precision math) are then not found by the LLVM jit machinery.
21-
# Thus, before importing core, we temporarily flip on the
22-
# RTLD_GLOBAL flag, which makes the symbols visible and
23-
# solves these issues. Another possible approach suggested
24-
# in the llvm discord is to manually and explicitly add
25-
# libheyoka.so to the DL search path:
26-
# DynamicLibrarySearchGenerator::Load(“/path/to/libheyoka.so”)
27-
# See:
28-
# https://docs.python.org/3/library/ctypes.html
29-
import ctypes as _ctypes
30-
import sys as _sys
31-
32-
_orig_dlopen_flags = _sys.getdlopenflags()
33-
_sys.setdlopenflags(_orig_dlopen_flags | _ctypes.RTLD_GLOBAL)
34-
35-
try:
36-
# We import the sub-modules into the root namespace.
37-
from .core import *
38-
finally:
39-
# Restore the original dlopen flags whatever
40-
# happens.
41-
_sys.setdlopenflags(_orig_dlopen_flags)
42-
43-
del _ctypes
44-
del _sys
45-
del _orig_dlopen_flags
46-
else:
47-
# We import the sub-modules into the root namespace.
48-
from .core import *
49-
50-
del _os
15+
# We import the sub-modules into the root namespace.
16+
from .core import *
5117

5218
# Explicitly import the submodules
5319
# NOTE: it is *important* that the import is performed

0 commit comments

Comments
 (0)