ctypes-commit Mailing List for ctypes (Page 102)
Brought to you by:
theller
You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
(8) |
May
(90) |
Jun
(143) |
Jul
(106) |
Aug
(94) |
Sep
(84) |
Oct
(163) |
Nov
(60) |
Dec
(58) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(128) |
Feb
(79) |
Mar
(227) |
Apr
(192) |
May
(179) |
Jun
(41) |
Jul
(53) |
Aug
(103) |
Sep
(28) |
Oct
(38) |
Nov
(81) |
Dec
(17) |
2006 |
Jan
(184) |
Feb
(111) |
Mar
(188) |
Apr
(67) |
May
(58) |
Jun
(123) |
Jul
(73) |
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
From: Thomas H. <th...@us...> - 2004-07-16 16:05:11
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10908 Added Files: ChangeLog Log Message: Separate ChangeLog for ctypes.com. --- NEW FILE: ChangeLog --- 2004-07-16 Thomas Heller <th...@py...> * __init__.py: More useful debug info from IUnknown.QueryInterface and ClassFactory.CreateInstance calls. New interface_name(iid) function, which returns a COM interface name from it's iid. |
From: Thomas H. <th...@us...> - 2004-07-16 16:03:33
|
Update of /cvsroot/ctypes/ctypes/win32/com/samples/server/IExplorer In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10566/IExplorer Log Message: Directory /cvsroot/ctypes/ctypes/win32/com/samples/server/IExplorer added to the repository |
From: Thomas H. <th...@us...> - 2004-07-16 16:02:20
|
Update of /cvsroot/ctypes/ctypes/win32/com/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10315 Modified Files: readtlb.py Log Message: Output interfaces in order. (Forward port from older branch.) Index: readtlb.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/tools/readtlb.py,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** readtlb.py 15 Jun 2004 09:20:26 -0000 1.27 --- readtlb.py 16 Jul 2004 16:02:06 -0000 1.28 *************** *** 738,749 **** print >> ofi, "#" * 78 interfaces = self.interfaces.values() ! # We *try* to sort the interfaces so that dependencies are ! # satisfied. If this fails, the generated file must be ! # fixed manually (although I'm not sure this is always ! # possible). ! interfaces.sort(self.depends) ! for itf in interfaces: ! print >> ofi ! print >> ofi, itf.declaration() if self.records: --- 738,763 ---- print >> ofi, "#" * 78 interfaces = self.interfaces.values() ! ! if 1: ! done = ["IUnknown", "IDispatch", "dispinterface"] ! while interfaces: ! interfaces = [i for i in interfaces if i.name not in done] ! for itf in interfaces: ! for b in itf._uses: ! if b not in done: ! break ! else: ! print >> ofi ! print >> ofi, itf.declaration() ! done.append(itf.name) ! else: ! # We *try* to sort the interfaces so that dependencies are ! # satisfied. If this fails, the generated file must be ! # fixed manually (although I'm not sure this is always ! # possible). ! interfaces.sort(self.depends) ! for itf in interfaces: ! print >> ofi ! print >> ofi, itf.declaration() if self.records: *************** *** 761,765 **** # The definition of the interfaces contains method lists. if self.interfaces: ! for itf in interfaces: print >> ofi print >> ofi, itf.definition() --- 775,779 ---- # The definition of the interfaces contains method lists. if self.interfaces: ! for itf in self.interfaces.values(): print >> ofi print >> ofi, itf.definition() *************** *** 785,789 **** path = r"c:\windows\system32\shdocvw.dll" ## path = r"c:\Programme\Microsoft Office\Office\MSO97.DLL" ! path = r"c:\Programme\Microsoft Office\Office\MSWORD8.OLB" ## path = r"c:\windows\system32\msi.dll" --- 799,803 ---- path = r"c:\windows\system32\shdocvw.dll" ## path = r"c:\Programme\Microsoft Office\Office\MSO97.DLL" ! ## path = r"c:\Programme\Microsoft Office\Office\MSWORD8.OLB" ## path = r"c:\windows\system32\msi.dll" *************** *** 798,802 **** ## path = r"c:\windows\system32\hnetcfg.dll" ## path = r"C:\WINDOWS\System32\MSHFLXGD.OCX" ! path = r"c:\windows\system32\scrrun.dll" import time start = time.clock() --- 812,816 ---- ## path = r"c:\windows\system32\hnetcfg.dll" ## path = r"C:\WINDOWS\System32\MSHFLXGD.OCX" ! ## path = r"c:\windows\system32\scrrun.dll" import time start = time.clock() |
From: Thomas H. <th...@us...> - 2004-07-16 15:59:25
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9559 Modified Files: server.py Log Message: Clean up debug prints. Index: server.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/server.py,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** server.py 21 Apr 2004 18:07:33 -0000 1.18 --- server.py 16 Jul 2004 15:59:16 -0000 1.19 *************** *** 88,92 **** Logger.install() ! print "DllGetClassObject %s" % ((rclsid, riid, ppv),) # This function is called by C code, and receives C integers as --- 88,93 ---- Logger.install() ! if __debug__: ! dprint("DllGetClassObject %s" % ((rclsid, riid, ppv),)) # This function is called by C code, and receives C integers as *************** *** 123,130 **** # XXX TODO: Read about inproc server refcounting in Don Box if g_locks: ! dprint("* DllCanUnloadNow -> S_FALSE", _active_objects) return S_FALSE else: ! dprint("* DllCanUnloadNow -> S_OK") return S_OK # Hm Call ole32.CoUnitialize here? --- 124,133 ---- # XXX TODO: Read about inproc server refcounting in Don Box if g_locks: ! if __debug__: ! dprint("* DllCanUnloadNow -> S_FALSE", _active_objects) return S_FALSE else: ! if __debug__: ! dprint("* DllCanUnloadNow -> S_OK", _active_objects) return S_OK # Hm Call ole32.CoUnitialize here? *************** *** 156,160 **** def AddRef(self, this): self._refcnt += 1 - ## dprint("AddRef", self, self._refcnt) ##?## self._factory.LockServer(None, 1) return self._refcnt --- 159,162 ---- *************** *** 162,166 **** def Release(self, this): self._refcnt -= 1 - ## dprint("Release", self, self._refcnt) ##?## self._factory.LockServer(None, 0) return self._refcnt --- 164,167 ---- *************** *** 172,176 **** else: g_locks -= 1 ! dprint("LockServer", fLock, g_locks) ################################################################ --- 173,178 ---- else: g_locks -= 1 ! if __debug__: ! dprint("LockServer", fLock, g_locks) ################################################################ |
From: Thomas H. <th...@us...> - 2004-07-16 15:53:57
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8132 Modified Files: ole.py Log Message: Correct the IOleWindow.GetWindow method definition. Index: ole.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/ole.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ole.py 21 Apr 2004 18:07:34 -0000 1.6 --- ole.py 16 Jul 2004 15:53:48 -0000 1.7 *************** *** 75,79 **** _iid_ = GUID("{00000114-0000-0000-C000-000000000046}") _methods_ = IUnknown._methods_ + [ ! STDMETHOD(HRESULT, "GetWindow", POINTER(c_int)), STDMETHOD(HRESULT, "ContextSensitiveHelp", c_int)] --- 75,79 ---- _iid_ = GUID("{00000114-0000-0000-C000-000000000046}") _methods_ = IUnknown._methods_ + [ ! STDMETHOD(HRESULT, "GetWindow", POINTER(HWND)), STDMETHOD(HRESULT, "ContextSensitiveHelp", c_int)] |
From: Thomas H. <th...@us...> - 2004-07-16 15:52:46
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7900 Modified Files: mallocspy.py Log Message: Index: mallocspy.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/mallocspy.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** mallocspy.py 30 Jun 2004 20:05:01 -0000 1.2 --- mallocspy.py 16 Jul 2004 15:52:37 -0000 1.3 *************** *** 62,65 **** --- 62,67 ---- if fSpyed: del self.blocks [pRequest] + else: + print "PreFree", pRequest, fSpyed return pRequest |
From: Thomas H. <th...@us...> - 2004-07-16 15:49:52
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7313 Modified Files: hresult.py Log Message: Add E_INVALIDARG. Index: hresult.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/hresult.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** hresult.py 30 Jun 2004 14:02:21 -0000 1.3 --- hresult.py 16 Jul 2004 15:49:41 -0000 1.4 *************** *** 12,15 **** --- 12,16 ---- E_POINTER = 0x80004003 E_FAIL = 0x80004005 + E_INVALIDARG = 0x80070057 CLASS_E_NOAGGREGATION = 0x80040110 |
From: Thomas H. <th...@us...> - 2004-07-16 15:43:03
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5920 Modified Files: __init__.py Log Message: Small cleanups. A new CreateGuid() function which returns a new GUID. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/__init__.py,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** __init__.py 16 Jul 2004 15:32:24 -0000 1.37 --- __init__.py 16 Jul 2004 15:42:52 -0000 1.38 *************** *** 4,7 **** --- 4,9 ---- from ctypes.wintypes import DWORD, WORD, BYTE + DEBUG = __debug__ # enable debugging output (via Windows' OutputDebugString) + HRESULT = _ctypes.HRESULT CopyComPointer = windll[_ctypes.__file__].CopyComPointer *************** *** 54,58 **** s = (c_wchar * 39)() ole32.StringFromGUID2(byref(self), s, 39) ! return "<guid:%s>" % s.value def __str__(self): --- 56,60 ---- s = (c_wchar * 39)() ole32.StringFromGUID2(byref(self), s, 39) ! return 'GUID("%s")' % s.value def __str__(self): *************** *** 192,201 **** _iid_ = GUID("{00000000-0000-0000-C000-000000000046}") - PIUnknown = POINTER(IUnknown) - ################################################################ ! # Custom argument checking function for POINTER(PIUnknown) _PyCArgType = type(byref(c_int())) - from ctypes import _Pointer def from_param(self, obj): # We accept two types of arguments here: --- 194,200 ---- _iid_ = GUID("{00000000-0000-0000-C000-000000000046}") ################################################################ ! # Custom argument checking function for POINTER(POINTER(IUnknown)) _PyCArgType = type(byref(c_int())) def from_param(self, obj): # We accept two types of arguments here: *************** *** 205,209 **** issubclass(obj._obj._type_, IUnknown): return obj ! if isinstance(obj, _Pointer) and \ issubclass(obj._type_._type_, IUnknown): return obj --- 204,208 ---- issubclass(obj._obj._type_, IUnknown): return obj ! if isinstance(obj, _ctypes._Pointer) and \ issubclass(obj._type_._type_, IUnknown): return obj *************** *** 215,221 **** # This must be set before it is first used in an argument list # XXX explain reason ! POINTER(PIUnknown).from_param = classmethod(from_param) ! IUnknown._methods_ = [STDMETHOD(HRESULT, "QueryInterface", REFIID, POINTER(PIUnknown)), STDMETHOD(c_ulong, "AddRef"), STDMETHOD(c_ulong, "Release")] --- 214,220 ---- # This must be set before it is first used in an argument list # XXX explain reason ! POINTER(POINTER(IUnknown)).from_param = classmethod(from_param) ! IUnknown._methods_ = [STDMETHOD(HRESULT, "QueryInterface", REFIID, POINTER(POINTER(IUnknown))), STDMETHOD(c_ulong, "AddRef"), STDMETHOD(c_ulong, "Release")] *************** *** 223,228 **** ################################################################ - DEBUG = __debug__ - import _winreg def interface_name(iid): --- 222,225 ---- *************** *** 360,363 **** --- 357,361 ---- def CreateInstance(coclass, interface=None, clsctx = CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER): + # Later: docs, docs if interface is None: interface = coclass._com_interfaces_[0] *************** *** 370,371 **** --- 368,380 ---- byref(p)) return p + + def CreateGuid(): + # Create a new GUID + g = GUID() + ole32.CoCreateGuid(byref(g)) + return g + + PIUnknown = POINTER(IUnknown) # deprecated + + ##if __name__ == "__main__": + ## print CreateGuid() |
From: Thomas H. <th...@us...> - 2004-07-16 15:32:33
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3877 Modified Files: __init__.py Log Message: Some To Do entries, and less noisy with DEBUG == False. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/__init__.py,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** __init__.py 16 Jul 2004 15:25:49 -0000 1.36 --- __init__.py 16 Jul 2004 15:32:24 -0000 1.37 *************** *** 286,289 **** --- 286,293 ---- # interface, including base interfaces ## print str([hasattr(x, "AddRef") and i for i, x in enumerate(proto._argtypes_)]) + + # We still have the problem when a COM method is implemented in Python, + # that we have to call .AddRef on all received COM interface pointers manually. + # This MUST either be fixed here, or in wrap, or in _ctypes' C code. for i in itfclass.mro()[:-3]: func = getattr(self, "%s_%s" % (i.__name__, name), None) *************** *** 301,308 **** def notimpl(self, *args): ! dprint("<E_NOTIMPL> method: %s of %s, args: %s" % \ ! (name, itfclass.__name__, str(args))) return E_NOTIMPL ! dprint("# unimplemented %s for interface %s" % (name, itfclass.__name__)) return notimpl --- 305,314 ---- def notimpl(self, *args): ! if DEBUG: ! dprint("<called E_NOTIMPL method> %s.%s, args: %s" % \ ! (name, itfclass.__name__, str(args))) return E_NOTIMPL ! if DEBUG: ! dprint("# unimplemented %s for interface %s" % (name, itfclass.__name__)) return notimpl *************** *** 322,325 **** --- 328,334 ---- self._com_pointers_.append((iid, itf)) + ################################################################ + # IUnknown methods + def QueryInterface(self, this, refiid, ppiunk): iid = refiid[0] *************** *** 330,335 **** return E_NOINTERFACE - # IUnknown methods - def AddRef(self, this): self._refcnt += 1 --- 339,342 ---- *************** *** 340,343 **** --- 347,354 ---- self._refcnt -= 1 self._factory.LockServer(None, 0) + # Later + ## if self._refcnt == 0: + ## import ctypes.com.server + ## ctypes.com.server._active_objects.remove(self) return self._refcnt |
From: Thomas H. <th...@us...> - 2004-07-16 15:25:57
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2324 Modified Files: __init__.py Log Message: Silence pychecker (somewhat), display HEX result from QueryInterface and CreateInstance. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/__init__.py,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** __init__.py 16 Jul 2004 15:15:14 -0000 1.35 --- __init__.py 16 Jul 2004 15:25:49 -0000 1.36 *************** *** 31,35 **** # the purpose of this function is to ensure that no com object # pointers are in sys.exc_info() ! try: 1/0 except: pass --- 31,35 ---- # the purpose of this function is to ensure that no com object # pointers are in sys.exc_info() ! try: 1//0 except: pass *************** *** 243,263 **** from ctypes.com.server import dprint if name == "QueryInterface": ! def wrapped(this, *args): result = func(this, *args) ! dprint("<method call> %s.%s(%s) -> %s" % \ (itfclass.__name__, name, interface_name(args[0][0]), result)) return result elif name == "CreateInstance": ! def wrapped(this, *args): ! result = func(this, *args) ! dprint("<method call> %s.%s(%s) -> %s" % \ ! (itfclass.__name__, name, _itf_name(args[1][0]), result)) ! return result ! else: ! def wrapped(this, *args): result = func(this, *args) ! dprint("<method call> %s.%s -> %s" % \ ! (itfclass.__name__, name, result)) return result return wrapped --- 243,264 ---- from ctypes.com.server import dprint if name == "QueryInterface": ! def wrapped_QI(this, *args): result = func(this, *args) ! dprint("<method call> %s.%s(%s) -> 0x%x" % \ (itfclass.__name__, name, interface_name(args[0][0]), result)) return result + return wrapped_QI elif name == "CreateInstance": ! def wrapped_CI(this, *args): result = func(this, *args) ! dprint("<method call> %s.%s(%s) -> 0x%x" % \ ! (itfclass.__name__, name, interface_name(args[1][0]), result)) return result + return wrapped_CI + def wrapped(this, *args): + result = func(this, *args) + dprint("<method call> %s.%s -> %s" % \ + (itfclass.__name__, name, result)) + return result return wrapped *************** *** 265,268 **** --- 266,270 ---- _refcnt = 0 _factory = None + _com_interfaces_ = [] # should be replaced in subclasses def _get_registrar(cls): |
From: Thomas H. <th...@us...> - 2004-07-16 15:15:23
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32566 Modified Files: __init__.py Log Message: Extend, and somewhat document, the _wrap function to provide more useful debug info. New interface_name function, which returns the name of a COM interface from it's iid. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/__init__.py,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** __init__.py 29 Jun 2004 09:59:28 -0000 1.34 --- __init__.py 16 Jul 2004 15:15:14 -0000 1.35 *************** *** 225,240 **** DEBUG = __debug__ def _wrap(func, name, itfclass): from ctypes.com.server import dprint ! def wrapped(self, *args): ! ## dprint("XXX", [hasattr(a, "AddRef") for a in args]) ! result = func(self, *args) ! dprint("<method call> %s.%s -> %s" % \ ! (itfclass.__name__, name, result)) ! return result return wrapped - - class COMObject(object): _refcnt = 0 --- 225,265 ---- DEBUG = __debug__ + import _winreg + def interface_name(iid): + # A handy function which returns the name of an interface from + # it's iid. If the interface is not registered, returns str(iid). + try: + return _winreg.QueryValue(_winreg.HKEY_CLASSES_ROOT, "Interface\\%s" % iid) + except WindowsError: + return str(iid) + + def _wrap(func, name, itfclass): + # This function is called, if DEBUG is True, to wrap a COM + # interface method implementation. For now, it prints method + # calls via Windows' OutputDebugString mechanism, and for the + # QueryInterface and CreateInstance method calls additionally the + # interface requested. This can be very handy in debugging. from ctypes.com.server import dprint ! if name == "QueryInterface": ! def wrapped(this, *args): ! result = func(this, *args) ! dprint("<method call> %s.%s(%s) -> %s" % \ ! (itfclass.__name__, name, interface_name(args[0][0]), result)) ! return result ! elif name == "CreateInstance": ! def wrapped(this, *args): ! result = func(this, *args) ! dprint("<method call> %s.%s(%s) -> %s" % \ ! (itfclass.__name__, name, _itf_name(args[1][0]), result)) ! return result ! else: ! def wrapped(this, *args): ! result = func(this, *args) ! dprint("<method call> %s.%s -> %s" % \ ! (itfclass.__name__, name, result)) ! return result return wrapped class COMObject(object): _refcnt = 0 |
From: Thomas H. <th...@us...> - 2004-06-30 20:05:53
|
Update of /cvsroot/ctypes/ctypes/build/lib.win32-2.4 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9983 Modified Files: _ctypes_test.pyd _ctypes.pyd Log Message: Recompiled, to bring them up to date. Index: _ctypes_test.pyd =================================================================== RCS file: /cvsroot/ctypes/ctypes/build/lib.win32-2.4/_ctypes_test.pyd,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 Binary files /tmp/cvshMxwzn and /tmp/cvsVKaDM7 differ Index: _ctypes.pyd =================================================================== RCS file: /cvsroot/ctypes/ctypes/build/lib.win32-2.4/_ctypes.pyd,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 Binary files /tmp/cvsTXKuxQ and /tmp/cvs3lie2A differ |
From: Thomas H. <th...@us...> - 2004-06-30 20:05:43
|
Update of /cvsroot/ctypes/ctypes/build/lib.win32-2.3 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9918 Modified Files: _ctypes_test.pyd _ctypes.pyd Log Message: Recompiled, to bring them up to date. Index: _ctypes_test.pyd =================================================================== RCS file: /cvsroot/ctypes/ctypes/build/lib.win32-2.3/_ctypes_test.pyd,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 Binary files /tmp/cvswwwHib and /tmp/cvssOco4M differ Index: _ctypes.pyd =================================================================== RCS file: /cvsroot/ctypes/ctypes/build/lib.win32-2.3/_ctypes.pyd,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 Binary files /tmp/cvsTSz2Jz and /tmp/cvsY3UMNb differ |
From: Thomas H. <th...@us...> - 2004-06-30 20:05:12
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9795 Modified Files: mallocspy.py Log Message: Add a CoGetMalloc convenience functions. Index: mallocspy.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/mallocspy.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** mallocspy.py 30 Jun 2004 14:08:38 -0000 1.1 --- mallocspy.py 30 Jun 2004 20:05:01 -0000 1.2 *************** *** 106,111 **** active = self.active_blocks() if active: ! m = POINTER(IMalloc)() ! ole32.CoGetMalloc(1, byref(m)) if warn: print "%d Allocated Memory Blocks:" % len(active) --- 106,110 ---- active = self.active_blocks() if active: ! m = CoGetMalloc() if warn: print "%d Allocated Memory Blocks:" % len(active) *************** *** 116,119 **** --- 115,123 ---- m.Free(c_voidp(block)) + def CoGetMalloc(): + m = POINTER(IMalloc)() + ole32.CoGetMalloc(1, byref(m)) + return m + ################################################################ |
From: Thomas H. <th...@us...> - 2004-06-30 20:04:20
|
Update of /cvsroot/ctypes/ctypes/unittests/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9661 Modified Files: test_sysalloc.py Log Message: More tests, more comments. Index: test_sysalloc.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/com/test_sysalloc.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_sysalloc.py 30 Jun 2004 14:05:09 -0000 1.1 --- test_sysalloc.py 30 Jun 2004 20:04:12 -0000 1.2 *************** *** 2,49 **** from ctypes import * from ctypes.com import mallocspy, ole32 - # We init COM before each test, and uninit afterwards - ole32.CoUninitialize() ! class BSTRTest(unittest.TestCase): def setUp(self): self.mallocspy = mallocspy.MallocSpy() self.mallocspy.register() def tearDown(self): ! self.mallocspy.revoke(warn=0) ################ def test_leak(self): - ole32.CoInitialize(None) - # Allocate 10 BSTR's without freeing them, and make sure the # leak is detected for i in range(10): ! windll.oleaut32.SysAllocString(unicode("Python is cool")) ! ole32.CoUninitialize() ! ! self.failUnlessEqual(len(self.mallocspy.active_blocks()), 10) ! ! def test_noleak(self): ! ole32.CoInitialize(None) # Allocate 10 BSTR's then free them, and make sure *no* leak # is detected L = [] for i in range(10): ! b = windll.oleaut32.SysAllocString(unicode("Python is cool")) L.append(b) - for b in L: windll.oleaut32.SysFreeString(b) ! ole32.CoUninitialize() - self.failUnlessEqual(self.mallocspy.active_blocks(), {}) - ################################################################ if __name__ == "__main__": unittest.main() - --- 2,111 ---- from ctypes import * from ctypes.com import mallocspy, ole32 + from ctypes.com.automation import BSTR ! # We init COM before each test, and uninit afterwards. ! # So we must start UN-initialized! ! ole32.CoUninitialize() ! ! class MallocSpyTest(unittest.TestCase): def setUp(self): + self.expect = None self.mallocspy = mallocspy.MallocSpy() self.mallocspy.register() + ole32.CoInitialize(None) def tearDown(self): ! try: ! # Even if tests fail or crash, we have to make sure we can ! # shutdown safely. The problem is that mallocspy cannot be ! # revoked completely while there are still unfreed memory ! # blocks which have been allocated while it was registered. ! # ! # So, we must delete *all* COM objects we still have anywhere, ! # even if an error occurred somewhere, and then shutdown COM, ! # BEFORE Python exits. ! try: 1/0 ! except: pass ! ! ole32.CoUninitialize() ! # Now, check the desired test outcome: ! self.failUnlessEqual(len(self.mallocspy.active_blocks()), self.expect) ! finally: ! self.mallocspy.revoke(warn=0) ################ def test_leak(self): # Allocate 10 BSTR's without freeing them, and make sure the # leak is detected for i in range(10): ! windll.oleaut32.SysAllocString(unicode("Python is cool %s" % i)) ! self.expect = 10 + def test_no_leak(self): # Allocate 10 BSTR's then free them, and make sure *no* leak # is detected L = [] for i in range(10): ! b = windll.oleaut32.SysAllocString(unicode("Python is cool %s" % i)) L.append(b) for b in L: windll.oleaut32.SysFreeString(b) ! self.expect = 0 ! ! def test_GetString_C(self): ! import _ctypes_test ! ! # GetString is this function, implemented in C: ! # ! # EXPORT(void) GetString(BSTR *pbstr) ! # { ! # *pbstr = SysAllocString(L"Goodbye!"); ! # } ! GetString = cdll[_ctypes_test.__file__].GetString ! ! # XXX Explain why we cannot create b outside the loop! ! # And why we cannot do anything against this :-) ! for i in range(32): ! b = BSTR() ! GetString(byref(b)) ! ! self.expect = 0 ! ! def test_GetString_Python(self): ! # Same test as before, but with ctypes implemented C function ! PROTO = WINFUNCTYPE(None, POINTER(BSTR), c_int) ! ! def func(pbstr, i): ! pbstr[0] = "%s %s" % ("Spam, spam, and spam", i) ! ! func = PROTO(func) ! ! for i in range(32): ! b = BSTR() ! func(byref(b), i) ! self.failUnlessEqual(b.value, "%s %s" % ("Spam, spam, and spam", i)) ! ! self.expect = 0 ! ! def test_BSTR_alloc(self): ! for i in range(32): ! BSTR(u"Hello World %d" % i) ! self.expect = 0 ! ! def test_BSTR_pointer(self): ! for i in range(32): ! p = pointer(BSTR()) ! p.value = u"Hello World %d" % i ! self.expect = 0 ! ! # Offtopic for this test: ! # XXX These need better error messages: ! ## POINTER(BSTR()) # TypeError: unhashable type ! ## pointer(BSTR) # TypeError: _type_ must have storage info ################################################################ if __name__ == "__main__": unittest.main() |
From: Thomas H. <th...@us...> - 2004-06-30 18:33:26
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23530 Modified Files: MANIFEST.in Log Message: Recursively include unittests/*.py. Index: MANIFEST.in =================================================================== RCS file: /cvsroot/ctypes/ctypes/MANIFEST.in,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** MANIFEST.in 25 Jun 2004 11:13:10 -0000 1.10 --- MANIFEST.in 30 Jun 2004 18:33:18 -0000 1.11 *************** *** 5,9 **** recursive-include source/gcc * ! include unittests/*.py include docs/*.html include docs/*.css --- 5,9 ---- recursive-include source/gcc * ! recursive-include unittests *.py include docs/*.html include docs/*.css |
From: Thomas H. <th...@us...> - 2004-06-30 14:09:13
|
Update of /cvsroot/ctypes/ctypes/unittests/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32762 Added Files: test_word.py Log Message: Test MSWORD via dynamic Dispatch. --- NEW FILE: test_word.py --- from ctypes.com import hresult from ctypes.com.client import Dispatch import unittest class Word(unittest.TestCase): def test_word(self): try: word = Dispatch("Word.Application") except WindowsError, details: if details.errno == hresult.CO_E_CLASSSTRING: self.fail("It seems Word is not installed...") raise word.Visible = 1 doc = word.Documents.Add() wrange = doc.Range() for i in range(10): wrange.InsertAfter("Hello from ctypes via COM %d\n" % i) paras = doc.Paragraphs for i in range(len(paras)): p = paras[i]() p.Font.ColorIndex = i+1 p.Font.Size = 12 + (2 * i) doc.Close(SaveChanges=0) word.Quit() if __name__ == '__main__': unittest.main() |
From: Thomas H. <th...@us...> - 2004-06-30 14:08:46
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32652 Added Files: mallocspy.py Log Message: IMalloc and IMallocSpy, plus a MallocSpy object. --- NEW FILE: mallocspy.py --- from ctypes import * from ctypes.wintypes import BOOL from ctypes.com import CreateInstance, GUID, ole32, IUnknown, \ STDMETHOD, HRESULT, REFIID, COMObject from ctypes.com.hresult import TYPE_E_ELEMENTNOTFOUND class IMalloc(IUnknown): _iid_ = GUID("{00000002-0000-0000-C000-000000000046}") _methods_ = IUnknown._methods_ + [ STDMETHOD(c_voidp, "Alloc", c_ulong), STDMETHOD(c_voidp, "Realloc", c_voidp, c_ulong), STDMETHOD(None, "Free", c_voidp), STDMETHOD(c_ulong, "GetSize", c_voidp), STDMETHOD(c_int, "DidAlloc", c_voidp), STDMETHOD(None, "HeapMinimize")] class IMallocSpy(IUnknown): _iid_ = GUID("{0000001D-0000-0000-C000-000000000046}") _methods_ = IUnknown._methods_ + [ STDMETHOD(c_ulong, "PreAlloc", c_ulong), STDMETHOD(c_voidp, "PostAlloc", c_voidp), STDMETHOD(c_voidp, "PreFree", c_voidp, BOOL), STDMETHOD(None, "PostFree", BOOL), STDMETHOD(c_ulong, "PreRealloc", c_voidp, c_ulong, POINTER(c_voidp), BOOL), STDMETHOD(c_voidp, "PostRealloc", c_voidp, BOOL), STDMETHOD(c_voidp, "PreGetSize", c_voidp, BOOL), STDMETHOD(c_ulong, "PostGetSize", c_ulong, BOOL), STDMETHOD(c_voidp, "PreDidAlloc", c_voidp, BOOL), STDMETHOD(c_int, "PostDidAlloc", c_voidp, BOOL, c_int), STDMETHOD(None, "PreHeapMinimize"), STDMETHOD(None, "PostHeapMinimize")] class MallocSpy(COMObject): _com_interfaces_ = [IMallocSpy] def __init__(self): self.blocks = {} super(MallocSpy, self).__init__() def AddRef(self, this): self._refcnt += 1 return self._refcnt def Release(self, this): self._refcnt -= 1 return self._refcnt ################ # keep track of allocated blocks and size def PreAlloc(self, this, cbRequest): self.cbRequest = cbRequest return cbRequest def PostAlloc(self, this, pActual): self.blocks[pActual] = self.cbRequest del self.cbRequest return pActual def PreFree(self, this, pRequest, fSpyed): if fSpyed: del self.blocks [pRequest] return pRequest def PostFree(self, this, fSpyed): pass def PreGetSize(self, this, pRequest, fSpyed): return pRequest def PostGetSize(self, this, cbActual, fSpyed): return cbActual def PreRealloc(self, this, pRequest, cbRequest, ppNewRequest, fSpyed): return cbRequest def PostRealloc(self, this, pActual, fSpyed): return pActual def PreDidAlloc(self, this, pRequest, fSpyed): return pRequest def PostDidAlloc(self, this, pRequest, fSpyed, fActual): return fActual def PreHeapMinimize(self, this): pass def PostHeapMinimize(self, this): pass ################ def active_blocks(self): return self.blocks def register(self): oledll.ole32.CoRegisterMallocSpy(byref(self._com_pointers_[0][1])) def revoke(self, warn=1): self.release_all(warn=warn) oledll.ole32.CoRevokeMallocSpy() def release_all(self, warn=1): active = self.active_blocks() if active: m = POINTER(IMalloc)() ole32.CoGetMalloc(1, byref(m)) if warn: print "%d Allocated Memory Blocks:" % len(active) for block, size in active.items(): didalloc = m.DidAlloc(c_voidp(block)) print "\t%d bytes at %08X" % (size, block), didalloc for block, size in active.items(): m.Free(c_voidp(block)) ################################################################ if __name__ == "__main__": import ctypes.com from ctypes.com.automation import LoadTypeLib, BSTR def doit(n): tlb = LoadTypeLib(r"c:\windows\system32\shdocvw.dll") for i in xrange(-1, n): name = BSTR() doc = BSTR() help = BSTR() try: tlb.GetDocumentation(i, byref(name), byref(doc), None, byref(help)) except WindowsError, detail: if detail.errno != TYPE_E_ELEMENTNOTFOUND: raise break ## print [name.value, doc.value] mallocspy = MallocSpy() mallocspy.register() try: doit(32000) except: import traceback traceback.print_exc() # Clear sys.exc_info(), in case there are COM objects left try: 1/0 except: pass # Shutdown COM by calling CoUninitialize *now*. # See ctypes.com.__init__.py for details import ctypes.com ctypes.com.__cleaner = None mallocspy.revoke() |
From: Thomas H. <th...@us...> - 2004-06-30 14:05:17
|
Update of /cvsroot/ctypes/ctypes/unittests/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31940 Added Files: test_sysalloc.py Log Message: Testing memory leaks. --- NEW FILE: test_sysalloc.py --- import unittest from ctypes import * from ctypes.com import mallocspy, ole32 # We init COM before each test, and uninit afterwards ole32.CoUninitialize() class BSTRTest(unittest.TestCase): def setUp(self): self.mallocspy = mallocspy.MallocSpy() self.mallocspy.register() def tearDown(self): self.mallocspy.revoke(warn=0) ################ def test_leak(self): ole32.CoInitialize(None) # Allocate 10 BSTR's without freeing them, and make sure the # leak is detected for i in range(10): windll.oleaut32.SysAllocString(unicode("Python is cool")) ole32.CoUninitialize() self.failUnlessEqual(len(self.mallocspy.active_blocks()), 10) def test_noleak(self): ole32.CoInitialize(None) # Allocate 10 BSTR's then free them, and make sure *no* leak # is detected L = [] for i in range(10): b = windll.oleaut32.SysAllocString(unicode("Python is cool")) L.append(b) for b in L: windll.oleaut32.SysFreeString(b) ole32.CoUninitialize() self.failUnlessEqual(self.mallocspy.active_blocks(), {}) ################################################################ if __name__ == "__main__": unittest.main() |
From: Thomas H. <th...@us...> - 2004-06-30 14:02:30
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31325 Modified Files: hresult.py Log Message: New error codes. Index: hresult.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/hresult.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** hresult.py 20 Apr 2004 20:18:18 -0000 1.2 --- hresult.py 30 Jun 2004 14:02:21 -0000 1.3 *************** *** 1,2 **** --- 1,4 ---- + import warnings + warnings.filterwarnings("ignore", category=FutureWarning) # COM success and error codes *************** *** 14,15 **** --- 16,20 ---- CLASS_E_CLASSNOTAVAILABLE = 0x80040111 + TYPE_E_ELEMENTNOTFOUND = 0x8002802B + + CO_E_CLASSSTRING = 0x800401F3 |
From: Thomas H. <th...@us...> - 2004-06-30 14:01:19
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31094 Modified Files: setup.py Log Message: Run the test-directories one after the other. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.86 retrieving revision 1.87 diff -C2 -d -r1.86 -r1.87 *** setup.py 30 Jun 2004 07:36:12 -0000 1.86 --- setup.py 30 Jun 2004 14:01:09 -0000 1.87 *************** *** 190,240 **** self.run_command('build') - test_files = [] for direct in self.test_dirs: mask = os.path.join(direct, self.test_prefix + "*.py") ! test_files.extend(glob.glob(mask)) ! self.announce("testing") ! self.extend_path() ! self.testcases = [] ! self.ok = self.fail = self.errors = 0 ! self.tracebacks = [] ! start_time = time.time() ! for t in test_files: ! testcases = self.run_test(t) ! for case in testcases: ! if self.verbosity > 1: ! print >> sys.stderr, case ! elif self.verbosity == 1: ! if case.endswith("ok"): ! sys.stderr.write(".") ! elif case.endswith("FAIL"): ! sys.stderr.write("F") ! elif case.endswith("ERROR"): ! sys.stderr.write("E") ! else: ! sys.stderr.write("?") ! stop_time = time.time() - print >> sys.stderr - for f in self.tracebacks: - print >> sys.stderr, "=" * 42 - print >> sys.stderr, f[0] - print >> sys.stderr, "-" * 42 - print >> sys.stderr, "\n".join(f[1:]) print >> sys.stderr ! print >> sys.stderr, "-" * 70 ! print >> sys.stderr, "Ran %d tests in %.3fs" % (len(self.testcases), stop_time - start_time) ! print >> sys.stderr ! if self.fail + self.errors == 0: ! print >> sys.stderr, "OK" ! else: ! if self.errors: ! print >> sys.stderr, "FAILED (failures=%d, errors=%d)" % (self.fail, self.errors) else: ! print >> sys.stderr, "FAILED (failures=%d)" % self.fail # run() --- 190,239 ---- self.run_command('build') for direct in self.test_dirs: mask = os.path.join(direct, self.test_prefix + "*.py") ! test_files = glob.glob(mask) ! print "=== Testing in '%s' ===" % direct ! self.extend_path() ! self.testcases = [] ! self.ok = self.fail = self.errors = 0 ! self.tracebacks = [] ! start_time = time.time() ! for t in test_files: ! testcases = self.run_test(t) ! for case in testcases: ! if self.verbosity > 1: ! print >> sys.stderr, case ! elif self.verbosity == 1: ! if case.endswith("ok"): ! sys.stderr.write(".") ! elif case.endswith("FAIL"): ! sys.stderr.write("F") ! elif case.endswith("ERROR"): ! sys.stderr.write("E") ! else: ! sys.stderr.write("?") ! stop_time = time.time() print >> sys.stderr + for f in self.tracebacks: + print >> sys.stderr, "=" * 42 + print >> sys.stderr, f[0] + print >> sys.stderr, "-" * 42 + print >> sys.stderr, "\n".join(f[1:]) + print >> sys.stderr ! print >> sys.stderr, "-" * 70 ! print >> sys.stderr, "Ran %d tests in %.3fs" % (len(self.testcases), stop_time - start_time) ! print >> sys.stderr ! if self.fail + self.errors == 0: ! print >> sys.stderr, "OK" else: ! if self.errors: ! print >> sys.stderr, "FAILED (failures=%d, errors=%d)" % (self.fail, self.errors) ! else: ! print >> sys.stderr, "FAILED (failures=%d)" % self.fail # run() |
From: Thomas H. <th...@us...> - 2004-06-30 07:36:21
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25959 Modified Files: setup.py Log Message: Remove some debug prints. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.85 retrieving revision 1.86 diff -C2 -d -r1.85 -r1.86 *** setup.py 30 Jun 2004 07:28:11 -0000 1.85 --- setup.py 30 Jun 2004 07:36:12 -0000 1.86 *************** *** 195,201 **** test_files.extend(glob.glob(mask)) - import pprint - pprint.pprint(test_files) - self.announce("testing") self.extend_path() --- 195,198 ---- *************** *** 375,379 **** for ext in self.extensions: if ext.name == "_ctypes": - print "INCDIR", incdir ext.include_dirs.append(incdir) ext.include_dirs.append(incdir_2) --- 372,375 ---- |
From: Thomas H. <th...@us...> - 2004-06-30 07:28:34
|
Update of /cvsroot/ctypes/ctypes/unittests/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24533/com Log Message: Directory /cvsroot/ctypes/ctypes/unittests/com added to the repository |
From: Thomas H. <th...@us...> - 2004-06-30 07:28:20
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24479 Modified Files: setup.py Log Message: The 'test-dirs' command line option is now a comma separated list of directories containing test files. Defaults to 'unittests', and on windows to 'unittests,unittests/com'. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.84 retrieving revision 1.85 diff -C2 -d -r1.84 -r1.85 *** setup.py 29 Jun 2004 10:16:51 -0000 1.84 --- setup.py 30 Jun 2004 07:28:11 -0000 1.85 *************** *** 139,144 **** user_options = [ ! ('test-dir=', None, ! "directory that contains the test definitions"), ('test-prefix=', None, "prefix to the testcase filename"), --- 139,144 ---- user_options = [ ! ('test-dirs=', None, ! "comma-separated list of directories that contain the test definitions"), ('test-prefix=', None, "prefix to the testcase filename"), *************** *** 150,156 **** # these are decided only after 'build_base' has its final value # (unless overridden by the user or client) - self.test_dir = 'unittests' self.test_prefix = 'test_' self.verbosity = 1 # initialize_options() --- 150,159 ---- # these are decided only after 'build_base' has its final value # (unless overridden by the user or client) self.test_prefix = 'test_' self.verbosity = 1 + if sys.platform == "win32": + self.test_dirs = r"unittests,unittests\com" + else: + self.test_dirs = "unittests" # initialize_options() *************** *** 167,170 **** --- 170,175 ---- self.build_platlib = build.build_platlib + self.test_dirs = self.test_dirs.split(",") + # finalize_options() *************** *** 185,190 **** self.run_command('build') ! mask = os.path.join(self.test_dir, self.test_prefix + "*.py") ! test_files = [os.path.basename(f) for f in glob.glob(mask)] self.announce("testing") --- 190,200 ---- self.run_command('build') ! test_files = [] ! for direct in self.test_dirs: ! mask = os.path.join(direct, self.test_prefix + "*.py") ! test_files.extend(glob.glob(mask)) ! ! import pprint ! pprint.pprint(test_files) self.announce("testing") *************** *** 197,201 **** start_time = time.time() for t in test_files: ! testcases = self.run_test(os.path.join(self.test_dir, t)) for case in testcases: if self.verbosity > 1: --- 207,211 ---- start_time = time.time() for t in test_files: ! testcases = self.run_test(t) for case in testcases: if self.verbosity > 1: |
From: Thomas H. <th...@us...> - 2004-06-29 10:16:59
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13154 Modified Files: setup.py Log Message: 64-bit Linux needs -fPIC as well. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.83 retrieving revision 1.84 diff -C2 -d -r1.83 -r1.84 *** setup.py 29 Jun 2004 09:41:46 -0000 1.83 --- setup.py 29 Jun 2004 10:16:51 -0000 1.84 *************** *** 109,113 **** platform = get_platform() ! if platform in ["solaris-2.9-sun4u"]: os.environ["CFLAGS"] = "-fPIC" --- 109,113 ---- platform = get_platform() ! if platform in ["solaris-2.9-sun4u", "linux-x86_64"]: os.environ["CFLAGS"] = "-fPIC" |