ctypes-commit Mailing List for ctypes (Page 68)
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-03-16 14:22:15
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27859 Modified Files: typeinfo.py Log Message: Wrap the GetDllEntry method. Index: typeinfo.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/typeinfo.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** typeinfo.py 10 Mar 2005 14:36:19 -0000 1.1 --- typeinfo.py 16 Mar 2005 14:21:55 -0000 1.2 *************** *** 319,323 **** return name.value, docstring.value, helpcontext.value, helpfile.value ! ## STDMETHOD(HRESULT, 'GetDllEntry', [MEMBERID, INVOKEKIND, POINTER(BSTR), POINTER(BSTR), POINTER(WORD)]), def GetRefTypeInfo(self, href): --- 319,329 ---- return name.value, docstring.value, helpcontext.value, helpfile.value ! def GetDllEntry(self, memid, invkind): ! "Return the dll name, function name, and ordinal for a function and invkind." ! dllname = BSTR() ! name = BSTR() ! ordinal = c_ushort() ! self.__com_GetDllEntry(memid, invkind, byref(dllname), byref(name), byref(ordinal)) ! return dllname.value, name.value, ordinal.value def GetRefTypeInfo(self, href): |
From: Thomas H. <th...@us...> - 2005-03-16 12:29:42
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31782 Modified Files: automation.py Log Message: A small optimization, and use the ctypes automatic unicode conversion. Index: automation.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/automation.py,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** automation.py 16 Mar 2005 10:18:14 -0000 1.11 --- automation.py 16 Mar 2005 12:29:32 -0000 1.12 *************** *** 44,55 **** ################################ ! # helper constants IID_NULL = GUID() riid_null = byref(IID_NULL) ! _oleaut32 = oledll.oleaut32 # 30. December 1899, midnight. For VT_DATE. _com_null_date = datetime.datetime(1899, 12, 30, 0, 0, 0) - ################################################################ # VARIANT, in all it's glory. --- 44,56 ---- ################################ ! # helpers IID_NULL = GUID() riid_null = byref(IID_NULL) ! _VariantClear = oledll.oleaut32.VariantClear ! _SysAllocStringLen = oledll.oleaut32.SysAllocStringLen ! # 30. December 1899, midnight. For VT_DATE. _com_null_date = datetime.datetime(1899, 12, 30, 0, 0, 0) ################################################################ # VARIANT, in all it's glory. *************** *** 148,152 **** # see also c:/sf/pywin32/com/win32com/src/oleargs.cpp 54 def _set_value(self, value): ! _oleaut32.VariantClear(byref(self)) if value is None: self.vt = VT_NULL --- 149,153 ---- # see also c:/sf/pywin32/com/win32com/src/oleargs.cpp 54 def _set_value(self, value): ! _VariantClear(byref(self)) if value is None: self.vt = VT_NULL *************** *** 174,184 **** self.vt = VT_R8 self._.VT_R8 = value ! elif isinstance(value, unicode): ! self.vt = VT_BSTR ! self._.c_void_p = _oleaut32.SysAllocStringLen(value, len(value)) ! elif isinstance(value, str): self.vt = VT_BSTR ! value = unicode(value) ! self._.c_void_p = _oleaut32.SysAllocStringLen(value, len(value)) elif isinstance(value, datetime.datetime): delta = value - _com_null_date --- 175,182 ---- self.vt = VT_R8 self._.VT_R8 = value ! elif isinstance(value, (str, unicode)): self.vt = VT_BSTR ! # do the c_wchar_p auto unicode conversion ! self._.c_void_p = _SysAllocStringLen(c_wchar_p.from_param(value), len(value)) elif isinstance(value, datetime.datetime): delta = value - _com_null_date |
From: Thomas H. <th...@us...> - 2005-03-16 10:18:28
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1610 Modified Files: automation.py Log Message: Fix VARIANT._set_value for bool and long. Index: automation.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/automation.py,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** automation.py 10 Mar 2005 14:36:19 -0000 1.10 --- automation.py 16 Mar 2005 10:18:14 -0000 1.11 *************** *** 151,164 **** if value is None: self.vt = VT_NULL elif isinstance(value, int): self.vt = VT_I4 self._.VT_I4 = value elif isinstance(value, long): - self.vt = VT_I4 u = self._ u.VT_I4 = value ! if u.VT_I4 != value: ! self.vt = VT_R8 ! u.VT_R8 = float(value) elif isinstance(value, float): self.vt = VT_R8 --- 151,174 ---- 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 + self._.VT_BOOL = value elif isinstance(value, int): self.vt = VT_I4 self._.VT_I4 = value elif isinstance(value, long): u = self._ u.VT_I4 = value ! if u.VT_I4 == value: ! self.vt = VT_I4 ! return ! if value >= 0: ! u.VT_UI4 = value ! if u.VT_UI4 == value: ! self.vt = VT_UI4 ! return ! self.vt = VT_R8 ! u.VT_R8 = float(value) elif isinstance(value, float): self.vt = VT_R8 *************** *** 171,177 **** value = unicode(value) self._.c_void_p = _oleaut32.SysAllocStringLen(value, len(value)) - elif isinstance(value, bool): - self.vt = VT_BOOL - self._.VT_BOOL = value elif isinstance(value, datetime.datetime): delta = value - _com_null_date --- 181,184 ---- |
From: Thomas H. <th...@us...> - 2005-03-16 09:53:16
|
Update of /cvsroot/ctypes/ctypes/comtypes/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27996 Modified Files: codegenerator.py Log Message: Fix a small problem. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/codegenerator.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** codegenerator.py 16 Mar 2005 09:31:11 -0000 1.4 --- codegenerator.py 16 Mar 2005 09:52:57 -0000 1.5 *************** *** 145,149 **** for typ, name, idlflags, default in m.arguments: if default is not None: ! arglist.append("( %r, '%s', %r )" % ( idlflags, self.type_name(typ), --- 145,149 ---- for typ, name, idlflags, default in m.arguments: if default is not None: ! arglist.append("( %r, %s, '%s', %r )" % ( idlflags, self.type_name(typ), |
From: Thomas H. <th...@us...> - 2005-03-16 09:31:21
|
Update of /cvsroot/ctypes/ctypes/comtypes/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23368 Modified Files: codegenerator.py Log Message: Call self.need_COMMETHOD() when needed. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/codegenerator.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** codegenerator.py 16 Mar 2005 07:45:46 -0000 1.3 --- codegenerator.py 16 Mar 2005 09:31:11 -0000 1.4 *************** *** 50,53 **** --- 50,54 ---- self.generate(m.returns) + self.need_COMMETHOD() print >> self.stream, "%s._methods_ = [" % body.itf.name for m in body.itf.members: |
From: Thomas H. <th...@us...> - 2005-03-16 09:09:14
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18198 Modified Files: __init__.py Log Message: Emit a warning instead of raising an exception when named com properties are required. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/__init__.py,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** __init__.py 16 Mar 2005 07:24:14 -0000 1.22 --- __init__.py 16 Mar 2005 09:09:02 -0000 1.23 *************** *** 183,188 **** # __setitem__ methods. ## prop = named_property(getters.get(item), setters.get(item), doc=doc) ! raise "Named Properties not yet implemented" setattr(self, name, prop) # metaclass for COM interface pointer classes --- 183,195 ---- # __setitem__ methods. ## prop = named_property(getters.get(item), setters.get(item), doc=doc) ! import warnings ! warnings.warn("Named property '%s'" % name, ! NotYetImplemented, ! stacklevel=3) ! continue setattr(self, name, prop) + + class NotYetImplemented(Warning): + pass # metaclass for COM interface pointer classes |
From: Thomas H. <th...@us...> - 2005-03-16 08:50:56
|
Update of /cvsroot/ctypes/ctypes/ctypes/wrap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14221 Modified Files: cparser_config.py Log Message: Exclude some symbols from limits.h that gccxml won't compile. Provide empty EXCLUDED and EXCLUDED_RE lists on platforms other than windows or linux. Index: cparser_config.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/wrap/cparser_config.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** cparser_config.py 4 Feb 2005 17:01:24 -0000 1.1 --- cparser_config.py 16 Mar 2005 08:50:26 -0000 1.2 *************** *** 66,71 **** --- 66,86 ---- IMAGE_ORDINAL_FLAG64 SECURITY_NT_AUTHORITY + _I8_MIN + _I8_MAX + _UI8_MAX + _I16_MIN + _I16_MAX + _UI16_MAX + _I32_MIN + _I32_MAX + _UI32_MAX + _I64_MIN + _I64_MAX + _UI64_MAX """.strip().split() + # The _I8_MIN symbols and friends are in limits.h, they have constanrs + # with i8 i16 i32 i64 suffixes which gccxml refuses to compile. + EXCLUDED_linux = """ _IOT_termios *************** *** 76,79 **** --- 91,96 ---- elif sys.platform.startswith("linux"): EXCLUDED = EXCLUDED_linux + else: + EXCLUDED = [] EXCLUDED = [text for text in EXCLUDED *************** *** 94,97 **** --- 111,116 ---- elif sys.platform.startswith("linux"): EXCLUDED_RE = EXCLUDED_RE_linux + else: + EXCLUDED_RE = [] EXCLUDED_RE = [re.compile(pat) for pat in EXCLUDED_RE |
From: Thomas H. <th...@us...> - 2005-03-16 07:51:32
|
Update of /cvsroot/ctypes/ctypes/ctypes/wrap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2890 Modified Files: codegenerator.py Log Message: _COMMETHOD_defined was never set to True. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/wrap/codegenerator.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** codegenerator.py 11 Mar 2005 15:40:44 -0000 1.5 --- codegenerator.py 16 Mar 2005 07:51:19 -0000 1.6 *************** *** 3,6 **** --- 3,9 ---- # $Log$ + # Revision 1.6 2005/03/16 07:51:19 theller + # _COMMETHOD_defined was never set to True. + # # Revision 1.5 2005/03/11 15:40:44 theller # Detect an 'Enum' com method, and create an __iter__ method in this class. *************** *** 559,563 **** return print >> self.imports, "from comtypes import COMMETHOD" ! self._STDMETHOD_defined = True _GUID_defined = False --- 562,566 ---- return print >> self.imports, "from comtypes import COMMETHOD" ! self._COMMETHOD_defined = True _GUID_defined = False |
From: Thomas H. <th...@us...> - 2005-03-16 07:45:58
|
Update of /cvsroot/ctypes/ctypes/comtypes/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1882 Modified Files: codegenerator.py Log Message: Don't generate high level methods - that's all done by the metaclass, if paramflags are available. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/codegenerator.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** codegenerator.py 11 Feb 2005 20:54:32 -0000 1.2 --- codegenerator.py 16 Mar 2005 07:45:46 -0000 1.3 *************** *** 11,14 **** --- 11,15 ---- # def CoClass(self, coclass): + self.need_GUID() print >> self.stream, "class %s(CoClass):" % coclass.name doc = getattr(coclass, "doc", None) *************** *** 37,52 **** basename = self.type_name(head.itf.base) ! ## tpl = self.templates.get(head.itf.name, None) ! ## if tpl is not None: ! ## print >> self.stream, tpl ! ## return ! print >> self.stream, "class %s(%s):" % (head.itf.name, basename) print >> self.stream, " _iid_ = GUID(%r)" % head.itf.iid print >> self.stream, " _idlflags_ = %s" % head.itf.idlflags - for m in head.itf.members: - is_property = self.make_ComMethodWrapper(m) - def ComInterfaceBody(self, body): # make sure we can generate the body --- 38,46 ---- basename = self.type_name(head.itf.base) ! self.need_GUID() print >> self.stream, "class %s(%s):" % (head.itf.name, basename) print >> self.stream, " _iid_ = GUID(%r)" % head.itf.iid print >> self.stream, " _idlflags_ = %s" % head.itf.idlflags def ComInterfaceBody(self, body): # make sure we can generate the body *************** *** 71,79 **** self.generate(head.itf.base) basename = self.type_name(head.itf.base) - ## tpl = self.templates.get(head.itf.name, None) - ## if tpl is not None: - ## print >> self.stream, tpl - ## return print >> self.stream, "class %s(%s):" % (head.itf.name, basename) doc = getattr(head.itf, "doc", None) --- 65,70 ---- self.generate(head.itf.base) basename = self.type_name(head.itf.base) + self.need_GUID() print >> self.stream, "class %s(%s):" % (head.itf.name, basename) doc = getattr(head.itf, "doc", None) *************** *** 83,105 **** print >> self.stream, " _idlflags_ = %s" % head.itf.idlflags - # code - prop_map = {} - for m in head.itf.members: - is_property = self.make_DispMethodWrapper(m) - if is_property is not None: - name, kind = is_property - prop_map.setdefault(name, []).append(kind) - for name, kinds in prop_map.items(): - if "propget" in kinds: - getter = "_get_%s" % name - if "propput" in kinds: - setter = "_set_%s" % name - elif "propputref" in kinds: - setter = "_putref_%s" % name - else: - setter = None - print >> self.stream, " %s = property(%s, %s)" % (name, getter, setter) - print >> self.stream - def DispInterfaceBody(self, body): # make sure we can generate the body --- 74,77 ---- *************** *** 143,156 **** for typ, name, idlflags, default in m.arguments: if default is not None: ! arglist.append("( %r, '%s', %s, %r )" % ( idlflags, - name, self.type_name(typ), default)) else: ! arglist.append("( %r, '%s', %s )" % ( idlflags, ! name, ! self.type_name(typ))) self.stream.write(",\n ".join(arglist)) print >> self.stream, ")," --- 115,128 ---- for typ, name, idlflags, default in m.arguments: if default is not None: ! arglist.append("( %r, '%s', %r )" % ( idlflags, self.type_name(typ), + name, default)) else: ! arglist.append("( %r, %s, '%s' )" % ( idlflags, ! self.type_name(typ), ! name)) self.stream.write(",\n ".join(arglist)) print >> self.stream, ")," *************** *** 159,163 **** # typ, name, idlflags, default args = [self.type_name(a[0]) for a in m.arguments] - ## code = " DISPMETHOD(%r,\n %s, '%s'" % ( code = " DISPMETHOD(%r, %s, '%s'" % ( [m.dispid] + m.idlflags, --- 131,134 ---- *************** *** 173,190 **** for typ, name, idlflags, default in m.arguments: if default is not None: ! arglist.append("( %r, '%s', %s, %r )" % ( idlflags, - name, self.type_name(typ), default)) else: ! arglist.append("( %r, '%s', %s )" % ( idlflags, - name, self.type_name(typ), )) self.stream.write(",\n ".join(arglist)) print >> self.stream, ")," - ## print >> self.stream, "\n )," def make_DispProperty(self, prop): --- 144,160 ---- for typ, name, idlflags, default in m.arguments: if default is not None: ! arglist.append("( %r, '%s', %r )" % ( idlflags, self.type_name(typ), + name, default)) else: ! arglist.append("( %r, %s, '%s' )" % ( idlflags, self.type_name(typ), + name, )) self.stream.write(",\n ".join(arglist)) print >> self.stream, ")," def make_DispProperty(self, prop): *************** *** 194,346 **** prop.name) - ################################################################ - # Python method implementation generators. - # - def make_DispPropertyWrapper(self, p): - type_name = self.type_name(p.typ) - print >> self.stream, " def _get_%s(self):" % p.name - print >> self.stream, " _result_ = %s()" % type_name - print >> self.stream, " self.__com_get_%s(byref(_result))" % p.name - print >> self.stream, " return _result_.value" - getter = "_get_%s" % p.name - - if "readonly" in p.idlflags: - setter = None - else: - setter = "_set_%s" % p.name - print >> self.stream, " def _set_%s(self, rhs):" % p.name - print >> self.stream, " self.__com_set_%s(rhs)" % p.name - - doc = getattr(p, "doc", None) - print >> self.stream, " %s = property(%s, %s, doc=%r)" % \ - (p.name, getter, setter, doc) - print >> self.stream - return None - - def make_ComMethodWrapper(self, m): - funcname = m.name - args = m.arguments - inargs = [] - for typ, name, idlflags, default in args: - if "in" in idlflags: - if default is not None: - inargs.append("%s=%r" % (name, default)) - elif "optional" in idlflags: - inargs.append("%s=%s" % (name, "MISSING")) - else: - inargs.append(name) - - allargs = [] - flocals = [] - for typ, name, idlflags, default in args: - # XXX What about [in, out] parameters? - if "out" in idlflags: - assert isinstance(typ, typedesc.PointerType) - flocals.append((name, self.type_name(typ.typ))) - allargs.append("byref(%s)" % name) - else: - allargs.append(name) - - # Now that POINTER(<com_interface>) instances have a .value property - # which returns the com pointer itself, we can do this FOR ALL types: - outargs = ["%s.value" % name for (typ, name, idlflags, default) in args - if "out" in idlflags] - - print >> self.stream, " def %s(%s):" % (funcname, ", ".join(["self"] + inargs)) - doc = getattr(m, "doc", None) - if doc: - print >> self.stream, " %r" % doc - for n, t in flocals: - print >> self.stream, " %s = %s()" % (n, t) - if outargs: - print >> self.stream, " self.__com_%s(%s)" % (funcname, ", ".join(allargs)) - print >> self.stream, " return %s" % ", ".join(outargs) - else: - print >> self.stream, " return self.__com_%s(%s)" % (funcname, ", ".join(allargs)) - - - def make_DispMethodWrapper(self, m): - if isinstance(m, typedesc.DispProperty): - return self.DispPropertyWrapper(m) - funcname = m.name - if "propget" in m.idlflags: - funcname = "_get_%s" % funcname - elif "propput" in m.idlflags: - funcname = "_set_%s" % funcname - elif "propputref" in m.idlflags: - funcname = "_putref_%s" % funcname - else: - pass - args = m.arguments[:] - if self.type_name(m.returns) != 'None': # return type != void - typ = typedesc.PointerType(m.returns, 32, 32) - args.append((typ, "_result_", ["out"], None)) # add with paramflag_fout - - inargs = [] - for typ, name, idlflags, default in args: - if "in" in idlflags: - if default is not None: - inargs.append("%s=%r" % (name, default)) - elif "optional" in idlflags: - inargs.append("%s=%s" % (name, "MISSING")) - else: - inargs.append(name) - - allargs = [] - flocals = [] - for typ, name, idlflags, default in args: - # XXX What about [in, out] parameters? - if "out" in idlflags: - assert isinstance(typ, typedesc.PointerType) - flocals.append((name, self.type_name(typ.typ))) - allargs.append("byref(%s)" % name) - else: - allargs.append(name) - - # Now that POINTER(<com_interface>) instances have a .value property - # which returns the com pointer itself, we can do this FOR ALL types: - outargs = ["%s.value" % name for (typ, name, idlflags, default) in args - if "out" in idlflags] - - print >> self.stream, " def %s(%s):" % (funcname, ", ".join(["self"] + inargs)) - doc = getattr(m, "doc", None) - if doc: - print >> self.stream, " %r" % doc - for n, t in flocals: - print >> self.stream, " %s = %s()" % (n, t) - if outargs: - print >> self.stream, " self.__com_%s(%s)" % (funcname, ", ".join(allargs)) - print >> self.stream, " return %s" % ", ".join(outargs) - else: - print >> self.stream, " return self.__com_%s(%s)" % (funcname, ", ".join(allargs)) - - is_property = None - # check if this could be a Python property - if "propget" in m.idlflags: - if len(inargs) == 0: - # 'propget' can only be a Python property if it has no args - is_property = m.name, "propget" - else: - print >> self.stream, " %s = %s" % (m.name, funcname) - elif "propput" in m.idlflags: - if len(inargs) == 1: - # 'propput' can only be a Python property if it has no args - is_property = m.name, "propput" - else: - print >> self.stream, " %s = %s" % (m.name, funcname) - elif "propputref" in m.idlflags: - if len(inargs) == 1: - # 'propputref' can only be a Python property if it has no args - # XXX - is_property = m.name, "propputref" - else: - print >> self.stream, " %s = %s" % (m.name, funcname) - - print >> self.stream - return is_property - # shortcut for development if __name__ == "__main__": import tlbparser tlbparser.main() - --- 164,169 ---- |
From: Thomas H. <th...@us...> - 2005-03-16 07:24:26
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30190 Modified Files: __init__.py Log Message: propput nethod names are prefixed '_set_', not '_put_'. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/__init__.py,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** __init__.py 11 Mar 2005 17:52:21 -0000 1.21 --- __init__.py 16 Mar 2005 07:24:14 -0000 1.22 *************** *** 183,187 **** # __setitem__ methods. ## prop = named_property(getters.get(item), setters.get(item), doc=doc) ! raise "Not Yet Implemented" setattr(self, name, prop) --- 183,187 ---- # __setitem__ methods. ## prop = named_property(getters.get(item), setters.get(item), doc=doc) ! raise "Named Properties not yet implemented" setattr(self, name, prop) *************** *** 338,342 **** methodname = "_get_%s" % methodname elif "propput" in idlflags: ! methodname = "_put_%s" % methodname return restype, methodname, tuple(argtypes), tuple(paramflags), tuple(idlflags), helptext --- 338,342 ---- methodname = "_get_%s" % methodname elif "propput" in idlflags: ! methodname = "_set_%s" % methodname return restype, methodname, tuple(argtypes), tuple(paramflags), tuple(idlflags), helptext |
From: Thomas H. <th...@us...> - 2005-03-16 07:23:27
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29975 Modified Files: GUID.py Log Message: Fix pychecker warnings in a classmethod. Index: GUID.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/GUID.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** GUID.py 24 Feb 2005 16:46:07 -0000 1.5 --- GUID.py 16 Mar 2005 07:23:16 -0000 1.6 *************** *** 56,62 **** return progid.value ! def create_new(self): "Create a brand new guid" ! guid = self() _ole32.CoCreateGuid(byref(guid)) return guid --- 56,62 ---- return progid.value ! def create_new(cls): "Create a brand new guid" ! guid = cls() _ole32.CoCreateGuid(byref(guid)) return guid |
From: Thomas H. <th...@us...> - 2005-03-15 11:11:11
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29087 Modified Files: setup_gccxml.iss Log Message: vcInstall.exe did not work, because the working directory was not specified. So it couldn't find patch.exe. Index: setup_gccxml.iss =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/setup_gccxml.iss,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** setup_gccxml.iss 17 Dec 2004 09:45:36 -0000 1.1 --- setup_gccxml.iss 15 Mar 2005 11:10:58 -0000 1.2 *************** *** 22,25 **** --- 22,26 ---- Source: "C:\sf\gccxml\GCC_XML\VcInstall\vcCat.exe"; DestName: cat.exe; DestDir: "{app}\install"; Flags: ignoreversion Source: "C:\sf\gccxml\GCC_XML\VcInstall\vcPatch.exe"; DestName: patch.exe; DestDir: "{app}\install"; Flags: ignoreversion + Source: "config"; DestDir: "{app}\bin"; [Icons] *************** *** 27,31 **** [Run] ! Filename: "{app}\install\vcInstall.exe"; Parameters: "{app}\install {app}\bin"; Check: CreateConfig({app}\bin\config) [UninstallDelete] --- 28,32 ---- [Run] ! Filename: "{app}\install\vcInstall.exe"; WorkingDir: "{app}\install"; Parameters: ". ..\bin" [UninstallDelete] *************** *** 37,46 **** [Registry] Root: HKLM; Subkey: "Software\gccxml"; ValueType: string; ValueName: "loc"; ValueData: {app}; Flags: uninsdeletekey - - [Code] - function CreateConfig(filename: String) : Boolean; - begin - SaveStringToFile(filename, 'GCCXML_COMPILER="cl"', false); - Result := true; - end; - --- 38,39 ---- |
From: Thomas H. <th...@us...> - 2005-03-14 10:33:53
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3930 Modified Files: ChangeLog Log Message: Record changes. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.79 retrieving revision 1.80 diff -C2 -d -r1.79 -r1.80 *** ChangeLog 11 Mar 2005 20:09:15 -0000 1.79 --- ChangeLog 14 Mar 2005 10:33:41 -0000 1.80 *************** *** 1,2 **** --- 1,10 ---- + 2005-03-14 Thomas Heller <th...@py...> + + * _ctypes.c: Fixed refcount leak in functions with 'out' + parameters. + + * _ctypes.c: Keyword arguments to Structures/Unions were ignored. + Thanks to Jimmy Retzlaff for finding this. + 2005-03-11 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2005-03-14 10:31:44
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3314 Modified Files: _ctypes.c Log Message: Fix refcount leaks in _build_callargs(). Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.222 retrieving revision 1.223 diff -C2 -d -r1.222 -r1.223 *** _ctypes.c 14 Mar 2005 07:57:55 -0000 1.222 --- _ctypes.c 14 Mar 2005 10:31:31 -0000 1.223 *************** *** 2549,2552 **** --- 2549,2555 ---- + /* + _byref consumes a refcount to its argument + */ static PyObject * _byref(PyObject *obj) *************** *** 2560,2569 **** parg = new_CArgObject(); ! if (parg == NULL) return NULL; parg->tag = 'P'; parg->pffi_type = &ffi_type_pointer; - Py_INCREF(obj); parg->obj = obj; parg->value.p = ((CDataObject *)obj)->b_ptr; --- 2563,2573 ---- parg = new_CArgObject(); ! if (parg == NULL) { ! Py_DECREF(obj); return NULL; + } parg->tag = 'P'; parg->pffi_type = &ffi_type_pointer; parg->obj = obj; parg->value.p = ((CDataObject *)obj)->b_ptr; *************** *** 2676,2680 **** case PARAMFLAG_FOUT: /* 'out' parameter. ! It's argtypes must be a POINTER of a c type. */ ob = PyTuple_GET_ITEM(argtypes, i); --- 2680,2684 ---- case PARAMFLAG_FOUT: /* 'out' parameter. ! argtypes[i] must be a POINTER to a c type. */ ob = PyTuple_GET_ITEM(argtypes, i); *************** *** 2682,2687 **** /* Create an instance of the pointed-to type */ ob = PyObject_CallObject(dict->proto, NULL); /* Insert as byref parameter */ ! PyTuple_SET_ITEM(callargs, i, _byref(ob)); outmask |= (1 << i); break; --- 2686,2696 ---- /* Create an instance of the pointed-to type */ ob = PyObject_CallObject(dict->proto, NULL); + if (ob == NULL) + goto error; /* Insert as byref parameter */ ! ob = _byref(ob); ! if (ob == NULL) ! goto error; ! PyTuple_SET_ITEM(callargs, i, ob); outmask |= (1 << i); break; *************** *** 2704,2708 **** if (ob == 0) goto error; ! PyTuple_SET_ITEM(callargs, i, _byref(ob)); outmask |= (1 << i); break; --- 2713,2720 ---- if (ob == 0) goto error; ! ob = _byref(ob); ! if (ob == NULL) ! goto error; ! PyTuple_SET_ITEM(callargs, i, ob); outmask |= (1 << i); break; *************** *** 2788,2793 **** char *tag = PyString_AS_STRING(dict->proto); /* simple data type, but no pointer */ ! if (tag[0] == 'P') return result; } if (dict->getfunc) { --- 2800,2807 ---- char *tag = PyString_AS_STRING(dict->proto); /* simple data type, but no pointer */ ! if (tag[0] == 'P') { ! Py_INCREF(result); return result; + } } if (dict->getfunc) { |
From: Thomas H. <th...@us...> - 2005-03-14 08:06:23
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30055 Modified Files: test_structures.py Log Message: Test invalid types in Structure _fields_. Test keyword arguments in Structure.__init__(). Index: test_structures.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_structures.py,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** test_structures.py 20 Jan 2005 21:06:46 -0000 1.31 --- test_structures.py 14 Mar 2005 08:06:12 -0000 1.32 *************** *** 216,219 **** --- 216,234 ---- self.assertRaises(ValueError, Person, "1234567", 5) + + def test_keyword_initializers(self): + class POINT(Structure): + _fields_ = [("x", c_int), ("y", c_int)] + pt = POINT(1, 2) + self.failUnlessEqual((pt.x, pt.y), (1, 2)) + + pt = POINT(y=2, x=1) + self.failUnlessEqual((pt.x, pt.y), (1, 2)) + + def test_invalid_field_types(self): + class POINT(Structure): + pass + self.assertRaises(TypeError, setattr, POINT, "_fields_", [("x", 1), ("y", 2)]) + def test_intarray_fields(self): class SomeInts(Structure): |
From: Thomas H. <th...@us...> - 2005-03-14 08:03:58
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29481 Modified Files: stgdict.c Log Message: Check for invalid types in Structure _fields_. Index: stgdict.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/stgdict.c,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** stgdict.c 10 Feb 2005 09:18:37 -0000 1.31 --- stgdict.c 14 Mar 2005 08:03:47 -0000 1.32 *************** *** 264,267 **** --- 264,273 ---- } dict = PyType_stgdict(desc); + if (dict == NULL) { + PyErr_Format(PyExc_TypeError, + "second item in _fields_ tuple (index %d) must be a C type", + i); + return -1; + } stgdict->ffi_type.elements[ffi_ofs + i] = &dict->ffi_type; dict->flags |= DICTFLAG_FINAL; /* mark field type final */ |
From: Thomas H. <th...@us...> - 2005-03-14 07:58:07
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28061 Modified Files: _ctypes.c Log Message: Don't ignore keyword arguments in Structure.__init__(). Reported by Jimmy Retzlaff. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.221 retrieving revision 1.222 diff -C2 -d -r1.221 -r1.222 *** _ctypes.c 11 Mar 2005 19:26:59 -0000 1.221 --- _ctypes.c 14 Mar 2005 07:57:55 -0000 1.222 *************** *** 3069,3112 **** return -1; } ! if (PyTuple_GET_SIZE(args) == 0) ! return 0; /* no initializers: nothing to do */ ! fields = PyObject_GetAttrString(self, "_fields_"); ! if (!fields) { ! PyErr_Clear(); ! fields = PyTuple_New(0); ! } ! ! if (PyTuple_GET_SIZE(args) > PySequence_Length(fields)) { ! Py_DECREF(fields); ! PyErr_SetString(PyExc_ValueError, ! "too many initializers"); ! return -1; ! } ! ! for (i = 0; i < PyTuple_GET_SIZE(args); ++i) { ! PyObject *pair = PySequence_GetItem(fields, i); ! PyObject *name; ! PyObject *val; ! if (!pair) { ! Py_DECREF(fields); ! return IBUG("_fields_[i] failed"); ! } ! ! name = PySequence_GetItem(pair, 0); ! if (!name) { ! Py_DECREF(fields); ! return IBUG("_fields_[i][0] failed"); } ! val = PyTuple_GET_ITEM(args, i); ! if (-1 == PyObject_SetAttr(self, name, val)) { Py_DECREF(fields); return -1; } ! Py_DECREF(name); ! Py_DECREF(pair); } - Py_DECREF(fields); if (kwds) { --- 3069,3112 ---- return -1; } ! if (PyTuple_GET_SIZE(args)) { ! fields = PyObject_GetAttrString(self, "_fields_"); ! if (!fields) { ! PyErr_Clear(); ! fields = PyTuple_New(0); } ! if (PyTuple_GET_SIZE(args) > PySequence_Length(fields)) { Py_DECREF(fields); + PyErr_SetString(PyExc_ValueError, + "too many initializers"); return -1; } ! for (i = 0; i < PyTuple_GET_SIZE(args); ++i) { ! PyObject *pair = PySequence_GetItem(fields, i); ! PyObject *name; ! PyObject *val; ! if (!pair) { ! Py_DECREF(fields); ! return IBUG("_fields_[i] failed"); ! } ! ! name = PySequence_GetItem(pair, 0); ! if (!name) { ! Py_DECREF(fields); ! return IBUG("_fields_[i][0] failed"); ! } ! ! val = PyTuple_GET_ITEM(args, i); ! if (-1 == PyObject_SetAttr(self, name, val)) { ! Py_DECREF(fields); ! return -1; ! } ! ! Py_DECREF(name); ! Py_DECREF(pair); ! } ! Py_DECREF(fields); } if (kwds) { |
From: Thomas H. <th...@us...> - 2005-03-11 20:43:45
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9865 Modified Files: setup.py Log Message: Add the ctypes.wrap package. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.119 retrieving revision 1.120 diff -C2 -d -r1.119 -r1.120 *** setup.py 11 Mar 2005 19:26:14 -0000 1.119 --- setup.py 11 Mar 2005 20:43:35 -0000 1.120 *************** *** 412,416 **** # the ctypes package # ! packages = ["ctypes"] package_dir = {} --- 412,416 ---- # the ctypes package # ! packages = ["ctypes", "ctypes.wrap"] package_dir = {} |
From: Thomas H. <th...@us...> - 2005-03-11 20:32:47
|
Update of /cvsroot/ctypes/ctypes/docs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6550 Modified Files: tutorial.stx index.stx Log Message: Updates for 0.9.5. Index: index.stx =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/index.stx,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** index.stx 28 Oct 2004 18:13:15 -0000 1.9 --- index.stx 11 Mar 2005 20:32:38 -0000 1.10 *************** *** 1,5 **** The ctypes module ! overview :: "tutorial":tutorial.html :: "reference":reference.html :: "faq":faq.html --- 1,5 ---- The ctypes module ! overview :: "tutorial":tutorial.html :: "codegenerator":codegen.html :: "reference":reference.html :: "faq":faq.html *************** *** 8,21 **** Overview ! 'ctypes' is a Python package to create and manipulate C data types ! in Python, and to call functions in dynamic link libraries/shared ! dlls. It allows wrapping these libraries in pure Python. ! It works on Windows, Linux and MacOS X and other systems. The ! latter require that your machine is supported by libffi. News ! **'ctypes' version 0.9.2 has been released (Oct 28, 2004).** Fixed several bugs and memory leaks. --- 8,81 ---- Overview ! 'ctypes' is an advanced ffi (Foreign Function Interface) package for ! Python 2.3 and higher. ! 'ctypes' allows to call functions exposed from dlls/shared libraries ! and has extensive facilities to create, access and manipulate ! simple and complicated C data types in Python - in other words: ! wrap libraries in pure Python. It is even possible to implement C ! callback functions in pure Python. ! ! ctypes works on Windows, Mac OS X, Linux, Solaris, FreeBSD, OpenBSD. ! It may also run on other systems, provided that libffi supports ! this platform. ! ! For windows, ctypes contains a ctypes.com package which allows to ! call and implement custom COM interfaces. ! ! Detailed changelogs are in CVS (well, sometimes I forget to update ! them): ! ! "ANNOUNCE":http://cvs.sourceforge.net/viewcvs.py/ctypes/ctypes/ANNOUNCE?rev=release_0_9_5 ! ! "ChangeLog":http://cvs.sourceforge.net/viewcvs.py/ctypes/ctypes/ChangeLog?rev=HEAD ! ! "com ChangeLog":http://cvs.sourceforge.net/viewcvs.py/ctypes/ctypes/win32/com/ChangeLog?rev=HEAD News ! **'ctypes' version 0.9.5 has been released (Mar 1, 2005).** ! ! New package 'ctypes.wrap'. It contains decorators for easier ! creation of wrapper functions. ! ! This package also contains a toolchain for (semi)automatic ! creation of wrappers for external libraries - it can parse C ! header files and generate ctypes code for the declarations in ! them. It can even handle preprocessor definitions! For details, ! see ! "codegenerator":codegen.html ! ! On systems where sizeof(int) == sizeof(long), c_int/c_long and ! c_uint/c_ulong are now aliases. Similar for c_long/c_longlong and ! c_ulong/c_ulonglong. This prevents unneeded type errors. ! ! If an exception occurs in a callback function, a full traceback is ! now printed. Raising SystemExit in a callback function now ! correctly exists Python. ! ! HRESULT is now a proper ctype - no longer a function. This allows ! to use it in the argtypes sequence for function prototypes. ! ! An easier way to define structures and unions that reference ! themselves, or have dependencies to other data types. The ! _fields_ attribute can now be set *after* the Structure/Union ! class has been created. This makes the SetPointerType function ! obsolete. ! ! The semantics of the _fields_ attribute in sub-subclasses of ! Structure and Union has been fixed. The baseclasses _fields_ list ! is extended, not replaced, in subclasses. Assigning _fields_ when ! it is no longer possible raises an error now. ! ! Structures and unions now work as restype and in the argtypes list ! for functions. ! ! An important bug has been fixed with pointers. ! ! ! Older news ! ! 'ctypes' version 0.9.2 has been released (Oct 28, 2004): Fixed several bugs and memory leaks. *************** *** 50,110 **** ! Detailed changelogs are in CVS (well, sometimes I forget to update ! them): ! ! "ANNOUNCE":http://cvs.sourceforge.net/viewcvs.py/ctypes/ctypes/ANNOUNCE?rev=release_0_9_2 ! ! "ChangeLog":http://cvs.sourceforge.net/viewcvs.py/ctypes/ctypes/ChangeLog?rev=HEAD ! ! "com ChangeLog":http://cvs.sourceforge.net/viewcvs.py/ctypes/ctypes/win32/com/ChangeLog?rev=HEAD ! ! ! Future plans ! ! The ultimate purpose of the 0.9 release series is to shake out the ! remaining bugs, especially on platforms I have no access to, and ! to target a rock stable ctypes 1.0 release. ! ! When ctypes 1.0 is released, the com framework will be split off ! into a separate framework named 'comtypes'. ! ! ! Testimonials ! ! *I am using it and much prefer it to the calldll/windll ! ... easy to use, well documented ...* - Ben C ! ! *Your ctypes stuff is awesome! Thanks so much for making ! it. Almost every time I write a C extension it's so I can call ! some Windows function - I don't know if I'll need to do that much ! anymore and that makes me very happy. :)* - Dave Brueck ! ! <!-- ! *Naive questioners who just want to get at a DLL with Python ! probably are in search of ctypes.* - Dr. Dobb's Python-URL! ! --> ! ! *ctypes! With stuff like Pysco and Pyrex maturing, the main reason ! I was still writing C extensions was to access various Windows ! APIs (especially those not covered in the Win32 Python ! extensions), but no longer - I may never write another "wrapper" ! extension again and that makes me very, very happy. :)* - Dave ! Brueck ! ! *I like the idea of using ctypes for creating highly native ! windows applications. So far I have been using wxPython, but that ! library is so big that it adds 3-4 seconds latency to the startup ! of the python :-), Also memory footprint is kind of huge.* - Henk Punt ! ! *... and I just started using ctypes tonight. Good old ! calldll/windll won't be in my toolkit much longer. :) It's a very ! exciting time for Python. Between Psyco and ctypes, writing code ! in C is becoming quite rare for me!* - Jimmy Retzlaff ! ! *ctypes is very cool! Great piece of work.* - Just van Rossum ! ! Old news ! ! **'ctypes' 0.9.0:** 'ctypes' now requires Python 2.3 or higher, Python 2.2 is no longer --- 110,114 ---- ! 'ctypes' 0.9.0: 'ctypes' now requires Python 2.3 or higher, Python 2.2 is no longer Index: tutorial.stx =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/tutorial.stx,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** tutorial.stx 30 Dec 2004 18:03:50 -0000 1.24 --- tutorial.stx 11 Mar 2005 20:32:37 -0000 1.25 *************** *** 1,5 **** ctypes tutorial ! "overview":index.html :: tutorial :: "reference":reference.html :: "faq":faq.html --- 1,5 ---- ctypes tutorial ! "overview":index.html :: tutorial :: "codegenerator":codegen.html :: "reference":reference.html :: "faq":faq.html |
From: Thomas H. <th...@us...> - 2005-03-11 20:10:37
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32138 Modified Files: ANNOUNCE Log Message: Announcement for 0.9.5. Index: ANNOUNCE =================================================================== RCS file: /cvsroot/ctypes/ctypes/ANNOUNCE,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** ANNOUNCE 28 Oct 2004 18:41:16 -0000 1.18 --- ANNOUNCE 11 Mar 2005 20:10:26 -0000 1.19 *************** *** 1,9 **** ! ctypes 0.9.2 released - Oct 28, 2004 ==================================== Overview ! ctypes is a ffi (Foreign Function Interface) package for Python ! 2.3 and higher. ctypes allows to call functions exposed from dlls/shared libraries --- 1,9 ---- ! ctypes 0.9.5 released - Mar 11, 2005 ==================================== Overview ! ctypes is an advanced ffi (Foreign Function Interface) package for ! Python 2.3 and higher. ctypes allows to call functions exposed from dlls/shared libraries *************** *** 17,21 **** this platform. ! On windows, ctypes contains a ctypes.com package which allows to call and implement custom COM interfaces. --- 17,21 ---- this platform. ! For windows, ctypes contains a ctypes.com package which allows to call and implement custom COM interfaces. *************** *** 23,60 **** If you download the source distribution, please choose the ZIP ! file for Windows, and the .tar.gz file for other systems. These archive have different contents! ! Changes in 0.9.2 ! Fixed several bugs and memory leaks. ! ctypes is now tested on Windows, Linux (x86 and x86_64), OpenBSD ! and Mac OS X. ! Implemented some helper functions: memmove, memset, string_at, wstring_at. ! The former act as their C library counterpart, the latter two allow ! to read a zero-terminated (wide) strings at a certain address. - Implemented a cast(cobj, ctype) function, which creates a new object - of the specified ctype from an existing object. ! ctypes now explicitely allocates executable memory for the callbacks ! it creates, this makes it work correctly on platforms where ! executing data is normally forbidden (OpenBSD, Win XP SP2 on AMD 64). ! Fixed the unicode handling on non-windows platforms. ! Bit fields in structures and unions are now implemented. ! For a bit field, one would specify the width in bits as the third ! part in the _fields_ list like this: ! class BitFieldSample(Structure): ! _fields_ = [("anInt", c_int), ! ("aBitField", c_int, 3)] ! POINTER(None) now returns c_void_p. This change was made for easier ! code generation, and makes sense since 'None' is the ctypes way to ! spell 'void'. --- 23,73 ---- If you download the source distribution, please choose the ZIP ! file for Windows, and the .tar.gz file for other machines. These archive have different contents! ! There have been lots of changes - if you are the author or user of ! a package that uses ctypes, please test it with this release ! and report problems on the ctypes-users mailing list. ! Additions ! New package ctypes.wrap. This contains decorators usable for ! easier creation of wrapper functions. ! This package also contains a toolchain for (semi)automatic ! creation of wrappers for external libraries - it can parse ! C header files and generate ctypes code for the declarations in ! them. It can even handle preprocessor definitions! For details, ! see http://starship.python.net/crew/theller/ctypes/codegen.html ! Changes in 0.9.5 ! On systems where sizeof(int) == sizeof(long), c_int/c_long and ! c_uint/c_ulong are now aliases. Similar for c_long/c_longlong and ! c_ulong/c_ulonglong. This prevents unneeded type errors. ! If an exception occurs in a callback function, a full traceback is ! now printed. Raising SystemExit in a callback function now ! correctly exists Python. ! HRESULT is now a proper ctype - no longer a function. This allows ! to use it in the argtypes sequence for function prototypes. ! An easier way to define structures and unions that reference ! themselves, or have dependencies to other data types. The ! _fields_ attribute can now be set *after* the Structure/Union ! class has been created. This makes the SetPointerType function ! obsolete. ! ! The semantics of the _fields_ attribute in sub-subclasses of ! Structure and Union has been fixed. The baseclasses _fields_ list ! is extended, not replaced, in subclasses. Assigning _fields_ when ! it is no longer possible raises an error now. ! ! Structures and unions now work as restype and in the argtypes list ! for functions. ! ! An important bug has been fixed with pointers. *************** *** 66,79 **** - Future plans - - The ultimate purpose of the 0.9 release series is to shake out the - remaining bugs, especially on platforms I have no access to, and - to target a rock stable ctypes 1.0 release. - - When ctypes 1.0 is released, the com framework will be split off - into a separate framework named 'comtypes'. - - Download --- 79,82 ---- |
From: Thomas H. <th...@us...> - 2005-03-11 20:09:59
|
Update of /cvsroot/ctypes/ctypes/ctypes/wrap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31949 Added Files: codegen.txt Log Message: Documentation for the code generator. --- NEW FILE: codegen.txt --- =============================== README: ctypes code generation =============================== .. _REST quickref (only for the editor): http://docutils.sourceforge.net/docs/user/rst/quickstart.html This document describes the ctypes code generator. The generator converts declarations in C header files into executable Python code: enums, structs, unions, function declarations, com interfaces, and preprocessor definitions. .. contents:: Overview ======== Creating wrappers for C header file(s) is a two step process. First, the ``h2xml.py`` script runs GCC-XML_ over the include file(s), creating a XML file containing declarations and definitions. Second, the ``xml2py.py`` script parses the XML files and creates Python code containing all or a subset of these definitions. Python code is generated for C enums, structure, unions, typedefs and function declarations. Also included are preprocessor definitions, as far as they can be converted to valid Python code. It is possible to filter the output so that only a subset of the definitions are converted, so it is either possible to generate a complete Python module wrapping a shared library, or the generator can be used to create snippets of Python code which can be pasted into a manually written module. Requirements ============ GCC-XML_ (from http://www.gccxml.org/) is required to parse C header files into an XML description. **Unfortunately the latest official version 0.6.0 does not fulfill the ctypes code generator requirements.** For windows, you can download a prebuild `GCC-XML windows installer`_ from `the ctypes download page`_ (this is an unofficial release). Please note that even the *installation* of GCC-XML requires that MSVC 6, 7, or 7.1 is installed on your system, because it needs the system header files. For other platforms you must `get the development version from CVS`_ and `build GCC-XML from source`_. .. _the ctypes download page: http://sourceforge.net/project/showfiles.php?group_id=71702 .. _GCC-XML windows installer: http://sourceforge.net/project/showfiles.php?group_id=71702&package_id=146740&release_id=311918 .. _GCC-XML: http://www.gccxml.org/ .. _build GCC-XML from source: http://www.gccxml.org/HTML/Install.html .. _get the development version from CVS: http://www.gccxml.org/HTML/Download.html Usage examples ============== Here are several examples that show how to call the ``h2xml.py`` and ``xml2py.py`` scripts, and the code they generate. The output has sometimes been cleaned up a bit, for clarity. Generally, the codegenerator creates a lot of comments pointing to the C header file. This is useful to quickly look up the C source code. Parse the windows header files (this may take a while):: C:\>python h2xml.py windows.h -o windows.xml -q C:\> Generate code for the ``RECT`` structure:: C:\>xml2py.py windows.xml -s RECT from ctypes import * LONG = c_long class tagRECT(Structure): pass RECT = tagRECT tagRECT._fields_ = [ ('left', c_long), ('top', c_long), ('right', c_long), ('bottom', c_long), ] assert sizeof(tagRECT) == 16, sizeof(tagRECT) assert alignment(tagRECT) == 4, alignment(tagRECT) C:\> Generate the ``MB_xxx`` constants, which are flags used for the ``MessageBox`` function:: c:\>python xml2py.py windows.xml -r MB_.* # generated by 'xml2py.py' # flags 'windows.xml -r MB_.*' MB_USERICON = 128 MB_DEFBUTTON3 = 512 MB_USEGLYPHCHARS = 4 MB_ABORTRETRYIGNORE = 2 MB_ICONASTERISK = 64 MB_ICONINFORMATION = MB_ICONASTERISK MB_ICONHAND = 16 MB_ICONERROR = MB_ICONHAND MB_ICONEXCLAMATION = 48 MB_ICONWARNING = MB_ICONEXCLAMATION MB_RIGHT = 524288 MB_SYSTEMMODAL = 4096 MB_ICONQUESTION = 32 MB_APPLMODAL = 0 MB_OK = 0 MB_TYPEMASK = 15 MB_MODEMASK = 12288 MB_TASKMODAL = 8192 MB_OKCANCEL = 1 MB_RETRYCANCEL = 5 MB_DEFAULT_DESKTOP_ONLY = 131072 MB_RTLREADING = 1048576 MB_PRECOMPOSED = 1 MB_DEFBUTTON1 = 0 MB_DEFMASK = 3840 MB_DEFBUTTON2 = 256 MB_YESNOCANCEL = 3 MB_CANCELTRYCONTINUE = 6 MB_HELP = 16384 MB_ICONMASK = 240 MB_SETFOREGROUND = 65536 MB_TOPMOST = 262144 MB_COMPOSITE = 2 MB_DEFBUTTON4 = 768 MB_YESNO = 4 MB_ERR_INVALID_CHARS = 8 MB_NOFOCUS = 32768 MB_ICONSTOP = MB_ICONHAND MB_MISCMASK = 49152 C:\> Generate code for the ``RegisterClass`` function, note how this pulls in a lot of types (if you want code compatible with Python 2.3 don't use the ``-d`` flag):: C:\>python xml2py.py windows.xml -w -s RegisterClass -d # generated by 'xml2py' # flags 'windows.xml -w -s RegisterClass' from ctypes import * from ctypes import decorators WORD = c_ushort ATOM = WORD class tagWNDCLASSA(Structure): pass WNDCLASSA = tagWNDCLASSA @ decorators.stdcall(ATOM, 'user32', [POINTER(WNDCLASSA)]) def RegisterClassA(p1): return RegisterClassA._api_(p1) RegisterClass = RegisterClassA UINT = c_uint LONG_PTR = c_long LRESULT = LONG_PTR WNDPROC = WINFUNCTYPE(LRESULT, c_void_p, c_uint, c_uint, c_long) PVOID = c_void_p HANDLE = PVOID HINSTANCE = HANDLE HICON = HANDLE HCURSOR = HICON HBRUSH = HANDLE CHAR = c_char LPCSTR = POINTER(CHAR) tagWNDCLASSA._fields_ = [ ('style', UINT), ('lpfnWndProc', WNDPROC), ('cbClsExtra', c_int), ('cbWndExtra', c_int), ('hInstance', HINSTANCE), ('hIcon', HICON), ('hCursor', HCURSOR), ('hbrBackground', HBRUSH), ('lpszMenuName', LPCSTR), ('lpszClassName', LPCSTR), ] assert sizeof(tagWNDCLASSA) == 40, sizeof(tagWNDCLASSA) assert alignment(tagWNDCLASSA) == 4, alignment(tagWNDCLASSA) Generate code for the ``ICreateErrorInfo`` com interface. This example uses the ``-m`` command line flag, and the generated code imports several symbols from the specified ``ctypes.com`` module. Note that the ``_iid_`` member of the interface cannot be created by the code generator, but the generated comment allows to quickly locate the header file and patch this manually:: C:\sf\ctypes\ctypes\wrap>xml2py windows.xml -s ICreateErrorInfo -m ctypes.com # generated by 'xml2py' # flags 'windows.xml -s ICreateErrorInfo -m ctypes.com' from ctypes import * from ctypes.com import IUnknown from ctypes.com import GUID class ICreateErrorInfo(IUnknown): _iid_ = GUID('{}') # please look up iid and fill in! # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 5366 pass from ctypes.com import HRESULT from ctypes.com import GUID WCHAR = c_wchar OLECHAR = WCHAR LPOLESTR = POINTER(OLECHAR) from ctypes.com import DWORD from ctypes.com import STDMETHOD ICreateErrorInfo._methods_ = IUnknown._methods + [ # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 5366 STDMETHOD(HRESULT, 'SetGUID', [POINTER(GUID)]), STDMETHOD(HRESULT, 'SetSource', [LPOLESTR]), STDMETHOD(HRESULT, 'SetDescription', [LPOLESTR]), STDMETHOD(HRESULT, 'SetHelpFile', [LPOLESTR]), STDMETHOD(HRESULT, 'SetHelpContext', [DWORD]), ] Create a Python module ``win_lean.py`` containing wrappers for the 'lean' windows api, this creates a fairly large file:: C:\>python h2xml.py windows.h -D WIN32_LEAN_AND_MEAN -D NO_STRICT -o win_lean.xml -q C:\>python xml2py.py win_lean.xml -w -o win_lean.py Create a Python module ``SDL.py`` containing wrappers for the ``SDL`` library. To work around a problem GCC-XML has with a certain construct in the SDL header files on Windows, you must define the ``SDLCALL`` macro to an empty value:: C:\>python h2xml.py SDL.h -I SDL\include -D SDLCALL= -o SDL.xml -q C:\>python xml2py.py SDL.xml -o SDL.py -l SDL.dll C:\> The h2xml.py script =================== ``h2xml.py`` lets you specify the names of the header files to parse, the name of the XML output file, and a few options which are passed to GCC-XML. The ``-D``, ``-E``, and ``-I`` flags may occur several times. ``-h, --help`` Print a short usage summary and exit. ``-q, --quiet`` Run in quiet mode. The default mode is verbose, ``h2xml.py`` prints what it is currently doing. ``-D name[=value]`` This flag defines a preprocessor name. ``-U name`` This flag undefines a preprocessor name. ``-I directory`` This flag defines an additional include directory. ``-o xmlfile`` This flag specifies name and path of the XML output file. The xml2py.py script ==================== ``-h, --help`` Print a short usage summary and exit. ``-d`` Use Python 2.4 decorators for wrapped functions. ``-k[d][e][f][m][s][t]`` Specifies the kind of types to include in the output: ``d`` - simple preprocessor definitions: #define <identifier> <identifier> ``e`` - enumerations ``f`` - function declarations ``m`` - preprocessor macros taking parameters: #define <ident>(parameters) something ``s`` - structures and unions ``t`` - typedefs ``-l sharedlib`` specify shared library to search for exported functions. ``-m module`` specifies a Python module containing symbols that will be imported instead of generated. ``-o outputfile`` name of the output file containing Python code. If not specified, the code is printed to standard output. ``-r regular_expression`` regular expression specifying names of symbols to include. ``-s symbol`` name of symbol to include. ``-v`` verbose mode: prints a short summary of types generated. ``-w`` windows only: add all standard windows dlls to the list of shared libraries searched for functions. Note that specifying the ``-k``, ``-s``, and ``-r`` flags create a start set of type declarations, the generated code, however, may also contain other types. If, for example, the code for an external function is generated, code for the argument and return types is also needed. Also note that code for function declarations is only created when ``xml2py.py`` can locate the function in one of the shared libraries specified with ``-l`` or ``-w``. Getting Help ============ If you have questions or need assistance with *ctypes* or the code generator, please `post a message`_ to the `ctypes-users mailing list`_. .. _post a message: mailto:cty...@li... .. _ctypes-users mailing list: http://lists.sourceforge.net/lists/listinfo/ctypes-users .. Local Variables: mode: indented-text indent-tabs-mode: nil sentence-end-double-space: t fill-column: 70 compile-command: "make" End: |
From: Thomas H. <th...@us...> - 2005-03-11 20:09:28
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31838 Modified Files: ChangeLog Log Message: Record changes. I'll release 0.9.5 now. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.78 retrieving revision 1.79 diff -C2 -d -r1.78 -r1.79 *** ChangeLog 10 Feb 2005 09:20:26 -0000 1.78 --- ChangeLog 11 Mar 2005 20:09:15 -0000 1.79 *************** *** 1,2 **** --- 1,16 ---- + 2005-03-11 Thomas Heller <th...@py...> + + * ctypes-0.9.5 released. + + * The prototypes that WINFUNCTYPE or CFUNCTYPE return can now be + called with an optional third parameter: paramflags. This must be + a tuple specifying the parameter direction (in, out), the + parameter name (optional), and the default parameter value (also + optional). This creates a somewhat higher level function, and + also allows to call functions with named parameters. + + The change made on 2005-01-15 has been reverted again - it is + better to create instancemethods, if needed, in the calling code. + 2005-02-10 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2005-03-11 19:27:18
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20874 Modified Files: _ctypes.c Log Message: Set version number to 0.9.5. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.220 retrieving revision 1.221 diff -C2 -d -r1.220 -r1.221 *** _ctypes.c 11 Mar 2005 11:04:34 -0000 1.220 --- _ctypes.c 11 Mar 2005 19:26:59 -0000 1.221 *************** *** 4035,4039 **** PyModule_AddObject(m, "FUNCFLAG_CDECL", PyInt_FromLong(FUNCFLAG_CDECL)); PyModule_AddObject(m, "FUNCFLAG_PYTHONAPI", PyInt_FromLong(FUNCFLAG_PYTHONAPI)); ! PyModule_AddStringConstant(m, "__version__", "0.9.3"); PyExc_ArgError = PyErr_NewException("ctypes.ArgumentError", NULL, NULL); --- 4035,4039 ---- PyModule_AddObject(m, "FUNCFLAG_CDECL", PyInt_FromLong(FUNCFLAG_CDECL)); PyModule_AddObject(m, "FUNCFLAG_PYTHONAPI", PyInt_FromLong(FUNCFLAG_PYTHONAPI)); ! PyModule_AddStringConstant(m, "__version__", "0.9.5"); PyExc_ArgError = PyErr_NewException("ctypes.ArgumentError", NULL, NULL); |
From: Thomas H. <th...@us...> - 2005-03-11 19:26:51
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20807 Modified Files: __init__.py Log Message: Set version number to 0.9.5. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** __init__.py 7 Mar 2005 09:26:12 -0000 1.55 --- __init__.py 11 Mar 2005 19:26:42 -0000 1.56 *************** *** 9,13 **** del _magicfile ! __version__ = "0.9.3" from _ctypes import Union, Structure, Array --- 9,13 ---- del _magicfile ! __version__ = "0.9.5" from _ctypes import Union, Structure, Array |
From: Thomas H. <th...@us...> - 2005-03-11 19:26:28
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20697 Modified Files: setup.py Log Message: Set version number to 0.9.5. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.118 retrieving revision 1.119 diff -C2 -d -r1.118 -r1.119 *** setup.py 11 Mar 2005 07:55:26 -0000 1.118 --- setup.py 11 Mar 2005 19:26:14 -0000 1.119 *************** *** 12,16 **** LIBFFI_SOURCES='source/gcc/libffi' ! __version__ = "0.9.3" ################################################################ --- 12,16 ---- LIBFFI_SOURCES='source/gcc/libffi' ! __version__ = "0.9.5" ################################################################ |