[pypy-commit] pypy default: Merged in habnabit/pypy (pull request #455)

arigo pypy.commits at gmail.com
Sat Jun 11 02:48:06 EDT 2016


Author: Armin Rigo <armin.rigo at gmail.com>
Branch: 
Changeset: r85090:38b72e0e5401
Date: 2016-06-11 08:47 +0200
http://bitbucket.org/pypy/pypy/changeset/38b72e0e5401/

Log:	Merged in habnabit/pypy (pull request #455)

	Add sys.{get,set}dlopenflags.

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 = space.int_w(w_flags)
diff --git a/pypy/module/sys/test/test_sysmodule.py b/pypy/module/sys/test/test_sysmodule.py
--- a/pypy/module/sys/test/test_sysmodule.py
+++ b/pypy/module/sys/test/test_sysmodule.py
@@ -445,14 +445,12 @@
 
     def test_dlopenflags(self):
         import sys
-        if hasattr(sys, "setdlopenflags"):
-            assert hasattr(sys, "getdlopenflags")
-            raises(TypeError, sys.getdlopenflags, 42)
-            oldflags = sys.getdlopenflags()
-            raises(TypeError, sys.setdlopenflags)
-            sys.setdlopenflags(oldflags+1)
-            assert sys.getdlopenflags() == oldflags+1
-            sys.setdlopenflags(oldflags)
+        raises(TypeError, sys.getdlopenflags, 42)
+        oldflags = sys.getdlopenflags()
+        raises(TypeError, sys.setdlopenflags)
+        sys.setdlopenflags(oldflags+1)
+        assert sys.getdlopenflags() == oldflags+1
+        sys.setdlopenflags(oldflags)
 
     def test_refcount(self):
         import sys
@@ -610,7 +608,7 @@
 class AppTestSysSettracePortedFromCpython(object):
     def test_sys_settrace(self):
         import sys
-        
+
         class Tracer:
             def __init__(self):
                 self.events = []
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,15 +145,20 @@
         else:
             return lltype.nullptr(rffi.VOIDP.TO)
 
+    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=-1):
         """ 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 = _dlopen_default_mode()
+        elif (mode & (RTLD_LAZY | RTLD_NOW)) == 0:
             mode |= RTLD_NOW
         res = c_dlopen(name, rffi.cast(rffi.INT, mode))
         if not res:
@@ -193,6 +198,11 @@
     DLLHANDLE = rwin32.HMODULE
     RTLD_GLOBAL = None
 
+    def _dlopen_default_mode():
+        """ The default dlopen mode if it hasn't been changed by the user.
+        """
+        return 0
+
     def dlopen(name, mode=-1):
         # mode is unused on windows, but a consistant signature
         res = rwin32.LoadLibrary(name)


More information about the pypy-commit mailing list