Skip to content

Commit 177eb5d

Browse files
tornariadimpase
authored andcommitted
singular: do not directly dlopen() the singular library
Same as for gap in the previous commit. Instead of requiring the soname (as in sage.env.LIBSINGULAR_PATH) we dlopen() the extension module sage.libs.singular.singular which will indirectly dlopen() libSingular.
1 parent e98eb69 commit 177eb5d

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

src/sage/libs/singular/singular.pyx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,14 +1705,7 @@ cdef object si2sa_intvec(intvec *v):
17051705
cdef extern from *: # hack to get at cython macro
17061706
int unlikely(int)
17071707

1708-
cdef extern from "dlfcn.h":
1709-
void *dlopen(char *, long)
1710-
char *dlerror()
1711-
void dlclose(void *handle)
1712-
1713-
cdef extern from "dlfcn.h":
1714-
cdef long RTLD_LAZY
1715-
cdef long RTLD_GLOBAL
1708+
from posix.dlfcn cimport dlopen, dlclose, dlerror, RTLD_LAZY, RTLD_GLOBAL
17161709

17171710
cdef int overflow_check(unsigned long e, ring *_ring) except -1:
17181711
"""
@@ -1762,8 +1755,6 @@ cdef init_libsingular():
17621755

17631756
cdef void *handle = NULL
17641757

1765-
from sage.env import LIBSINGULAR_PATH
1766-
lib = str_to_bytes(LIBSINGULAR_PATH, FS_ENCODING, "surrogateescape")
17671758

17681759
# This is a workaround for https://github.com/Singular/Singular/issues/1113
17691760
# and can be removed once that fix makes it into release of Singular that
@@ -1780,10 +1771,12 @@ cdef init_libsingular():
17801771

17811772
import platform
17821773
if not platform.system().startswith("CYGWIN"):
1774+
# reload the current module to force reload of libSingular (see #33446)
1775+
lib = str_to_bytes(__loader__.path, FS_ENCODING, "surrogateescape")
17831776
handle = dlopen(lib, RTLD_GLOBAL|RTLD_LAZY)
17841777
if not handle:
17851778
err = dlerror()
1786-
raise ImportError(f"cannot load Singular library from {LIBSINGULAR_PATH} ({err})")
1779+
raise RuntimeError(f"Could not reload Singular library with RTLD_GLOBAL ({err})")
17871780

17881781
# load SINGULAR
17891782
siInit(lib)

0 commit comments

Comments
 (0)