[pypy-commit] pypy default: Blindly check in this win32 test.
arigo
noreply at buildbot.pypy.org
Wed Aug 31 20:02:03 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r46955:0d75ab342438
Date: 2011-08-31 20:01 +0200
http://bitbucket.org/pypy/pypy/changeset/0d75ab342438/
Log: Blindly check in this win32 test.
diff --git a/pypy/jit/backend/llsupport/descr.py b/pypy/jit/backend/llsupport/descr.py
--- a/pypy/jit/backend/llsupport/descr.py
+++ b/pypy/jit/backend/llsupport/descr.py
@@ -289,6 +289,10 @@
def get_ffi_flags(self):
return self.ffi_flags
+ def get_call_conv(self):
+ from pypy.rlib.clibffi import get_call_conv
+ return get_call_conv(self.ffi_flags)
+
def get_arg_types(self):
return self.arg_classes
diff --git a/pypy/jit/backend/test/runner_test.py b/pypy/jit/backend/test/runner_test.py
--- a/pypy/jit/backend/test/runner_test.py
+++ b/pypy/jit/backend/test/runner_test.py
@@ -2041,6 +2041,57 @@
assert len(glob.lst) > 0
lltype.free(raw, flavor='raw')
+ def test_call_to_winapi_function(self):
+ from pypy.rlib.clibffi import _WIN32, FUNCFLAG_STDCALL
+ if not _WIN32:
+ py.test.skip("Windows test only")
+ from pypy.rlib.libffi import CDLL, types, ArgChain
+ from pypy.rlib.rwin32 import DWORD
+ libc = CDLL('KERNEL32')
+ c_GetCurrentDir = libc.getpointer('GetCurrentDirectoryA',
+ [types.ulong, types.pointer],
+ types.ulong)
+
+ cwd = os.getcwd()
+ buflen = len(cwd) + 10
+ buffer = lltype.malloc(rffi.CCHARP.TO, buflen, flavor='raw')
+ argchain = ArgChain().arg(rffi.cast(DWORD, buflen)).arg(buffer)
+ res = c_GetCurrentDir.call(argchain, DWORD)
+ assert rffi.cast(lltype.Signed, res) == len(cwd)
+ assert rffi.charp2strn(buffer, buflen) == cwd
+ lltype.free(buffer, flavor='raw')
+
+ cpu = self.cpu
+ func_adr = llmemory.cast_ptr_to_adr(c_GetCurrentDir.funcsym)
+ funcbox = ConstInt(heaptracker.adr2int(func_adr))
+ calldescr = cpu.calldescrof_dynamic([types.ulong, types.pointer],
+ types.ulong,
+ EffectInfo.MOST_GENERAL,
+ ffi_flags=FUNCFLAG_STDCALL)
+ i1 = BoxInt()
+ i2 = BoxInt()
+ i3 = BoxInt()
+ tok = BoxInt()
+ faildescr = BasicFailDescr(1)
+ ops = [
+ ResOperation(rop.CALL_RELEASE_GIL, [funcbox, i1, i2], i3,
+ descr=calldescr),
+ ResOperation(rop.GUARD_NOT_FORCED, [], None, descr=faildescr),
+ ResOperation(rop.FINISH, [i3], None, descr=BasicFailDescr(0))
+ ]
+ ops[1].setfailargs([])
+ looptoken = LoopToken()
+ self.cpu.compile_loop([i1, i2], ops, looptoken)
+
+ buffer = lltype.malloc(rffi.CCHARP.TO, buflen, flavor='raw')
+ self.cpu.set_future_value_int(0, buflen)
+ self.cpu.set_future_value_int(1, rffi.cast(lltype.Signed, buffer))
+ fail = self.cpu.execute_token(looptoken)
+ assert fail.identifier == 0
+ assert self.cpu.get_latest_value_int(0) == len(cwd)
+ assert rffi.charp2strn(buffer, buflen) == cwd
+ lltype.free(buffer, flavor='raw')
+
def test_guard_not_invalidated(self):
cpu = self.cpu
i0 = BoxInt()
diff --git a/pypy/rlib/clibffi.py b/pypy/rlib/clibffi.py
--- a/pypy/rlib/clibffi.py
+++ b/pypy/rlib/clibffi.py
@@ -408,6 +408,13 @@
FUNCFLAG_USE_ERRNO = 8
FUNCFLAG_USE_LASTERROR = 16
+def get_call_conv(flags):
+ if _WIN32 and (flags & FUNCFLAG_CDECL == 0):
+ return FFI_STDCALL
+ else:
+ return FFI_DEFAULT_ABI
+
+
class AbstractFuncPtr(object):
ll_cif = lltype.nullptr(FFI_CIFP.TO)
ll_argtypes = lltype.nullptr(FFI_TYPE_PP.TO)
@@ -427,11 +434,6 @@
self.ll_cif = lltype.malloc(FFI_CIFP.TO, flavor='raw',
track_allocation=False) # freed by the __del__
- if _WIN32 and (flags & FUNCFLAG_CDECL == 0):
- cc = FFI_STDCALL
- else:
- cc = FFI_DEFAULT_ABI
-
if _MSVC:
# This little trick works correctly with MSVC.
# It returns small structures in registers
@@ -441,7 +443,7 @@
elif restype.c_size <= 8:
restype = ffi_type_sint64
- res = c_ffi_prep_cif(self.ll_cif, cc,
+ res = c_ffi_prep_cif(self.ll_cif, get_call_conv(flags),
rffi.cast(rffi.UINT, argnum), restype,
self.ll_argtypes)
if not res == FFI_OK:
More information about the pypy-commit
mailing list