[pypy-svn] r61676 - in pypy/trunk/pypy/lib: _ctypes app_test/ctypes_tests
afa at codespeak.net
afa at codespeak.net
Mon Feb 9 19:39:18 CET 2009
Author: afa
Date: Mon Feb 9 19:39:16 2009
New Revision: 61676
Modified:
pypy/trunk/pypy/lib/_ctypes/function.py
pypy/trunk/pypy/lib/app_test/ctypes_tests/test_cfuncs.py
Log:
When compiling a function with the STDCALL calling convention,
the function name is of the form _<name>@<n>
Where <n> is the total size of arguments pushed on the stack.
Have ctypes try all possible names.
test_cfuncs.py now passes on Windows
Modified: pypy/trunk/pypy/lib/_ctypes/function.py
==============================================================================
--- pypy/trunk/pypy/lib/_ctypes/function.py (original)
+++ pypy/trunk/pypy/lib/_ctypes/function.py Mon Feb 9 19:39:16 2009
@@ -140,7 +140,23 @@
if self._buffer is not None:
self._ptr = _rawffi.FuncPtr(self._buffer[0], argshapes, resshape)
return self._ptr
- return self.dll._handle.ptr(self.name, argshapes, resshape)
+ cdll = self.dll._handle
+ try:
+ return cdll.ptr(self.name, argshapes, resshape)
+ except AttributeError:
+ if self._flags_ & _rawffi.FUNCFLAG_CDECL:
+ raise
+
+ # For stdcall, try mangled names:
+ # funcname -> _funcname@<n>
+ # where n is 0, 4, 8, 12, ..., 128
+ for i in range(32):
+ mangled_name = "_%s@%d" % (self.name, i*4)
+ try:
+ return cdll.ptr(mangled_name, argshapes, resshape)
+ except AttributeError:
+ pass
+ raise
@staticmethod
def _guess_argtypes(args):
Modified: pypy/trunk/pypy/lib/app_test/ctypes_tests/test_cfuncs.py
==============================================================================
--- pypy/trunk/pypy/lib/app_test/ctypes_tests/test_cfuncs.py (original)
+++ pypy/trunk/pypy/lib/app_test/ctypes_tests/test_cfuncs.py Mon Feb 9 19:39:16 2009
@@ -197,4 +197,5 @@
class TestStdcallCFunctions(TestCFunctions):
def setup_class(cls):
+ TestCFunctions.setup_class.im_func(cls)
cls._dll = stdcall_dll(_ctypes_test)
More information about the Pypy-commit
mailing list