[pypy-commit] pypy default: Add sys.{get,set}dlopenflags.
Aar...@google.com>
pypy.commits at gmail.com
Sat Jun 11 02:48:18 EDT 2016
Author: "Aaron Gallagher <habnabit at google.com>"
Branch:
Changeset: r85085:2609c88e9f08
Date: 2016-06-08 15:45 -0700
http://bitbucket.org/pypy/pypy/changeset/2609c88e9f08/
Log: Add sys.{get,set}dlopenflags.
Tests already existed for this as part of importing the sys modules
tests from cpython.
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -1512,7 +1512,7 @@
try:
ll_libname = rffi.str2charp(path)
try:
- dll = rdynload.dlopen(ll_libname)
+ dll = rdynload.dlopen(ll_libname, space.sys.dlopenflags)
finally:
lltype.free(ll_libname, flavor='raw')
except rdynload.DLOpenError as e:
diff --git a/pypy/module/sys/__init__.py b/pypy/module/sys/__init__.py
--- a/pypy/module/sys/__init__.py
+++ b/pypy/module/sys/__init__.py
@@ -1,6 +1,7 @@
from pypy.interpreter.mixedmodule import MixedModule
from pypy.interpreter.error import OperationError
from rpython.rlib.objectmodel import we_are_translated
+from rpython.rlib import rdynload
import sys
_WIN = sys.platform == 'win32'
@@ -19,6 +20,7 @@
self.defaultencoding = "ascii"
self.filesystemencoding = None
self.debug = True
+ self.dlopenflags = rdynload._dlopen_default_mode()
interpleveldefs = {
'__name__' : '(space.wrap("sys"))',
@@ -85,7 +87,9 @@
'float_info' : 'system.get_float_info(space)',
'long_info' : 'system.get_long_info(space)',
- 'float_repr_style' : 'system.get_float_repr_style(space)'
+ 'float_repr_style' : 'system.get_float_repr_style(space)',
+ 'getdlopenflags' : 'system.getdlopenflags',
+ 'setdlopenflags' : 'system.setdlopenflags',
}
if sys.platform == 'win32':
diff --git a/pypy/module/sys/system.py b/pypy/module/sys/system.py
--- a/pypy/module/sys/system.py
+++ b/pypy/module/sys/system.py
@@ -58,3 +58,9 @@
def get_float_repr_style(space):
return space.wrap("short")
+
+def getdlopenflags(space):
+ return space.wrap(space.sys.dlopenflags)
+
+def setdlopenflags(space, w_flags):
+ space.sys.dlopenflags = w_flags
diff --git a/rpython/rlib/rdynload.py b/rpython/rlib/rdynload.py
--- a/rpython/rlib/rdynload.py
+++ b/rpython/rlib/rdynload.py
@@ -26,7 +26,7 @@
if _MAC_OS:
pre_include_bits = ['#define MACOSX']
-else:
+else:
pre_include_bits = []
if _FREEBSD or _NETBSD or _WIN32:
@@ -145,14 +145,17 @@
else:
return lltype.nullptr(rffi.VOIDP.TO)
- def dlopen(name, mode=-1):
+ def _dlopen_default_mode():
+ """ The default dlopen mode if it hasn't been changed by the user.
+ """
+ mode = RTLD_NOW
+ if RTLD_LOCAL is not None:
+ mode |= RTLD_LOCAL
+ return mode
+
+ def dlopen(name, mode):
""" Wrapper around C-level dlopen
"""
- if mode == -1:
- if RTLD_LOCAL is not None:
- mode = RTLD_LOCAL
- else:
- mode = 0
if (mode & (RTLD_LAZY | RTLD_NOW)) == 0:
mode |= RTLD_NOW
res = c_dlopen(name, rffi.cast(rffi.INT, mode))
@@ -193,7 +196,12 @@
DLLHANDLE = rwin32.HMODULE
RTLD_GLOBAL = None
- def dlopen(name, mode=-1):
+ def _dlopen_default_mode():
+ """ The default dlopen mode if it hasn't been changed by the user.
+ """
+ return 0
+
+ def dlopen(name, mode):
# mode is unused on windows, but a consistant signature
res = rwin32.LoadLibrary(name)
if not res:
More information about the pypy-commit
mailing list