Re: feature request for setting _pack_ to a higher value
Thomas Heller <[email protected]>
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <[email protected]> |
Axel Seibert schrieb:
> Hi, Thomas!
>
> Thanx for asking -- no, I have not found any other solution yet.
Ok, so the remaining question was: How can I change a (generated) ctypes Union
definition so that the packing is a multiple of an arbitrary value, 8 in this case.
Background: A Union contains all the _fields_ in the same memory block (they overlay
each other; only one is normally valid), so the Union size is the size of the largest
field. We have now the goal to bring the union size up to a multiple of 8 by adding
a dummy field. Here is the ode that I wrote:
<snip>
from ctypes import *
def fill_union(value, fields):
size = 0
for name, typ in fields:
size = max(size, sizeof(typ))
delta = 8 - size % 8
return fields + [("", c_char * (size + delta))]
class X(Union):
_fields_ = fill_union(8, [("a", c_char),
("b", c_short),
("c", c_char * 31)])
print sizeof(X)
<snip/>
> So long,
> Axel
>
> Am 09.04.2010 um 10:02 schrieb Thomas Heller:
>
>> Axel Seibert schrieb:
>>> Hi, Thomas!
>>>
>>> I tried to apply your solution to my problem. I found two issues with that:
>>> a) a couple of my structs that require padding are Unions. Do you have a solution for that?
>>> b) I believe that line "missing = a - size % a" needs to be replaced by missing = a - sizeof(t) % a
>>
>> Axel - sorry for this delayed reply; I'm very short on time. Is the question
>> still open or did you find a solution yourself in the meantime?
>>
>> --
>> Thanks,
>> Thomas
>>
>>
>> ------------------------------------------------------------------------------
>> Download Intel® Parallel Studio Eval
>> Try the new software tools for yourself. Speed compiling, find bugs
>> proactively, and fine-tune applications for parallel performance.
>> See why Intel Parallel Studio got high marks during beta.
>> http://p.sf.net/sfu/intel-sw-dev
>> _______________________________________________
>> ctypes-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/ctypes-users
>>
>
>
> ------------------------------------------------------------------------------
> Download Intel® Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
--
Thanks,
Thomas
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev