Hello,
here are patches against pypy 1.5 so that comtypes works with it
(I hope it is acceptable to post patches here; I have no time to
learn mercurial at the moment).
Thanks,
Thomas
diff -x *.*~ -x *.orig -x *.pyc -ur
c:\pypy-1.5.0a0-win32\lib_pypy/_ctypes/basics.py
c:\pypy\lib_pypy/_ctypes/basics.py
--- c:\pypy-1.5.0a0-win32\lib_pypy/_ctypes/basics.py Thu Mar 24 12:14:58 2011
+++ c:\pypy\lib_pypy/_ctypes/basics.py Tue Jun 07 18:53:13 2011
@@ -123,7 +123,10 @@
return buffer(self._buffer)
def _get_b_base(self):
- return self._base
+ try:
+ return self._base
+ except AttributeError:
+ return None
_b_base_ = property(_get_b_base)
_b_needsfree_ = False
diff -x *.*~ -x *.orig -x *.pyc -ur
c:\pypy-1.5.0a0-win32\lib_pypy/_ctypes/function.py
c:\pypy\lib_pypy/_ctypes/function.py
--- c:\pypy-1.5.0a0-win32\lib_pypy/_ctypes/function.py Fri Apr 29 12:40:36 2011
+++ c:\pypy\lib_pypy/_ctypes/function.py Thu Jun 09 13:50:00 2011
@@ -307,13 +307,13 @@
"native COM method call without 'this' parameter"
)
thisarg = cast(args[0], POINTER(POINTER(c_void_p))).contents
- argtypes = [c_void_p] + list(argtypes)
- args = list(args)
- args[0] = args[0].value
+ thisptr = c_void_p(args[0].value)
+ args, outargs = self._convert_args(argtypes, args[1:], kwargs)
+ args.insert(0, thisptr)
else:
thisarg = None
+ args, outargs = self._convert_args(argtypes, args, kwargs)
- args, outargs = self._convert_args(argtypes, args, kwargs)
argtypes = [type(arg) for arg in args]
restype = self._restype_
@@ -366,6 +366,10 @@
if not outargs:
return result
+ simple_cdata = type(c_void_p()).__bases__[0]
+ outargs = [x.value if type(x).__bases__[0] is simple_cdata else x
+ for x in outargs]
+
if len(outargs) == 1:
return outargs[0]
@@ -443,10 +447,7 @@
total = len(args)
paramflags = self._paramflags
- if self._com_index:
- inargs_idx = 1
- else:
- inargs_idx = 0
+ inargs_idx = 0
if not paramflags and total < len(argtypes):
raise TypeError("not enough arguments")
diff -x *.*~ -x *.orig -x *.pyc -ur
c:\pypy-1.5.0a0-win32\lib_pypy/_ctypes/primitive.py
c:\pypy\lib_pypy/_ctypes/primitive.py
--- c:\pypy-1.5.0a0-win32\lib_pypy/_ctypes/primitive.py Thu Mar 24 12:14:58 2011
+++ c:\pypy\lib_pypy/_ctypes/primitive.py Thu Jun 09 13:49:15 2011
@@ -212,16 +212,18 @@
result.value = property(_getvalue, _setvalue)
elif tp == 'X':
- from ctypes import windll
- SysAllocStringLen = windll.oleaut32.SysAllocStringLen
- SysStringLen = windll.oleaut32.SysStringLen
- SysFreeString = windll.oleaut32.SysFreeString
+ # We must use WinDLL("oleaut32") instead of
+ # windll.oleaut32 because this creates a new instance of
+ # the loaded dll; and we want to have control over the
+ # argtypes and restype attribute of the exposed functions
+ from ctypes import WinDLL
+ oleaut32 = WinDLL("oleaut32")
def _getvalue(self):
addr = self._buffer[0]
if addr == 0:
return None
else:
- size = SysStringLen(addr)
+ size = oleaut32.SysStringLen(addr)
return _rawffi.wcharp2rawunicode(addr, size)
def _setvalue(self, value):
@@ -230,11 +232,11 @@
value = value.decode(ConvMode.encoding,
ConvMode.errors)
array = _rawffi.Array('u')(len(value)+1, value)
- value = SysAllocStringLen(array.buffer, len(value))
+ value = oleaut32.SysAllocStringLen(array.buffer,
len(value))
elif value is None:
value = 0
if self._buffer[0]:
- SysFreeString(self._buffer[0])
+ oleaut.SysFreeString(self._buffer[0])
self._buffer[0] = value
result.value = property(_getvalue, _setvalue)
diff -x *.*~ -x *.orig -x *.pyc -ur
c:\pypy-1.5.0a0-win32\lib_pypy/_ctypes/__init__.py
c:\pypy\lib_pypy/_ctypes/__init__.py
--- c:\pypy-1.5.0a0-win32\lib_pypy/_ctypes/__init__.py Thu Mar 24 12:14:58 2011
+++ c:\pypy\lib_pypy/_ctypes/__init__.py Thu Jun 09 13:26:36 2011
@@ -18,7 +18,14 @@
if _os.name in ("nt", "ce"):
from _rawffi import FormatError
from _rawffi import check_HRESULT as _check_HRESULT
- CopyComPointer = None # XXX
+ def CopyComPointer(src, dst):
+ from ctypes import c_void_p, cast
+ if src:
+ hr = src[0][0].AddRef(src)
+ if hr & 0x80000000:
+ return hr
+ dst[0] = cast(src, c_void_p).value
+ return 0
LoadLibrary = dlopen
from _rawffi import FUNCFLAG_STDCALL, FUNCFLAG_CDECL, FUNCFLAG_PYTHONAPI
_______________________________________________
pypy-dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-dev