[ctypes-commit] ctypes/sandbox/tools/codegen generate.py,1.12,1.13
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2004-11-12 09:36:23
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7579 Modified Files: generate.py Log Message: Field offset is an integer. Index: generate.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/generate.py,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** generate.py 12 Nov 2004 09:00:36 -0000 1.12 --- generate.py 12 Nov 2004 09:36:11 -0000 1.13 *************** *** 52,61 **** pass ! def _calc_packing(struct, fields, pack, verbose): if struct.size is None: # incomplete struct return -1 if struct.name in dont_assert_size: return None - assert not isinstance(struct, nodes.Union) if struct.bases: size = struct.bases[0].size --- 52,62 ---- pass ! def _calc_packing(struct, fields, pack): ! # Try a certain packing, raise PackingError if field offsets, ! # total size ot total alignment is wrong. if struct.size is None: # incomplete struct return -1 if struct.name in dont_assert_size: return None if struct.bases: size = struct.bases[0].size *************** *** 66,70 **** for i, f in enumerate(fields): if f.bits: ! return -2 s, a = storage(f.typ) if pack is not None: --- 67,71 ---- for i, f in enumerate(fields): if f.bits: ! return -2 # XXX FIXME s, a = storage(f.typ) if pack is not None: *************** *** 72,77 **** if size % a: size += a - size % a ! if size != int(f.offset): ! raise PackingError, "field offset" size += s total_align = max(total_align, a) --- 73,78 ---- if size % a: size += a - size % a ! if size != f.offset: ! raise PackingError, "field offset (%s/%s)" % (size, f.offset) size += s total_align = max(total_align, a) *************** *** 84,94 **** size += a - size % a if size != struct.size: ! raise PackingError, "total size" ! def calc_packing(struct, fields, verbose=False): # try several packings, starting with unspecified packing for pack in [None, 16*8, 8*8, 4*8, 2*8, 1*8]: try: ! _calc_packing(struct, fields, pack, verbose) except PackingError, details: continue --- 85,95 ---- size += a - size % a if size != struct.size: ! raise PackingError, "total size (%s/%s)" % (size, struct.size) ! def calc_packing(struct, fields): # try several packings, starting with unspecified packing for pack in [None, 16*8, 8*8, 4*8, 2*8, 1*8]: try: ! _calc_packing(struct, fields, pack) except PackingError, details: continue *************** *** 326,329 **** --- 327,331 ---- # Hm, how to detect a COM interface with no methods? IXMLDOMCDATASection is such a beast... if not isinstance(body.struct, nodes.Union) and not methods: + ## if not methods: pack = calc_packing(body.struct, fields) if pack is not None: |