[pypy-commit] pypy disable_pythonapi: implement windows sys.dllhandle as a _rawffi.alt.CDLL
mattip
noreply at buildbot.pypy.org
Sun Jun 22 21:39:49 CEST 2014
Author: mattip <matti.picus at gmail.com>
Branch: disable_pythonapi
Changeset: r72138:8c81f5d58b5c
Date: 2014-06-22 21:03 +0300
http://bitbucket.org/pypy/pypy/changeset/8c81f5d58b5c/
Log: implement windows sys.dllhandle as a _rawffi.alt.CDLL
which makes cpython.pythonapi on windows equivalent to linux
diff --git a/pypy/module/_rawffi/alt/interp_funcptr.py b/pypy/module/_rawffi/alt/interp_funcptr.py
--- a/pypy/module/_rawffi/alt/interp_funcptr.py
+++ b/pypy/module/_rawffi/alt/interp_funcptr.py
@@ -312,7 +312,7 @@
# ========================================================================
class W_CDLL(W_Root):
- def __init__(self, space, name, mode):
+ def __init__(self, space, name, mode, handle = rffi.VOIDP):
self.flags = libffi.FUNCFLAG_CDECL
self.space = space
if name is None:
@@ -320,7 +320,7 @@
else:
self.name = name
try:
- self.cdll = libffi.CDLL(name, mode)
+ self.cdll = libffi.CDLL(name, mode, handle=handle)
except DLOpenError, e:
raise wrap_dlopenerror(space, e, self.name)
diff --git a/pypy/module/sys/vm.py b/pypy/module/sys/vm.py
--- a/pypy/module/sys/vm.py
+++ b/pypy/module/sys/vm.py
@@ -244,10 +244,8 @@
handle = space.fromcache(State).get_pythonapi_handle()
# Make a dll object with it
- from pypy.module._rawffi.interp_rawffi import W_CDLL
- from rpython.rlib.clibffi import RawCDLL
- cdll = RawCDLL(handle)
- return space.wrap(W_CDLL(space, "python api", cdll))
+ from pypy.module._rawffi.alt.interp_funcptr import W_CDLL
+ return space.wrap(W_CDLL(space, "python api", -1, handle=handle))
def getsizeof(space, w_object, w_default=None):
"""Not implemented on PyPy."""
diff --git a/rpython/rlib/libffi.py b/rpython/rlib/libffi.py
--- a/rpython/rlib/libffi.py
+++ b/rpython/rlib/libffi.py
@@ -11,7 +11,7 @@
from rpython.rlib.clibffi import FUNCFLAG_CDECL, FUNCFLAG_STDCALL, \
AbstractFuncPtr, push_arg_as_ffiptr, c_ffi_call, FFI_TYPE_STRUCT
from rpython.rlib.rdynload import dlopen, dlclose, dlsym, dlsym_byordinal
-from rpython.rlib.rdynload import DLLHANDLE
+from rpython.rlib.rdynload import DLLHANDLE, _WIN32
import os
@@ -413,9 +413,12 @@
# XXX: it partially duplicate the code in clibffi.py
class CDLL(object):
- def __init__(self, libname, mode=-1):
+ def __init__(self, libname, mode=-1, handle=rffi.VOIDP):
"""Load the library, or raises DLOpenError."""
self.lib = rffi.cast(DLLHANDLE, 0)
+ if handle is not rffi.VOIDP :
+ self.lib = rffi.cast(DLLHANDLE, handle)
+ return
with rffi.scoped_str2charp(libname) as ll_libname:
self.lib = dlopen(ll_libname, mode)
diff --git a/rpython/rlib/test/test_libffi.py b/rpython/rlib/test/test_libffi.py
--- a/rpython/rlib/test/test_libffi.py
+++ b/rpython/rlib/test/test_libffi.py
@@ -186,6 +186,24 @@
chain.arg(10)
sleep.call(chain, lltype.Void, is_struct=False)
+ def test_dll_create(self):
+ if os.name == 'nt':
+ import sys
+ if not isinstance(sys.dllhandle, int):
+ py.test.skip('Run with cpython, not pypy')
+ dll = CDLL(None, handle=sys.dllhandle)
+ else:
+ dll = CDLL(None)
+ try:
+ # The pythonapi of the translating python
+ dll.getaddressindll('Py_OptimizeFlag')
+ except KeyError:
+ try:
+ dll.getaddressindll('PyPy_OptimizeFlag')
+ except KeyError:
+ assert False, 'could not find function in pythonapi'
+
+
class TestLibffiCall(BaseFfiTest):
"""
Test various kind of calls through libffi.
More information about the pypy-commit
mailing list