[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.
------=_NextPart_000_058B_01C2C56E.ADA1ED20
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
Hi
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
:
[StructLayout(LayoutKind.Sequential)]
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.
___________
Jerome.
----- 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
3013,
> 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
something
> I guess...
>
------=_NextPart_000_058B_01C2C56E.ADA1ED20
Content-Type: application/octet-stream;
name="CustomAttributeBuilder.cs.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="CustomAttributeBuilder.cs.diff"
69,74c69,71=0A=
< 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=
---=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=
78a76=0A=
> =0A=
79a78=0A=
> int sizeConst =3D 0;=0A=
92,93c91,96=0A=
< for (int i =3D 0; i < nnamed; ++i) {=0A=
< byte type =3D data [pos++];=0A=
---=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=
96a100=0A=
> =0A=
104a109,115=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=
110c121,122=0A=
< switch ((UnmanagedType)utype) {=0A=
---=0A=
> switch ((UnmanagedType)utype)=20
> {=0A=
115a128=0A=
> return =
UnmanagedMarshal.DefineByValArray(sizeConst);=0A=
116a130=0A=
> return UnmanagedMarshal.DefineByValTStr(sizeConst);=0A=
------=_NextPart_000_058B_01C2C56E.ADA1ED20--