Author: Armin Rigo <[email protected]>
Branch:
Changeset: r68200:afb227c80804
Date: 2013-11-18 09:28 +0100
http://bitbucket.org/pypy/pypy/changeset/afb227c80804/
Log: Hack around a FreeBSD issue
diff --git a/rpython/rlib/rdynload.py b/rpython/rlib/rdynload.py
--- a/rpython/rlib/rdynload.py
+++ b/rpython/rlib/rdynload.py
@@ -4,6 +4,7 @@
from rpython.rtyper.tool import rffi_platform
from rpython.rtyper.lltypesystem import rffi
from rpython.rlib.rarithmetic import r_uint
+from rpython.rlib.objectmodel import we_are_translated
from rpython.translator.tool.cbuild import ExternalCompilationInfo
from rpython.translator.platform import platform
@@ -79,6 +80,38 @@
RTLD_NOW = cConfig.RTLD_NOW
RTLD_LAZY = cConfig.RTLD_LAZY
+ _t_opened = {}
+
+ def t_dlopen(name):
+ # for direct execution: can't use the regular way on FreeBSD :-(
+ #
http://factor-language.blogspot.de/2009/02/note-about-libdl-functions-on-netbsd.html
+ import ctypes
+ if name:
+ name = rffi.charp2str(name)
+ else:
+ name = None
+ try:
+ res = ctypes.cdll.LoadLibrary(name)
+ except OSError, e:
+ raise DLOpenError(str(e))
+ h = rffi.cast(rffi.VOIDP, res._handle)
+ _t_opened[rffi.cast(rffi.LONG, h)] = res
+ return h
+
+ def t_dlclose(handle):
+ _t_opened.pop(rffi.cast(rffi.LONG, handle))
+ return rffi.cast(rffi.INT, 0)
+
+ def t_dldym(handle, name):
+ import ctypes
+ lib = _t_opened[rffi.cast(rffi.LONG, handle)]
+ try:
+ symbol = lib[name]
+ except AttributeError:
+ raise KeyError(name)
+ res = ctypes.cast(symbol, ctypes.c_void_p)
+ return rffi.cast(rffi.VOIDP, res.value or 0)
+
def dlerror():
# XXX this would never work on top of ll2ctypes, because
# ctypes are calling dlerror itself, unsure if I can do much in this
@@ -91,6 +124,8 @@
def dlopen(name, mode=-1):
""" Wrapper around C-level dlopen
"""
+ if not we_are_translated():
+ return t_dlopen(name)
if mode == -1:
if RTLD_LOCAL is not None:
mode = RTLD_LOCAL
@@ -104,11 +139,16 @@
raise DLOpenError(err)
return res
- dlclose = c_dlclose
+ def dlclose(handle):
+ if not we_are_translated():
+ return t_dlclose(handle)
+ return c_dlclose(handle)
def dlsym(libhandle, name):
""" Wrapper around C-level dlsym
"""
+ if not we_are_translated():
+ return t_dldym(libhandle, name)
res = c_dlsym(libhandle, name)
if not res:
raise KeyError(name)
diff --git a/rpython/rlib/test/test_rdynload.py
b/rpython/rlib/test/test_rdynload.py
--- a/rpython/rlib/test/test_rdynload.py
+++ b/rpython/rlib/test/test_rdynload.py
@@ -21,3 +21,4 @@
lltype.Signed)), dlsym(lib, 'abs'))
assert 1 == handle(1)
assert 1 == handle(-1)
+ dlclose(lib)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit