[cffi-devel] foreign-type-size of struct types

Luis Oliveira luismbo at gmail.com
Thu Aug 4 18:37:04 UTC 2005


On 4/ago/2005, at 13:33, Wilco Greven wrote:
> I'm using cffi for trying to revive the Qt bindings. Doing so I found 
> out that
> for the calculation of the size of struct types, the alignment of the 
> struct
> itself is not taking into account. For the following struct for example

What should the alignment of a struct type be? I think it depends on 
the ABI and I think right now they are being aligned as if they were 
void* pointers, that doesn't sound right.


> (defcstruct smoke-class
>   (class-name string)
>   (parents index)
>   (class-fn :pointer)
>   (enum-fn :pointer)
>   (flags :unsigned-short))

Is index a struct type? If not, what is the relevance of struct 
alignment here?


> cffi calculates a size of 18, which should be 20 (please correct me if 
> I'm
> wrong). Attached is a patch which defines an extra method for
> foreign-type-size for a foreign-struct-type argument. This method is 
> used to
> apply adjust-for-alignment on the newly defined struct.

Maybe I'm missing something, why should the struct's size be influenced 
by its own alignment requirements?

-- 
Luís Oliveira
http://student.dei.uc.pt/~lmoliv/
Equipa Portuguesa do Translation Project
http://www2.iro.umontreal.ca/~pinard/po/registry.cgi?team=pt




More information about the cffi-devel mailing list