[pypy-commit] pypy release-pypy3.5-6.x: Use LoadLibraryEx in loading extension modules, like CPython's _PyImport_FindSharedFuncptr

mattip pypy.commits at gmail.com
Thu Oct 11 17:26:29 EDT 2018


Author: Matti Picus <matti.picus at gmail.com>
Branch: release-pypy3.5-6.x
Changeset: r95202:2dda0ffebf61
Date: 2018-10-07 14:20 +0300
http://bitbucket.org/pypy/pypy/changeset/2dda0ffebf61/

Log:	Use LoadLibraryEx in loading extension modules, like CPython's
	_PyImport_FindSharedFuncptr

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
@@ -93,8 +93,11 @@
 
 if sys.platform == 'win32':
     dash = '_'
+    WIN32 = True
 else:
     dash = ''
+    WIN32 = False
+
 
 def fclose(fp):
     try:
@@ -1671,7 +1674,11 @@
     try:
         ll_libname = rffi.str2charp(path)
         try:
-            dll = rdynload.dlopen(ll_libname, space.sys.dlopenflags)
+            if WIN32:
+                # Allow other DLLs in the same directory with "path"
+                dll = rdynload.dlopenex(ll_libname)
+            else:
+                dll = rdynload.dlopen(ll_libname, space.sys.dlopenflags)
         finally:
             lltype.free(ll_libname, flavor='raw')
     except rdynload.DLOpenError as e:
diff --git a/rpython/rlib/rdynload.py b/rpython/rlib/rdynload.py
--- a/rpython/rlib/rdynload.py
+++ b/rpython/rlib/rdynload.py
@@ -233,6 +233,15 @@
             raise DLOpenError(ustr.encode('utf-8'))
         return res
 
+    def dlopenex(name):
+        res = rwin32.LoadLibraryExA(name)
+        if not res:
+            err = rwin32.GetLastError_saved()
+            ustr = rwin32.FormatErrorW(err)
+            # DLOpenError unicode msg breaks translation of cpyext create_extension_module
+            raise DLOpenError(ustr.encode('utf-8'))
+        return res
+
     def dlclose(handle):
         res = rwin32.FreeLibrary(handle)
         if res:


More information about the pypy-commit mailing list