[Mono-list] Marshaling problem in .19

Jerome Laban jlaban@wanadoo.fr
Sun, 26 Jan 2003 19:11:06 +0100

This is a multi-part message in MIME format.

Content-Type: text/plain;
Content-Transfer-Encoding: 8bit


It seems that there is a interpretation bug in the
CustomAttributeBuilder.get_umarshal method.

Some fix for the CustomAttributeBuilder.cs file is included with this post.
(I don't know where to find the meaning of the two bytes before string
size). If I trust the header of the file, this is your code Paolo.

But this does not seem to be enough, for the type description of this struct

    public struct Test {
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst=4)]
        public string a;

Here is the IL disassembly from the mcs generated file :

    .field public marshal( fixed sysstring []) string a

Whereas with the csc generated file it is :

    .field public marshal( fixed sysstring[4]) string a

This seems to be an IL emitter bug, but I cannot find where it is...

By the way, the test file marshal2.cs fails with mono 0.19 and probably with
the 0.18 too.


----- Original Message ----- 
From: "Jérôme LABAN" <jlaban@wanadoo.fr>
To: <mono-list@ximian.com>
Sent: Saturday, January 25, 2003 9:08 PM
Subject: Re: [Mono-list] Marshaling problem in .19

> I'm also having troubles using String marshalling in some cases :
>     [MarshalAs(UnmanagedType.ByValStr, SizeConst=16)]
> seems to be loaded as
>     [MarshalAs(UnmanagedType.LPStr)]
> While actually, in the method emit_struct_info (marshal.c) on the line
> I presume that
> the info->fields[i].mspec should not return a NULL pointer when a marshal
> attribute is set.
> Using LPStr while it should be ByValStr leads the marshaller to use string
> data as a pointer.
> Is this a type loader problem ? mspec member should be filled with
> I guess...

Content-Type: application/octet-stream;
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;

< 		internal static string string_from_bytes (byte[] data, int pos, int =
len) {=0A=
< 			char[] chars =3D new char [len];=0A=
< 			// FIXME: use a utf8 decoder here=0A=
< 			for (int i =3D 0; i < len; ++i)=0A=
< 				chars [i] =3D (char)data [pos + i];=0A=
< 			return new String (chars);=0A=
>         internal static string string_from_bytes (byte[] data, int =
pos, int len)=20
>         {=0A=
>             return System.Text.Encoding.UTF8.GetString(data, pos, len);=0A=
> =0A=
>             int sizeConst =3D 0;=0A=
< 			for (int i =3D 0; i < nnamed; ++i) {=0A=
< 				byte type =3D data [pos++];=0A=
> 			for (int i =3D 0; i < nnamed; ++i)=0A=
>             {=0A=
>                 int paramType; // What is this ?=0A=
>                 paramType =3D (int)data [pos++];=0A=
>                 paramType |=3D ((int)data [pos++]) << 8;=0A=
> =0A=
> =0A=
>                 case "SizeConst":=0A=
>                     value =3D (int)data [pos++];=0A=
>                     value |=3D ((int)data [pos++]) << 8;=0A=
>                     value |=3D ((int)data [pos++]) << 16;=0A=
>                     value |=3D ((int)data [pos++]) << 24;=0A=
>                     sizeConst =3D value;=0A=
>                     break;=0A=
< 			switch ((UnmanagedType)utype) {=0A=
>             switch ((UnmanagedType)utype)=20
>             {=0A=
>                     return =
>                     return UnmanagedMarshal.DefineByValTStr(sizeConst);=0A=