[Scilab-users] Minimal mono/call_scilab example crashes with optimizations turned on
Bogdan Burlacu
froz3nshade at gmail.com
Fri Nov 8 12:02:24 CET 2013
On Fri, 08 Nov 2013 10:51:58 +0100
Sylvestre Ledru <sylvestre.ledru at scilab-enterprises.com> wrote:
> Hello,
>
> On 08/11/2013 10:28, Bogdan Burlacu wrote:
> > Hello,
> >
> > I am using Scilab-5.4.1 and mono-3.2.3, on 64-bit arch linux.
> >
> > I've attached a minimal example in the file test.cs (also posted on
> > http://pastebin.com/JukugFFs).
> >
> > The code is compiled with 'gmcs /reference:Mono.Posix.dll /unsafe
> > test.cs'
> >
> AFAIK, this feature has never been tested with Mono...
> I am glad to know that it is even starting correctly without the
> optimisation...
> You should try to make a smaller test case and/or build with the
> debug symbols.
>
> Sylvestre
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
Hello again,
I found out what the problem was:
Within Scilab, the SciErr struct is declared like this:
struct api_Err
{
int iErr;
int iMsgCount;
char* pstMsg[MESSAGE_STACK_SIZE];
} SciErr;
while in Scilab_cs_wrapper.cs, it is:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public unsafe struct api_Err
{
public int iErr;
public int iMsgCount;
public fixed int pstructMsg[5];
}
This struct should be defined as:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public unsafe struct api_Err
{
public int iErr;
public int iMsgCount;
public fixed char pstructMsg[5];
}
Notice I changed the last field from 'int' to 'char'.
Now, everything works fine. Credit goes to a reddit user which spotted
the difference:
http://www.reddit.com/r/csharp/comments/1pz9od/mono_scilab_unsafe_code_and_optimization/cd9hqab
Best,
Bogdan
More information about the users
mailing list