ctypes-commit Mailing List for ctypes (Page 41)
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...> - 2005-08-24 07:12:24
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19338 Added Files: Tag: branch_1_0 test_codegen.py Log Message: Add a simple test for the code generator. --- NEW FILE: test_codegen.py --- import sys, os import unittest import ctypes import _ctypes_test class Test(unittest.TestCase): def test(self): os.system("%s ../ctypes/wrap/h2xml.py -I../source _ctypes_test.h -o _ctypes_test.xml" % \ (sys.executable,)) os.system("%s ../ctypes/wrap/xml2py.py _ctypes_test.xml -o _ctypes_test.py -l%s" % (sys.executable, _ctypes_test.__file__)) lines = [l.rstrip() for l in open("_ctypes_test.py", "r").readlines()] self.failUnlessEqual(lines[2:], EXPECTED[2:]) EXPECTED = r"""# generated by 'xml2py' # flags '_ctypes_test.xml -o _ctypes_test.py -lc:\sf\ctypes_dist\build\lib.win32-2.3\_ctypes_test.pyd' from ctypes import * def _testfunc_i_bhilfd(b, h, i, l, f, d): # ../source/_ctypes_test.h 1 return _testfunc_i_bhilfd._api_(b, h, i, l, f, d) _testfunc_i_bhilfd = cdecl(c_int, '_ctypes_test', [c_char, c_short, c_int, c_long, c_float, c_double]) (_testfunc_i_bhilfd) """.splitlines() if __name__ == "__main__": unittest.main() |
From: Thomas H. <th...@us...> - 2005-08-24 07:11:46
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19134 Added Files: Tag: branch_1_0 _ctypes_test.h Log Message: Declare at least one function from _ctypes_test.c in an include file. --- NEW FILE: _ctypes_test.h --- extern int _testfunc_i_bhilfd(char b, short h, int i, long l, float f, double d); |
From: Thomas H. <th...@us...> - 2005-08-23 19:44:32
|
Update of /cvsroot/ctypes/ctypes/comtypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1188 Modified Files: Tag: branch_1_0 test_ie.py Added Files: Tag: branch_1_0 test_createwrappers.py Log Message: Add some tests, fix some tests. --- NEW FILE: test_createwrappers.py --- import ut import glob import comtypes.typeinfo import comtypes.client # This test takes quite some time. It tried to build wrappers for all # .dll, .tlb, and .ocx in the system directory which contain typelibs. class Test(ut.TestCase): def setUp(self): comtypes.client.gen_dir = None comtypes.client.__verbose__ = False def tearDown(self): comtypes.client.gen_dir = comtypes.client._find_gen_dir() number = 0 def add_test(fname): try: comtypes.typeinfo.LoadTypeLibEx(fname) except WindowsError: return global number def test(self): comtypes.client.CreateModule(fname) test.__doc__ = "CreateModule(%r)" % fname setattr(Test, "test_%d" % number, test) number += 1 # MSADODC.OCX: _Recordset is not defined. for fname in glob.glob(r"c:\windows\system32\*.ocx"): add_test(fname) # MSCALDEV.TLB - UnicodeEncodeError in COM method name for fname in glob.glob(r"c:\windows\system32\*.tlb"): add_test(fname) # msvbvm60.dll Ignoring _HiddenInterface which has no base interface for fname in glob.glob(r"c:\windows\system32\*.dll"): add_test(fname) if __name__ == "__main__": ut.main() Index: test_ie.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/unittests/Attic/test_ie.py,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -C2 -d -r1.1.2.4 -r1.1.2.5 *** test_ie.py 19 Aug 2005 19:43:55 -0000 1.1.2.4 --- test_ie.py 23 Aug 2005 19:44:15 -0000 1.1.2.5 *************** *** 1,3 **** --- 1,4 ---- import ut + from ctypes import * from comtypes.client import CreateObject, GetEvents, ReleaseEvents *************** *** 32,38 **** self._events.append("DocumentComplete") def PumpWaitingMessages(): from ctypes import windll, byref - from ctypes.wintypes import MSG user32 = windll.user32 msg = MSG() --- 33,51 ---- self._events.append("DocumentComplete") + + class POINT(Structure): + _fields_ = [("x", c_long), + ("y", c_long)] + + class MSG(Structure): + _fields_ = [("hWnd", c_ulong), + ("message", c_uint), + ("wParam", c_ulong), + ("lParam", c_ulong), + ("time", c_ulong), + ("pt", POINT)] + def PumpWaitingMessages(): from ctypes import windll, byref user32 = windll.user32 msg = MSG() |
From: Thomas H. <th...@us...> - 2005-08-23 19:42:31
|
Update of /cvsroot/ctypes/ctypes/comtypes/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv898 Modified Files: Tag: branch_1_0 typedesc.py tlbparser.py codegenerator.py Log Message: Fix generation of constants in typelib wrappers. Don't generate functions in typelib wrappers. Index: tlbparser.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/tlbparser.py,v retrieving revision 1.4.2.21 retrieving revision 1.4.2.22 diff -C2 -d -r1.4.2.21 -r1.4.2.22 *** tlbparser.py 23 Aug 2005 19:38:25 -0000 1.4.2.21 --- tlbparser.py 23 Aug 2005 19:42:20 -0000 1.4.2.22 *************** *** 160,163 **** --- 160,166 ---- # functions for i in range(ta.cFuncs): + # We skip all function definitions. There are several + # problems with these, and we can, for comtypes, ignore them. + continue fd = tinfo.GetFuncDesc(i) dllname, func_name, ordinal = tinfo.GetDllEntry(fd.memid, fd.invkind) *************** *** 189,193 **** typ = self.make_type(vd.elemdescVar.tdesc, tinfo) var_value = vd._.lpvarValue[0].value ! v = typedesc.Variable(name, typ, repr(var_value)) self._register(name, v) if var_doc is not None: --- 192,196 ---- typ = self.make_type(vd.elemdescVar.tdesc, tinfo) var_value = vd._.lpvarValue[0].value ! v = typedesc.Constant(name, typ, var_value) self._register(name, v) if var_doc is not None: *************** *** 484,488 **** return # BUG: We try to register an item that's already registered. ! raise ValueError, "Bug: Multiple registered" self.items[fullname] = value --- 487,491 ---- return # BUG: We try to register an item that's already registered. ! raise ValueError, "Bug: Multiple registered name '%s': %r" % (name, value) self.items[fullname] = value *************** *** 497,506 **** tlib = tinfo.GetContainingTypeLib()[0] if tlib != self.tlib: typ = typedesc.External(tlib, name, ! tlib.GetDocumentation(-1)[:2]) ! ta = tinfo.GetTypeAttr() ! typ.size = ta.cbSizeInstance * 8 ! typ.align = ta.cbAlignment * 8 self._register(name, typ, tlib) return typ --- 500,511 ---- tlib = tinfo.GetContainingTypeLib()[0] if tlib != self.tlib: + ta = tinfo.GetTypeAttr() + size = ta.cbSizeInstance * 8 + align = ta.cbAlignment * 8 typ = typedesc.External(tlib, name, ! size, ! align, ! tlib.GetDocumentation(-1)[:2]) self._register(name, typ, tlib) return typ Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/codegenerator.py,v retrieving revision 1.6.2.17 retrieving revision 1.6.2.18 diff -C2 -d -r1.6.2.17 -r1.6.2.18 *** codegenerator.py 18 Aug 2005 14:40:19 -0000 1.6.2.17 --- codegenerator.py 23 Aug 2005 19:42:20 -0000 1.6.2.18 *************** *** 124,127 **** --- 124,134 ---- self._make_module(ext.tlib) + def Constant(self, tp): + print >> self.stream, \ + "%s = %r # Constant %s" % (tp.name, + tp.value, + self.type_name(tp.typ, False)) + self.names.add(tp.name) + def SAFEARRAYType(self, sa): self.generate(sa.typ) Index: typedesc.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/typedesc.py,v retrieving revision 1.1.2.8 retrieving revision 1.1.2.9 diff -C2 -d -r1.1.2.8 -r1.1.2.9 *** typedesc.py 29 Jul 2005 19:46:08 -0000 1.1.2.8 --- typedesc.py 23 Aug 2005 19:42:20 -0000 1.1.2.9 *************** *** 4,13 **** from ctypes.wrap.typedesc import * class External(object): ! def __init__(self, tlib, name, docs=None): # the type library containing the symbol self.tlib = tlib # name of symbol self.symbol_name = name # type lib description self.docs = docs --- 4,21 ---- from ctypes.wrap.typedesc import * + class Constant(object): + def __init__(self, name, typ, value): + self.name = name + self.typ = typ + self.value = value + class External(object): ! def __init__(self, tlib, name, size, align, docs=None): # the type library containing the symbol self.tlib = tlib # name of symbol self.symbol_name = name + self.size = size + self.align = align # type lib description self.docs = docs |
From: Thomas H. <th...@us...> - 2005-08-23 19:41:17
|
Update of /cvsroot/ctypes/ctypes/comtypes/client In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv629 Modified Files: Tag: branch_1_0 __init__.py Log Message: Allow prints to be switched off. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/client/Attic/__init__.py,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** __init__.py 19 Aug 2005 19:43:46 -0000 1.1.2.3 --- __init__.py 23 Aug 2005 19:41:03 -0000 1.1.2.4 *************** *** 100,103 **** --- 100,105 ---- "GetEvents", "ReleaseEvents", "CreateModule"] + __verbose__ = __debug__ + ################################################################ # Determine the directory where generated modules live. *************** *** 231,235 **** # found. Other errors while importing should probably make # this function fail. ! if __debug__: print "# Generating comtypes.gen.%s" % modulename modname = fullname.split(".")[-1] --- 233,237 ---- # found. Other errors while importing should probably make # this function fail. ! if __verbose__: print "# Generating comtypes.gen.%s" % modulename modname = fullname.split(".")[-1] *************** *** 271,275 **** ofi = open(os.path.join(gen_dir, modname + ".py"), "w") # use warnings.warn, maybe? ! if __debug__: print "# Generating comtypes.gen.%s" % modname generate_module(tlib, ofi, CreateModule, _name_module) --- 273,277 ---- ofi = open(os.path.join(gen_dir, modname + ".py"), "w") # use warnings.warn, maybe? ! if __verbose__: print "# Generating comtypes.gen.%s" % modname generate_module(tlib, ofi, CreateModule, _name_module) |
From: Thomas H. <th...@us...> - 2005-08-23 19:40:33
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv458 Modified Files: Tag: branch_1_0 __init__.py Added Files: Tag: branch_1_0 hresult.py Log Message: add comtypes.hresult. --- NEW FILE: hresult.py --- # comtypes.hresult # COM success and error codes # # Note that the codes should be written in decimal notation! S_OK = 0 S_FALSE = 1 E_UNEXPECTED = -2147418113 #0x8000FFFFL E_NOTIMPL = -2147467263 #0x80004001L E_NOINTERFACE = -2147467262 #0x80004002L E_POINTER = -2147467261 #0x80004003L E_FAIL = -2147467259 #0x80004005L E_INVALIDARG = -2147024809 #0x80070057L CLASS_E_NOAGGREGATION = -2147221232 #0x80040110L CLASS_E_CLASSNOTAVAILABLE = -2147221231 #0x80040111L TYPE_E_ELEMENTNOTFOUND = -2147352077 #0x8002802BL CO_E_CLASSSTRING = -2147221005 #0x800401F3L # connection point error codes CONNECT_E_CANNOTCONNECT = -2147220990 CONNECT_E_ADVISELIMIT = -2147220991 CONNECT_E_NOCONNECTION = -2147220992 # DISP_E_... constants are in comtypes.automation Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/__init__.py,v retrieving revision 1.25.2.28 retrieving revision 1.25.2.29 diff -C2 -d -r1.25.2.28 -r1.25.2.29 *** __init__.py 23 Aug 2005 19:37:47 -0000 1.25.2.28 --- __init__.py 23 Aug 2005 19:40:24 -0000 1.25.2.29 *************** *** 19,22 **** --- 19,24 ---- DWORD = c_ulong + from comtypes.hresult import E_NOINTERFACE + ################################################################ # Where should the __ctypes_from_param__ story go? *************** *** 850,855 **** ################################################################ - # XXX - from ctypes.com.hresult import E_NOINTERFACE class COMObject(object): --- 852,855 ---- |
From: Thomas H. <th...@us...> - 2005-08-23 19:38:33
|
Update of /cvsroot/ctypes/ctypes/comtypes/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32471 Modified Files: Tag: branch_1_0 tlbparser.py Log Message: Fix a generation problem with external symbols. Index: tlbparser.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/tlbparser.py,v retrieving revision 1.4.2.20 retrieving revision 1.4.2.21 diff -C2 -d -r1.4.2.20 -r1.4.2.21 *** tlbparser.py 17 Aug 2005 16:30:46 -0000 1.4.2.20 --- tlbparser.py 23 Aug 2005 19:38:25 -0000 1.4.2.21 *************** *** 500,503 **** --- 500,506 ---- name, tlib.GetDocumentation(-1)[:2]) + ta = tinfo.GetTypeAttr() + typ.size = ta.cbSizeInstance * 8 + typ.align = ta.cbAlignment * 8 self._register(name, typ, tlib) return typ |
From: Thomas H. <th...@us...> - 2005-08-23 19:38:02
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32372 Modified Files: Tag: branch_1_0 __init__.py Log Message: Small beautification. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/__init__.py,v retrieving revision 1.25.2.27 retrieving revision 1.25.2.28 diff -C2 -d -r1.25.2.27 -r1.25.2.28 *** __init__.py 19 Aug 2005 18:51:26 -0000 1.25.2.27 --- __init__.py 23 Aug 2005 19:37:47 -0000 1.25.2.28 *************** *** 20,23 **** --- 20,26 ---- ################################################################ + # Where should the __ctypes_from_param__ story go? + # And what would be the 'correct' name for that method? + ################################################################ # constants for object creation CLSCTX_INPROC_SERVER = 1 *************** *** 144,151 **** return value.QueryInterface(cls) # The interface 'cls' is used as a mixin. p = type(_compointer_base)("POINTER(%s)" % cls.__name__, _ptr_bases, ! {"__ctypes_from_outparam__": lambda self: self, "from_param": classmethod(from_param), "__com_interface__": cls}) --- 147,157 ---- return value.QueryInterface(cls) + def __ctypes_from_outparam__(self): + return self + # The interface 'cls' is used as a mixin. p = type(_compointer_base)("POINTER(%s)" % cls.__name__, _ptr_bases, ! {"__ctypes_from_outparam__": __ctypes_from_outparam__, "from_param": classmethod(from_param), "__com_interface__": cls}) |
From: Thomas H. <th...@us...> - 2005-08-22 09:39:03
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv677 Modified Files: Tag: branch_1_0 _ctypes.c Log Message: Fixed another sizeof(int) != sizeof(void*) problem. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.226.2.22 retrieving revision 1.226.2.23 diff -C2 -d -r1.226.2.22 -r1.226.2.23 *** _ctypes.c 22 Aug 2005 09:31:37 -0000 1.226.2.22 --- _ctypes.c 22 Aug 2005 09:38:53 -0000 1.226.2.23 *************** *** 200,209 **** { void *buf; ! if (!PyInt_Check(value)) { PyErr_SetString(PyExc_TypeError, "integer expected"); return NULL; } ! buf = (void *)PyInt_AS_LONG(value); return CData_AtAddress(type, buf); } --- 200,211 ---- { void *buf; ! if (!PyInt_Check(value) && !PyLong_Check(value)) { PyErr_SetString(PyExc_TypeError, "integer expected"); return NULL; } ! buf = (void *)PyLong_AsVoidPtr(value); ! if (PyErr_Occurred()) ! return NULL; return CData_AtAddress(type, buf); } |
From: Thomas H. <th...@us...> - 2005-08-22 09:38:56
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv652 Modified Files: Tag: branch_1_0 ChangeLog Log Message: Fixed another sizeof(int) != sizeof(void*) problem. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.86.2.13 retrieving revision 1.86.2.14 diff -C2 -d -r1.86.2.13 -r1.86.2.14 *** ChangeLog 22 Aug 2005 09:32:59 -0000 1.86.2.13 --- ChangeLog 22 Aug 2005 09:38:45 -0000 1.86.2.14 *************** *** 1,4 **** --- 1,7 ---- 2005-08-22 Thomas Heller <th...@py...> + * source\_ctypes.c (CDataType_from_address): Fixed another + potential problem for systems where sizeof(int) != sizeof(void *). + * Fix a problem which showed up as array.value != array[:]. |
From: Thomas H. <th...@us...> - 2005-08-22 09:33:07
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32383 Modified Files: Tag: branch_1_0 ChangeLog Log Message: Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.86.2.12 retrieving revision 1.86.2.13 diff -C2 -d -r1.86.2.12 -r1.86.2.13 *** ChangeLog 19 Aug 2005 18:40:44 -0000 1.86.2.12 --- ChangeLog 22 Aug 2005 09:32:59 -0000 1.86.2.13 *************** *** 1,2 **** --- 1,6 ---- + 2005-08-22 Thomas Heller <th...@py...> + + * Fix a problem which showed up as array.value != array[:]. + 2005-08-19 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2005-08-22 09:31:52
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32205 Modified Files: Tag: branch_1_0 test_arrays.py Log Message: Fix a problem reported by JUrner. Index: test_arrays.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_arrays.py,v retrieving revision 1.8 retrieving revision 1.8.6.1 diff -C2 -d -r1.8 -r1.8.6.1 *** test_arrays.py 18 Aug 2004 12:27:25 -0000 1.8 --- test_arrays.py 22 Aug 2005 09:31:44 -0000 1.8.6.1 *************** *** 92,95 **** --- 92,108 ---- self.failUnless(ARRAY(c_int, 3) is ARRAY(c_int, 3)) + def test_from_address(self): + # Failed with 0.9.8, reported by JUrner + p = create_string_buffer("foo") + sz = (c_char * 3).from_address(addressof(p)) + self.failUnlessEqual(sz[:], "foo") + self.failUnlessEqual(sz.value, "foo") + + def test_from_addressW(self): + p = create_unicode_buffer("foo") + sz = (c_wchar * 3).from_address(addressof(p)) + self.failUnlessEqual(sz[:], "foo") + self.failUnlessEqual(sz.value, "foo") + if __name__ == '__main__': unittest.main() |
From: Thomas H. <th...@us...> - 2005-08-22 09:31:46
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32171 Modified Files: Tag: branch_1_0 _ctypes.c Log Message: Fix a problem reported by JUrner. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.226.2.21 retrieving revision 1.226.2.22 diff -C2 -d -r1.226.2.21 -r1.226.2.22 *** _ctypes.c 19 Aug 2005 18:22:32 -0000 1.226.2.21 --- _ctypes.c 22 Aug 2005 09:31:37 -0000 1.226.2.22 *************** *** 1909,1912 **** --- 1909,1913 ---- pd->b_ptr = buf; pd->b_length = dict->length; + pd->b_size = dict->size; return (PyObject *)pd; } |
From: Thomas H. <th...@us...> - 2005-08-22 07:34:11
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9444 Modified Files: Tag: branch_1_0 _ctypes_test.c Log Message: Remove a hardcoded breakpoint. Index: _ctypes_test.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes_test.c,v retrieving revision 1.46.2.4 retrieving revision 1.46.2.5 diff -C2 -d -r1.46.2.4 -r1.46.2.5 *** _ctypes_test.c 19 Aug 2005 18:47:16 -0000 1.46.2.4 --- _ctypes_test.c 22 Aug 2005 07:34:03 -0000 1.46.2.5 *************** *** 23,29 **** EXPORT(int *) _testfunc_ai8(int a[8]) { - #ifdef _DEBUG - _asm int 3; - #endif return a; } --- 23,26 ---- |
From: Thomas H. <th...@us...> - 2005-08-19 19:44:05
|
Update of /cvsroot/ctypes/ctypes/comtypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19368 Modified Files: Tag: branch_1_0 test_word.py test_ie.py test_client.py setup.py Log Message: Sync with upstream version. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/unittests/Attic/setup.py,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** setup.py 18 Aug 2005 14:42:18 -0000 1.1.2.1 --- setup.py 19 Aug 2005 19:43:55 -0000 1.1.2.2 *************** *** 1,5 **** from distutils.core import setup import glob - import ctypes import py2exe --- 1,5 ---- + # all the unittests can be converted to exe-files. from distutils.core import setup import glob import py2exe Index: test_client.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/unittests/Attic/test_client.py,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** test_client.py 17 Aug 2005 16:32:07 -0000 1.1.2.2 --- test_client.py 19 Aug 2005 19:43:55 -0000 1.1.2.3 *************** *** 4,8 **** # create the typelib wrapper and import it ! comtypes.client.make_module("msscript.ocx", wrapper="msscript") from comtypes.gen import msscript --- 4,8 ---- # create the typelib wrapper and import it ! comtypes.client.CreateModule("msscript.ocx", modulename="msscript") from comtypes.gen import msscript Index: test_ie.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/unittests/Attic/test_ie.py,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** test_ie.py 19 Aug 2005 18:51:32 -0000 1.1.2.3 --- test_ie.py 19 Aug 2005 19:43:55 -0000 1.1.2.4 *************** *** 53,57 **** sink = EventSink() ie = CreateObject("InternetExplorer.Application", ! wrapper="shdocvw_tlb", sink=sink) ie.Visible = True --- 53,57 ---- sink = EventSink() ie = CreateObject("InternetExplorer.Application", ! modulename="shdocvw_tlb", sink=sink) ie.Visible = True *************** *** 76,80 **** sink = EventSink() ie = CreateObject("InternetExplorer.Application", ! wrapper="shdocvw_tlb") import comtypes.gen.shdocvw_tlb as mod GetEvents(ie, sink, interface=mod.DWebBrowserEvents) --- 76,80 ---- sink = EventSink() ie = CreateObject("InternetExplorer.Application", ! modulename="shdocvw_tlb") import comtypes.gen.shdocvw_tlb as mod GetEvents(ie, sink, interface=mod.DWebBrowserEvents) Index: test_word.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/unittests/Attic/test_word.py,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** test_word.py 18 Aug 2005 14:42:18 -0000 1.1.2.1 --- test_word.py 19 Aug 2005 19:43:54 -0000 1.1.2.2 *************** *** 16,20 **** # create a word instance word = comtypes.client.CreateObject("Word.Application") ! wrapper = __import__(word.__com_interface__.__module__, globals(), locals(), ['*']) # Get the instance again, and receive events from that --- 16,20 ---- # create a word instance word = comtypes.client.CreateObject("Word.Application") ! module = __import__(word.__com_interface__.__module__, globals(), locals(), ['*']) # Get the instance again, and receive events from that *************** *** 36,40 **** time.sleep(0.5) ! doc.Close(SaveChanges = wrapper.wdDoNotSaveChanges) word.Quit() --- 36,40 ---- time.sleep(0.5) ! doc.Close(SaveChanges = module.wdDoNotSaveChanges) word.Quit() |
From: Thomas H. <th...@us...> - 2005-08-19 19:43:54
|
Update of /cvsroot/ctypes/ctypes/comtypes/client In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19334 Modified Files: Tag: branch_1_0 __init__.py Log Message: Sync with upstream version. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/client/Attic/__init__.py,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** __init__.py 18 Aug 2005 14:42:12 -0000 1.1.2.2 --- __init__.py 19 Aug 2005 19:43:46 -0000 1.1.2.3 *************** *** 1,2 **** --- 1,75 ---- + '''High level client level COM support module. + + CreateObject(progid, # which object to create + clsctx=None, # how to create the object + machine=None, # where to create the object + interface=None, # the interface we want + modulename=None, # alias name for the typelib wrapper + sink=None, # where to send events + sourceinterface=None) # the event interface we want + + + Create a COM object and return an interface pointer to it. + + + wrap(comobj, wrapper=None) + + CreateModule(typelib, modulename=None) + + Generate a Python wrapper for a COM typelibrary, import and return + the module. + + + gen_dir + + The directory where modules are created, this is the usually the + 'comtypes.gen' package directory. In a frozen exe, gen_dir is set + to None, and modules are only created in memory. + + CoGetObject(displayname, ...) + + Python wrappers for typelibraries are generated on demand in the + comtypes/gen directory. The names of these modules are derived from + typelibrary attributes - file names look like this + + _00020430_0000_0000_C000_000000000046_0_2_0.py + + so they are not really human readable. + + + The modulename optional argument to the CreateObject() and the + CreateModule() functions specifies the name for an alias module which + will contain everything that the typelib wrapper contains, but the + import statement could be written much easier. The friendly name must + be a valid Python module name, and the module is also created inside + the comtypes.gen package. + + For example, calling + + CreateModule("stdole2.tlb", modulename="stdole2_tlb") + + would generate the modules + comtypes.gen._00020430_0000_0000_C000_000000000046_0_2_0 + and + comtypes.gen.stdole2_tlb + + Another example uses the CreateObject function to create an instance + of Internet Explorer, generates the typelib wrapper for it, and makes + it available as comtypes.gen.IE_typelib module: + + obj = CreateObject("InternetExplorer.Application", + modulename="IE_typelib") + from comtypes.gen import IE_typelib + + The imported typelib wrapper can be used to access COM constants, for + example, and has also the advantage that py2exe would pick up the + typelib to include it in the executable. + + It is possible to create an exe file without importing the typelib + with a friendly name. py2exe includes the typelib parser and code + generation stuff into the executable, so the typelib wrapper would + then be generated at runtime, but only in memory. + ''' + ################################################################ # *************** *** 5,18 **** # - rename wrap # - # - rename make_module (generate_module, build_support, build_wrapper, get_wrapper... - # # - beautify the code generator output (import statements at the top) # # - add a GetTypelibWrapper(obj) function? # ################################################################ # comtypes.client - # XXX clean up docstring. import sys, os, new, imp --- 78,90 ---- # - rename wrap # # - beautify the code generator output (import statements at the top) # # - add a GetTypelibWrapper(obj) function? # + # - refactor this code into several modules now that this is a package + # ################################################################ # comtypes.client import sys, os, new, imp *************** *** 25,29 **** import comtypes.typeinfo ! __all__ = ["CreateObject", "GetActiveObject", "CoGetObject", "GetEvents", "ReleaseEvents"] ################################################################ --- 97,102 ---- import comtypes.typeinfo ! __all__ = ["CreateObject", "GetActiveObject", "CoGetObject", ! "GetEvents", "ReleaseEvents", "CreateModule"] ################################################################ *************** *** 88,92 **** return "comtypes.gen." + modname ! def make_module(tlib, wrapper=None): """Create a module wrapping a COM typelibrary on demand. --- 161,165 ---- return "comtypes.gen." + modname ! def CreateModule(tlib, modulename=None): """Create a module wrapping a COM typelibrary on demand. *************** *** 97,104 **** (libid, wMajorVerNum, wMinorVerNum, lcid=0) ! 'wrapper' allows to specify a name for an alias module which will also be created on demand inside the comtypes.gen package. ! If 'wrapper' is given and the module corresponding to that ! can be imported it is returned without trying to load the type library, so it CAN work without the type library actually being present. --- 170,177 ---- (libid, wMajorVerNum, wMinorVerNum, lcid=0) ! 'modulename' allows to specify a name for an alias module which will also be created on demand inside the comtypes.gen package. ! If 'modulename' is given and the module corresponding to that can ! be imported it is returned without trying to load the type library, so it CAN work without the type library actually being present. *************** *** 119,136 **** Example: ! make_module("shdocvw.dll", ! wrapper="IE_typelib") ! would create a module named comtypes.gen._EAB22AC0_30C1_11CF_A7EB_0000C05BAE0B_0_1_1 ! containing the wrapper code for the type library used by Internet ! Explorer. The 'comtypes.gen.IE_typelib' module is created as an ! alias. """ ! if wrapper: try: ! return _my_import("comtypes.gen." + wrapper) except: pass --- 192,210 ---- Example: ! CreateModule("shdocvw.dll", ! modulename="IE_typelib") ! would create modules named comtypes.gen._EAB22AC0_30C1_11CF_A7EB_0000C05BAE0B_0_1_1 + comtypes.gen.IE_typelib ! containing the Python wrapper code for the type library used by ! Internet Explorer. The former module contains all the code, the ! latter is a short stub loading the former. """ ! if modulename: try: ! return _my_import("comtypes.gen." + modulename) except: pass *************** *** 143,153 **** fullname = _name_module(tlib) # create and import the module ! mod = _make_module(tlib, fullname) ! if wrapper is None: return mod # create and import the friendly-named module try: ! return _my_import("comtypes.gen." + wrapper) except: # this way, the module is always regenerated if importing it --- 217,227 ---- fullname = _name_module(tlib) # create and import the module ! mod = _CreateWrapper(tlib, fullname) ! if modulename is None: return mod # create and import the friendly-named module try: ! return _my_import("comtypes.gen." + modulename) except: # this way, the module is always regenerated if importing it *************** *** 158,178 **** # this function fail. if __debug__: ! print "# Generating comtypes.gen.%s" % wrapper modname = fullname.split(".")[-1] code = "from comtypes.gen import %s\nglobals().update(%s.__dict__)\n" % (modname, modname) ! code += "__name__ = 'comtypes.gen.%s'" % wrapper if gen_dir is None: ! mod = new.module("comtypes.gen." + wrapper) exec code in mod.__dict__ ! sys.modules["comtypes.gen." + wrapper] = mod ! setattr(comtypes.gen, wrapper, mod) return mod # create in file system, and import it ! ofi = open(os.path.join(gen_dir, wrapper + ".py"), "w") ofi.write(code) ofi.close() ! return _my_import("comtypes.gen." + wrapper) ! def _make_module(tlib, fullname): # helper which creates and imports the real typelib wrapper module. try: --- 232,252 ---- # this function fail. if __debug__: ! print "# Generating comtypes.gen.%s" % modulename modname = fullname.split(".")[-1] code = "from comtypes.gen import %s\nglobals().update(%s.__dict__)\n" % (modname, modname) ! code += "__name__ = 'comtypes.gen.%s'" % modulename if gen_dir is None: ! mod = new.module("comtypes.gen." + modulename) exec code in mod.__dict__ ! sys.modules["comtypes.gen." + modulename] = mod ! setattr(comtypes.gen, modulename, mod) return mod # create in file system, and import it ! ofi = open(os.path.join(gen_dir, modulename + ".py"), "w") ofi.write(code) ofi.close() ! return _my_import("comtypes.gen." + modulename) ! def _CreateWrapper(tlib, fullname): # helper which creates and imports the real typelib wrapper module. try: *************** *** 199,203 **** if __debug__: print "# Generating comtypes.gen.%s" % modname ! generate_module(tlib, ofi, make_module, _name_module) if gen_dir is None: --- 273,277 ---- if __debug__: print "# Generating comtypes.gen.%s" % modname ! generate_module(tlib, ofi, CreateModule, _name_module) if gen_dir is None: *************** *** 214,218 **** # XXX rename this! ! def wrap(punk, wrapper=None): """Try to QueryInterface a COM pointer to the 'most useful' interface. --- 288,292 ---- # XXX rename this! ! def wrap(punk, modulename=None): """Try to QueryInterface a COM pointer to the 'most useful' interface. *************** *** 252,256 **** # import the wrapper, generating it on demand ! mod = make_module(tlib, wrapper) # Python interface class interface = getattr(mod, itf_name) --- 326,330 ---- # import the wrapper, generating it on demand ! mod = CreateModule(tlib, modulename) # Python interface class interface = getattr(mod, itf_name) *************** *** 383,387 **** def GetActiveObject(progid, interface=None, # the interface we want ! wrapper=None, # alias name for the typelib wrapper sink=None, # where to send events sourceinterface=None): # the event interface we want --- 457,461 ---- def GetActiveObject(progid, interface=None, # the interface we want ! modulename=None, # alias name for the typelib wrapper sink=None, # where to send events sourceinterface=None): # the event interface we want *************** *** 390,409 **** return _manage(obj, clsid, interface=interface, ! wrapper=wrapper, sink=sink, sourceinterface=sourceinterface) def _manage(obj, clsid, ! interface, wrapper, sink, sourceinterface): if interface is None: ! obj = wrap(obj, wrapper) ! elif wrapper: # XXX fix me. ! # wrap(obj, wrapper) should be refactored into: # - tlib = get_typelib(obj) ! # - make_module(tlib, wrapper) # - obj.QueryInterface(...) ! wrap(obj, wrapper) if sink is not None: if sourceinterface is None: --- 464,483 ---- return _manage(obj, clsid, interface=interface, ! modulename=modulename, sink=sink, sourceinterface=sourceinterface) def _manage(obj, clsid, ! interface, modulename , sink, sourceinterface): if interface is None: ! obj = wrap(obj, modulename) ! elif modulename: # XXX fix me. ! # wrap(obj, modulename) should be refactored into: # - tlib = get_typelib(obj) ! # - CreateModule(tlib, modulename) # - obj.QueryInterface(...) ! wrap(obj, modulename) if sink is not None: if sourceinterface is None: *************** *** 418,422 **** machine=None, # where to create the object interface=None, # the interface we want ! wrapper=None, # alias name for the typelib wrapper sink=None, # where to send events sourceinterface=None): # the event interface we want --- 492,496 ---- machine=None, # where to create the object interface=None, # the interface we want ! modulename=None, # alias name for the typelib wrapper sink=None, # where to send events sourceinterface=None): # the event interface we want *************** *** 430,434 **** 'clsctx' specifies how to create the object, use the CLSCTX_... constants. 'machine' allows to specify a remote machine to create the object on. ! 'wrapper' allows to specify a readable alias name for the typelib wrapper. 'sink' specifies an optional object to receive COM events. 'sourceinterface' is the interface that sends events. If not specified, --- 504,508 ---- 'clsctx' specifies how to create the object, use the CLSCTX_... constants. 'machine' allows to specify a remote machine to create the object on. ! 'modulename' allows to specify a readable alias name for the typelib wrapper. 'sink' specifies an optional object to receive COM events. 'sourceinterface' is the interface that sends events. If not specified, *************** *** 444,448 **** return _manage(obj, clsid, interface=interface, ! wrapper=wrapper, sink=sink, sourceinterface=sourceinterface) --- 518,522 ---- return _manage(obj, clsid, interface=interface, ! modulename=modulename, sink=sink, sourceinterface=sourceinterface) *************** *** 450,454 **** def CoGetObject(displayname, interface=None, # the interface we want ! wrapper=None, # alias name for the typelib wrapper sink=None, # where to send events sourceinterface=None): # the event interface we want --- 524,528 ---- def CoGetObject(displayname, interface=None, # the interface we want ! modulename=None, # alias name for the typelib wrapper sink=None, # where to send events sourceinterface=None): # the event interface we want *************** *** 461,546 **** clsid=None, interface=interface, ! wrapper=wrapper, sink=sink, sourceinterface=sourceinterface) ################################################################ - - '''High level client level COM support module. - - CreateObject(progid, # which object to create - clsctx=None, # how to create the object - machine=None, # where to create the object - interface=None, # the interface we want - wrapper=None, # alias name for the typelib wrapper - sink=None, # where to send events - sourceinterface=None) # the event interface we want - - - Create a COM object and return an interface pointer to it. - - - wrap(comobj, wrapper=None) - - - make_module(typelib, wrapper=None) - - Generate a Python wrapper for a COM typelibrary, import and return - the module. - - - gen_dir - - The directory where modules are created, this is the usually the - 'comtypes.gen' package directory. In a frozen exe, gen_dir is set - to None, and modules are only created in memory. - - CoGetObject(displayname, ...) - - Python wrappers for typelibraries are generated on demand in the - comtypes/gen directory. The names of these modules are derived from - typelibrary attributes - file names look like this - - _00020430_0000_0000_C000_000000000046_0_2_0.py - - so they are not really human readable. - - - The wrapper optional argument to the CreateObject() and the - make_module() functions specifies the name for an alias module which - will contain everything that the typelib wrapper contains, but the - import statement could be written much easier. The friendly name must - be a valid Python module name, and the module is also created inside - the comtypes.gen package. - - For example, calling - - make_module("stdole2.tlb", wrapper="stdole2_tlb") - - would generate the modules - comtypes.gen._00020430_0000_0000_C000_000000000046_0_2_0 - and - comtypes.gen.stdole2_tlb - - Another example uses the CreateObject function to create an instance - of Internet Explorer, generates the typelib wrapper for it, and makes - it available as comtypes.gen.IE_typelib module: - - obj = CreateObject("InternetExplorer.Application", - wrapper="IE_typelib") - from comtypes.gen import IE_typelib - - The imported typelib wrapper can be used to access COM constants, for - example, and has also the advantage that py2exe would pick up the - typelib to include it in the executable. - - It is possible to create an exe file without importing the typelib - with a friendly name. py2exe includes the typelib parser and code - generation stuff into the executable, so the typelib wrapper would - then be generated at runtime, but only in memory. - ''' - - ################################################################ - - if __name__ == "__main__": - print GetActiveObject("Word.Application") --- 535,541 ---- clsid=None, interface=interface, ! modulename=modulename, sink=sink, sourceinterface=sourceinterface) ################################################################ |
From: Thomas H. <th...@us...> - 2005-08-19 18:51:41
|
Update of /cvsroot/ctypes/ctypes/comtypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3383 Modified Files: Tag: branch_1_0 test_ie.py Log Message: Sync with upstream version. Index: test_ie.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/unittests/Attic/test_ie.py,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** test_ie.py 18 Aug 2005 14:42:18 -0000 1.1.2.2 --- test_ie.py 19 Aug 2005 18:51:32 -0000 1.1.2.3 *************** *** 56,60 **** sink=sink) ie.Visible = True ! ie.Navigate("http://www.python.org/") import time for i in range(50): --- 56,60 ---- sink=sink) ie.Visible = True ! ie.Navigate2(URL="http://www.python.org/", Flags=0) import time for i in range(50): *************** *** 81,85 **** ie.Visible = True ! ie.Navigate("http://www.python.org/") import time for i in range(50): --- 81,85 ---- ie.Visible = True ! ie.Navigate2(Flags=0, URL="http://www.python.org/") import time for i in range(50): |
From: Thomas H. <th...@us...> - 2005-08-19 18:51:34
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3357 Modified Files: Tag: branch_1_0 typeinfo.py persist.py automation.py __init__.py Log Message: Sync with upstream version. Index: typeinfo.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/typeinfo.py,v retrieving revision 1.3.2.8 retrieving revision 1.3.2.9 diff -C2 -d -r1.3.2.8 -r1.3.2.9 *** typeinfo.py 18 Aug 2005 14:42:04 -0000 1.3.2.8 --- typeinfo.py 19 Aug 2005 18:51:26 -0000 1.3.2.9 *************** *** 203,209 **** ## "Return the TYPEKIND of type information" ! def GetTypeInfoOfGuid(self, guid): ! "Return type information for a guid" ! return self._GetTypeInfoOfGuid(byref(guid)) def GetLibAttr(self): --- 203,208 ---- ## "Return the TYPEKIND of type information" ! ## def GetTypeInfoOfGuid(self, guid): ! ## "Return type information for a guid" def GetLibAttr(self): *************** *** 217,223 **** ## "Return documentation for a type description." - # Oops: IsName modifies the case of the passed in buffer, - # if the value is found. - # XXX MUST BE FIXED! def IsName(self, name, lHashVal=0): """Check if there is type information for this name. --- 216,219 ---- *************** *** 306,312 **** return p.value - # not yet wrapped - ## STDMETHOD(HRESULT, 'CreateInstance', [POINTER(IUnknown), POINTER(IID), POINTER(PVOID)]), - def CreateInstance(self, punkouter=None, interface=IUnknown, iid=None): if iid is None: --- 302,305 ---- *************** *** 349,353 **** return "type", bindptr.lptcomp elif kind == DESCKIND_IMPLICITAPPOBJ: ! raise "NYI" elif kind == DESCKIND_NONE: raise NameError, "Name %s not found" % name --- 342,346 ---- return "type", bindptr.lptcomp elif kind == DESCKIND_IMPLICITAPPOBJ: ! raise NotImplementedError elif kind == DESCKIND_NONE: raise NameError, "Name %s not found" % name Index: automation.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/automation.py,v retrieving revision 1.12.2.14 retrieving revision 1.12.2.15 diff -C2 -d -r1.12.2.14 -r1.12.2.15 *** automation.py 18 Aug 2005 14:42:04 -0000 1.12.2.14 --- automation.py 19 Aug 2005 18:51:26 -0000 1.12.2.15 *************** *** 115,118 **** --- 115,120 ---- CURRENCY = CY + # The VARIANT structure is a good candidate for implementation in a C + # helper extension. At least the get/set methods. class tagVARIANT(Structure): # The C Header file defn of VARIANT is much more complicated, but *************** *** 166,170 **** if value is None: self.vt = VT_NULL ! # since bool is a subclass of int, this check must be first elif isinstance(value, bool): self.vt = VT_BOOL --- 168,173 ---- if value is None: self.vt = VT_NULL ! # since bool is a subclass of int, this check must come before ! # the check for int elif isinstance(value, bool): self.vt = VT_BOOL *************** *** 175,187 **** --- 178,195 ---- elif isinstance(value, long): u = self._ + # try VT_I4 first. u.VT_I4 = value if u.VT_I4 == value: + # it did work. self.vt = VT_I4 return + # try VT_UI4 next. if value >= 0: u.VT_UI4 = value if u.VT_UI4 == value: + # did work. self.vt = VT_UI4 return + # VT_R8 is last resort. self.vt = VT_R8 u.VT_R8 = float(value) *************** *** 344,356 **** # This allows to pass values which can be stored in VARIANTs as # function parameters declared as POINTER(VARIANT). See ! # InternetExplorer's Navigate method, for example. def _from_param(self, arg): ! # POINTER(VARIANT)? if isinstance(arg, POINTER(VARIANT)): return arg ! # byref(VARIANT)? if isinstance(arg, _carg_obj) and isinstance(arg._obj, VARIANT): return arg ! return pointer(VARIANT(arg)) POINTER(VARIANT).from_param = classmethod(_from_param) --- 352,369 ---- # This allows to pass values which can be stored in VARIANTs as # function parameters declared as POINTER(VARIANT). See ! # InternetExplorer's Navigate2() method, or Word's Close() method, for ! # examples. def _from_param(self, arg): ! # accept POINTER(VARIANT) instance if isinstance(arg, POINTER(VARIANT)): return arg ! # accept byref(VARIANT) instance if isinstance(arg, _carg_obj) and isinstance(arg._obj, VARIANT): return arg ! # accept VARIANT instance ! if isinstance(arg, VARIANT): ! return byref(arg) ! # anything else which can be converted to a VARIANT. ! return byref(VARIANT(arg)) POINTER(VARIANT).from_param = classmethod(_from_param) Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/__init__.py,v retrieving revision 1.25.2.26 retrieving revision 1.25.2.27 diff -C2 -d -r1.25.2.26 -r1.25.2.27 *** __init__.py 18 Aug 2005 14:42:04 -0000 1.25.2.26 --- __init__.py 19 Aug 2005 18:51:26 -0000 1.25.2.27 *************** *** 706,714 **** ("hr", HRESULT)] ! class COSERVERINFO(Structure): ! _fields_ = [("dwReserved1", c_ulong), ! ("pwszName", c_wchar_p), ! ("pAuthInfo", c_void_p), # wrong! ! ("dwReserved2", c_ulong)] def CoCreateInstanceEx(clsid, interface=None, --- 706,765 ---- ("hr", HRESULT)] ! class _COAUTHIDENTITY(Structure): ! _fields_ = [ ! ('User', POINTER(c_ushort)), ! ('UserLength', c_ulong), ! ('Domain', POINTER(c_ushort)), ! ('DomainLength', c_ulong), ! ('Password', POINTER(c_ushort)), ! ('PasswordLength', c_ulong), ! ('Flags', c_ulong), ! ] ! COAUTHIDENTITY = _COAUTHIDENTITY ! ! class _COAUTHINFO(Structure): ! _fields_ = [ ! ('dwAuthnSvc', c_ulong), ! ('dwAuthzSvc', c_ulong), ! ('pwszServerPrincName', c_wchar_p), ! ('dwAuthnLevel', c_ulong), ! ('dwImpersonationLevel', c_ulong), ! ('pAuthIdentityData', POINTER(_COAUTHIDENTITY)), ! ('dwCapabilities', c_ulong), ! ] ! COAUTHINFO = _COAUTHINFO ! ! class _COSERVERINFO(Structure): ! _fields_ = [ ! ('dwReserved1', c_ulong), ! ('pwszName', c_wchar_p), ! ('pAuthInfo', POINTER(_COAUTHINFO)), ! ('dwReserved2', c_ulong), ! ] ! COSERVERINFO = _COSERVERINFO ! ! class tagBIND_OPTS(Structure): ! _fields_ = [ ! ('cbStruct', c_ulong), ! ('grfFlags', c_ulong), ! ('grfMode', c_ulong), ! ('dwTickCountDeadline', c_ulong) ! ] ! # XXX Add __init__ which sets cbStruct? ! BIND_OPTS = tagBIND_OPTS ! ! class tagBIND_OPTS2(Structure): ! _fields_ = [ ! ('cbStruct', c_ulong), ! ('grfFlags', c_ulong), ! ('grfMode', c_ulong), ! ('dwTickCountDeadline', c_ulong), ! ('dwTrackFlags', c_ulong), ! ('dwClassContext', c_ulong), ! ('locale', c_ulong), ! ('pServerInfo', POINTER(_COSERVERINFO)), ! ] ! # XXX Add __init__ which sets cbStruct? ! BINDOPTS2 = tagBIND_OPTS2 def CoCreateInstanceEx(clsid, interface=None, Index: persist.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/Attic/persist.py,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** persist.py 10 Aug 2005 13:17:53 -0000 1.1.2.1 --- persist.py 19 Aug 2005 18:51:26 -0000 1.1.2.2 *************** *** 24,28 **** _idlflags_ = [] _methods_ = [ ! COMMETHOD([dispid(1610678272)], HRESULT, 'RemoteRead', ( ['in'], POINTER(c_wchar), 'pszPropName' ), ( ['out'], POINTER(VARIANT), 'pVar' ), --- 24,28 ---- _idlflags_ = [] _methods_ = [ ! COMMETHOD([dispid(1610678272)], HRESULT, 'Read', ( ['in'], POINTER(c_wchar), 'pszPropName' ), ( ['out'], POINTER(VARIANT), 'pVar' ), |
From: Thomas H. <th...@us...> - 2005-08-19 18:47:24
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2152/source Modified Files: Tag: branch_1_0 _ctypes_test.c Log Message: Fix errors on linux. Index: _ctypes_test.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes_test.c,v retrieving revision 1.46.2.3 retrieving revision 1.46.2.4 diff -C2 -d -r1.46.2.3 -r1.46.2.4 *** _ctypes_test.c 19 Aug 2005 18:24:16 -0000 1.46.2.3 --- _ctypes_test.c 19 Aug 2005 18:47:16 -0000 1.46.2.4 *************** *** 518,521 **** --- 518,523 ---- #endif + #ifdef MS_WIN32 + /* Should port this to linux */ #include <stdlib.h> #include <search.h> *************** *** 560,563 **** --- 562,566 ---- return (void *)hThread; } + #endif DL_EXPORT(void) |
From: Thomas H. <th...@us...> - 2005-08-19 18:47:24
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2152/unittests Modified Files: Tag: branch_1_0 test_prototypes.py Log Message: Fix errors on linux. Index: test_prototypes.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_prototypes.py,v retrieving revision 1.6.6.2 retrieving revision 1.6.6.3 diff -C2 -d -r1.6.6.2 -r1.6.6.3 *** test_prototypes.py 19 Aug 2005 18:38:33 -0000 1.6.6.2 --- test_prototypes.py 19 Aug 2005 18:47:16 -0000 1.6.6.3 *************** *** 177,181 **** def func(): pass ! WINFUNCTYPE(None, c_int * 3)(func) ################################################################ --- 177,181 ---- def func(): pass ! CFUNCTYPE(None, c_int * 3)(func) ################################################################ |
From: Thomas H. <th...@us...> - 2005-08-19 18:40:51
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv714 Modified Files: Tag: branch_1_0 ChangeLog Log Message: Record changes. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.86.2.11 retrieving revision 1.86.2.12 diff -C2 -d -r1.86.2.11 -r1.86.2.12 *** ChangeLog 19 Aug 2005 15:10:06 -0000 1.86.2.11 --- ChangeLog 19 Aug 2005 18:40:44 -0000 1.86.2.12 *************** *** 7,12 **** != sizeof(void *). Get pointer values by PyLong_AsVoidPtr. ! Fix a bug when paramflags are specified as [], so the numerical ! flag value is 0. 2005-08-18 Thomas Heller <th...@py...> --- 7,17 ---- != sizeof(void *). Get pointer values by PyLong_AsVoidPtr. ! Fix a bug when paramflags are specified as [], and so the ! numerical flag value is 0. ! ! Per suggestion from Mike Fletcher: call byref() automatically, if ! needed, for POINTER types in argtypes. Fix crash with ARRAY types ! in argtypes. Fix a small refcount leak. Cleanup and clarify some ! code. 2005-08-18 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2005-08-19 18:38:41
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32590 Modified Files: Tag: branch_1_0 test_prototypes.py Added Files: Tag: branch_1_0 test_variant.py test_comobject.py Log Message: More tests. --- NEW FILE: test_variant.py --- import unittest, os from ctypes import * def get_refcnt(comptr): # return the COM reference count of a COM interface pointer if not comptr: return 0 comptr.AddRef() return comptr.Release() if os.name == "nt": class VariantTestCase(unittest.TestCase): def __init__(self, *args): # We cannot import these at module level, but want these to be # available in the global namespace global IUnknown, VARIANT, LoadTypeLibEx, DISPPARAMS, LoadRegTypeLib, GUID from ctypes.com import IUnknown, GUID from ctypes.com.automation import VARIANT, LoadTypeLibEx, DISPPARAMS, LoadRegTypeLib unittest.TestCase.__init__(self, *args) def test_com_refcounts(self): # typelib for Internet Explorer tlb = LoadRegTypeLib(GUID("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}"), 1, 1, 0) self.failUnlessEqual(get_refcnt(tlb), 1) p = POINTER(IUnknown)() tlb.QueryInterface(byref(IUnknown._iid_), byref(p)) self.failUnlessEqual(get_refcnt(tlb), 2) del p self.failUnlessEqual(get_refcnt(tlb), 1) def test_com_pointers(self): """Storing a COM interface pointer in a VARIANT increments the refcount, changing the variant to contain something else decrements it""" tlb = LoadRegTypeLib(GUID("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}"), 1, 1, 0) self.failUnlessEqual(get_refcnt(tlb), 1) v = VARIANT(tlb) self.failUnlessEqual(get_refcnt(tlb), 2) p = v.value self.failUnlessEqual(get_refcnt(tlb), 3) del p self.failUnlessEqual(get_refcnt(tlb), 2) v.value = None self.failUnlessEqual(get_refcnt(tlb), 1) def test_null_com_pointers(self): p = POINTER(IUnknown)() self.failUnlessEqual(get_refcnt(p), 0) v = VARIANT(p) self.failUnlessEqual(get_refcnt(p), 0) def test_dispparams(self): # DISPPARAMS is a complex structure, well worth testing. d = DISPPARAMS() d.rgvarg = (VARIANT * 3)() # XXX The following line fails, which is a real bug in ctypes: # SystemError: ...\Objects\listobject.c:105: bad argument to internal function ## d.rgvarg[0].value = 1 def test_pythonobjects(self): objects = [None, 42, 3.14, True, False, "abc", u"abc"] for x in objects: v = VARIANT(x) self.failUnlessEqual(x, v.value) ################################################################ if __name__ == '__main__': unittest.main() Index: test_prototypes.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_prototypes.py,v retrieving revision 1.6.6.1 retrieving revision 1.6.6.2 diff -C2 -d -r1.6.6.1 -r1.6.6.2 *** test_prototypes.py 29 Jul 2005 18:00:41 -0000 1.6.6.1 --- test_prototypes.py 19 Aug 2005 18:38:33 -0000 1.6.6.2 *************** *** 166,169 **** --- 166,182 ---- self.failUnlessEqual("a", func(byref(ca))[0]) + class ArrayTest(unittest.TestCase): + def test(self): + func = testdll._testfunc_ai8 + func.restype = POINTER(c_int) + func.argtypes = c_int * 8, + + print func((c_int * 8)(1, 2, 3, 4, 5, 6, 7, 8)) + + # This did crash before: + + def func(): pass + WINFUNCTYPE(None, c_int * 3)(func) + ################################################################ --- NEW FILE: test_comobject.py --- import unittest, os, sys from ctypes import * def get_refcnt(comptr): if not comptr: return 0 comptr.AddRef() return comptr.Release() if sys.platform == "win32": class ComTestCase(unittest.TestCase): def __init__(self, *args): unittest.TestCase.__init__(self, *args) global COMObject, IUnknown, GUID from ctypes.com import COMObject, IUnknown, GUID def setUp(self): class Factory(object): def LockServer(self, *args): pass class MyObject(COMObject): _factory = Factory() _com_interfaces_ = [IUnknown] self.impl = MyObject() def tearDown(self): self.impl = None ################ def test_comobject(self): impl = self.impl self.failUnlessEqual(impl._refcnt, 0) p = pointer(impl._com_pointers_[0][1]) p.AddRef() self.failUnlessEqual(impl._refcnt, 1) self.failUnlessEqual(get_refcnt(p), 1) del p self.failUnlessEqual(impl._refcnt, 0) def test_qi(self): impl = self.impl self.failUnlessEqual(impl._refcnt, 0) p = pointer(impl._com_pointers_[0][1]) p.AddRef() self.failUnlessEqual(get_refcnt(p), 1) p2 = POINTER(IUnknown)() p.QueryInterface(byref(IUnknown._iid_), byref(p2)) self.failUnlessEqual(get_refcnt(p), 2) def test_from_progid(self): g = GUID.from_progid("InternetExplorer.Application") self.failUnlessEqual(g, GUID("{0002DF01-0000-0000-C000-000000000046}")) def test_GUID(self): g1 = GUID("{00000000-0001-0002-0003-000000000000}") g2 = GUID("{00000000-0001-0002-0003-000000000000}") g3 = GUID("{00000000-0001-0002-0003-000000000001}") self.failUnlessEqual(g1, g2) # for now, GUID instances are unhashable. ## d = {} ## d[g1] = None ## self.failUnlessEqual(g1 in d, True) ## self.failUnlessEqual(g2 in d, True) ## self.failUnlessEqual(g3 in d, False) ################################################################ if __name__ == '__main__': unittest.main() |
From: Thomas H. <th...@us...> - 2005-08-19 18:24:25
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29705 Modified Files: Tag: branch_1_0 _ctypes_test.c Log Message: Another test function. Index: _ctypes_test.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes_test.c,v retrieving revision 1.46.2.2 retrieving revision 1.46.2.3 diff -C2 -d -r1.46.2.2 -r1.46.2.3 *** _ctypes_test.c 29 Jul 2005 18:00:28 -0000 1.46.2.2 --- _ctypes_test.c 19 Aug 2005 18:24:16 -0000 1.46.2.3 *************** *** 21,24 **** --- 21,32 ---- /* some functions handy for testing */ + EXPORT(int *) _testfunc_ai8(int a[8]) + { + #ifdef _DEBUG + _asm int 3; + #endif + return a; + } + EXPORT(void) _testfunc_v(int a, int b, int *presult) { *************** *** 510,513 **** --- 518,564 ---- #endif + #include <stdlib.h> + #include <search.h> + + struct _sortit { + void *base; + size_t num; + size_t width; + int (_cdecl *compare)(const void *, const void *); + }; + + EXPORT(int) cmp(int *a, int *b) + { + return *a - *b; + } + + static DWORD WINAPI my_qsort(struct _sortit *s) + { + printf("Thread started\n"); + qsort(s->base, s->num, s->width, s->compare); + printf("Thread ending\n"); + return 42; + } + + EXPORT(void *) qsort_in_thread(void *base, size_t num, size_t width, + int (_cdecl *compare)(const void*, const void *)) + { + HANDLE hThread; + DWORD threadid; + static struct _sortit sortit; + + sortit.base = base; + sortit.num = num; + sortit.width = width; + sortit.compare = compare; + hThread = CreateThread(NULL, /* default security descriptor */ + 0, /* default stack size */ + &my_qsort, /* start address */ + &sortit, /* parameter */ + 0, /* dwCreationFlags */ + &threadid); + return (void *)hThread; + } + DL_EXPORT(void) init_ctypes_test(void) |
From: Thomas H. <th...@us...> - 2005-08-19 18:22:41
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29182 Modified Files: Tag: branch_1_0 _ctypes.c Log Message: Per suggestion from Mike Fletcher: call byref() automatically, if needed, for POINTER types in argtypes. Fix crash with ARRAY types in argtypes. Fix a small refcount leak. Cleanup and clarify some code. Add TODO comments. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.226.2.20 retrieving revision 1.226.2.21 diff -C2 -d -r1.226.2.20 -r1.226.2.21 *** _ctypes.c 19 Aug 2005 14:59:35 -0000 1.226.2.20 --- _ctypes.c 19 Aug 2005 18:22:32 -0000 1.226.2.21 *************** *** 582,611 **** } static PyObject * PointerType_from_param(PyObject *type, PyObject *value) { if (value == Py_None) return PyInt_FromLong(0); /* NULL pointer */ ! if (ArrayObject_Check(value)) { ! /* Array instances are also pointers when ! the item types are the same. ! */ ! StgDictObject *v = PyObject_stgdict(value); ! StgDictObject *t = PyType_stgdict(type); ! if (v && t && v->proto == t->proto) { ! Py_INCREF(value); ! return value; ! } ! } ! if (PointerObject_Check(value)) { ! StgDictObject *v = PyObject_stgdict(value); ! StgDictObject *t = PyType_stgdict(type); ! if (PyObject_IsSubclass(v->proto, t->proto)) { ! Py_INCREF(value); ! return value; ! } } ! return CDataType_from_param(type, value); } --- 582,622 ---- } + staticforward PyObject *_byref(PyObject *); + static PyObject * PointerType_from_param(PyObject *type, PyObject *value) { + StgDictObject *typedict; + if (value == Py_None) return PyInt_FromLong(0); /* NULL pointer */ ! typedict = PyType_stgdict(type); ! ! /* If we expect POINTER(<type>), but receive a <type> instance, accept ! it by calling byref(<type>). ! */ ! switch (PyObject_IsInstance(value, typedict->proto)) { ! case 1: ! Py_INCREF(value); /* _byref steals a refcount */ ! return _byref(value); ! case -1: ! PyErr_Clear(); ! break; ! default: ! break; } ! ! if (PointerObject_Check(value) || ArrayObject_Check(value)) { ! /* Array instances are also pointers when ! the item types are the same. ! */ ! StgDictObject *v = PyObject_stgdict(value); ! if (PyObject_IsSubclass(v->proto, typedict->proto)) { ! Py_INCREF(value); ! return value; ! } ! } ! return CDataType_from_param(type, value); } *************** *** 924,927 **** --- 935,941 ---- stgdict->proto = proto; + /* Arrays are passed as pointers to function calls. */ + stgdict->ffi_type = ffi_type_pointer; + /* create the new instance (which is a class, since we are a metatype!) */ *************** *** 2255,2259 **** typ = PyTuple_GET_ITEM(argtypes, i); dict = PyType_stgdict(typ); ! if ((flag & 2) && (dict->ffi_type.type != FFI_TYPE_POINTER)) { PyErr_Format(PyExc_TypeError, "output parameter %d not a pointer type: %s", --- 2269,2277 ---- typ = PyTuple_GET_ITEM(argtypes, i); dict = PyType_stgdict(typ); ! /* We could (and should maybe) also allow array types ! for 'out' parameters. The _build_callargs() function must ! be modified, though. See comments there... ! */ ! if ((flag & PARAMFLAG_FOUT) && (!PointerTypeObject_Check(typ))) { PyErr_Format(PyExc_TypeError, "output parameter %d not a pointer type: %s", *************** *** 2606,2610 **** } #endif - for (i = 0; i < len; ++i) { PyObject *item = PyTuple_GET_ITEM(paramflags, i); --- 2624,2627 ---- *************** *** 2642,2645 **** --- 2659,2672 ---- /* Create an instance of the pointed-to type */ ob = PyObject_CallObject(dict->proto, NULL); + /* XXX The above only works as intended for POINTER + types. For ARRAY types, we should create an + intance of the type itself, not of the itemtype. + + But that is not enough: + + We must not pass a byref() to the array then but + the array instance itself. Then, we cannot retrive + the result from the PyCArgObject. + */ if (ob == NULL) goto error; *************** *** 2663,2666 **** --- 2690,2696 ---- if (v == 0) goto error; + /* XXX But this looks wrong. Shouldn't we call + <type>.from_param(<value>) ? + */ ob = PyObject_CallFunctionObjArgs(dict->proto, v, *************** *** 2842,2847 **** #endif callargs = _build_callargs(self, argtypes, inargs, kwds, &retval); ! if (callargs == NULL) return NULL; if (converters) { --- 2872,2879 ---- #endif callargs = _build_callargs(self, argtypes, inargs, kwds, &retval); ! if (callargs == NULL) { ! Py_XDECREF(retval); return NULL; + } if (converters) { |
From: Thomas H. <th...@us...> - 2005-08-19 15:10:19
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14926 Modified Files: Tag: branch_1_0 ChangeLog Log Message: Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.86.2.10 retrieving revision 1.86.2.11 diff -C2 -d -r1.86.2.10 -r1.86.2.11 *** ChangeLog 19 Aug 2005 07:07:48 -0000 1.86.2.10 --- ChangeLog 19 Aug 2005 15:10:06 -0000 1.86.2.11 *************** *** 4,7 **** --- 4,13 ---- output when the instance is a COM method. + Fix two problems that will show up on platforms where sizeof(int) + != sizeof(void *). Get pointer values by PyLong_AsVoidPtr. + + Fix a bug when paramflags are specified as [], so the numerical + flag value is 0. + 2005-08-18 Thomas Heller <th...@py...> |