[Mono-dev] Marshalling: Bug in StructLayout?
Rolf Bjarne Kvinge
rolflists at ya.com
Sat Aug 18 10:38:49 EDT 2007
> -----Original Message-----
> From: mono-devel-list-bounces at lists.ximian.com [mailto:mono-devel-list-
> bounces at lists.ximian.com] On Behalf Of Prakash Punnoor
> Sent: sábado, 18 de agosto de 2007 16:21
> To: mono-devel-list at lists.ximian.com
> Subject: [Mono-dev] Marshalling: Bug in StructLayout?
> I am not sure whether I am making something wrong or mono has a bug.
> Please see attached program. If declare the AVRational struct with
> explicit offsets, it works, otherwise the width member (and following)
> in AVFormatContext are off by 4 bytes.
Structs may be padded according to the platform you're running on, so it's not a bug.
MSDN says about SequentialLayout: The members of the object are laid out sequentially, in the order in which they appear when exported to unmanaged memory. The members are laid out according to the packing specified in StructLayoutAttribute.Pack, and can be noncontiguous.
You have to use explicit layout (or StructLayoutAttribute.Pack) to get the correct structure on all platforms.
> To reproduce: I am on x86_64 Linux (gentoo) using ffmpeg-
> 0.4.9_p20070616-r1 and tao bindings (http://www.taoframework.com/) from
> svn. Unfortunately the binding are not really matching with the ffmpeg
> version I have, so I started duplicating/correcting the structs, as you
> can see in the source files.
> Nevertheless I stumbled across above behaviour.
> I compiled the cs file using
> gmcs ff.cs /lib:/usr/lib64/mono/tao /r:Tao.FFmpeg /out:ff.exe
> Just copy an avi file to the folder with ff.exe, rename the avi to
> and try it out. Instead of the width the height gets printed out, which
> indicates that off by 4 bytes problem. If I set the EXPLICIT define, I
> get correct output
> I compiled mono using gcc 4.2.1, might that be a problem?
> (°= =°)
> //\ Prakash Punnoor /\\
> V_/ \_V
More information about the Mono-devel-list