Andrew Ward | 26 Jul 2012 13:11
Picon

C# marshalling of std::wstring on Linux

Hello,

On Linux with Mono I have a SWIG C# wrapper which marshals a C# string method parameter using:

[MarshalAs(UnmanagedType.LPWStr)]

This converts the C# string into a 2 byte native string and passes its address as a wchar_t * to the SWIG generated C wrapper function.

At this point the SWIG generated C function constructs a std::wstring from the wchar_t pointer, however on my Linux system, wchar_t is 4 bytes, therefore the wstring constructor goes ahead blindly thinking the wchar_t pointer contains 4 byte character data, but it in fact contains 2 byte character data.

The same assumption and problem seems to exist in SWIG_csharp_wstring_callback when returning strings.

Is this a bug in SWIG? And is there a way I can use typemaps to provide a custom to/from conversion for Linux (It all works fine on Windows).

Regards,


Andrew Ward.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user

Gmane