[Mono-list] Need help with DllImport (P/Invoke) and UCS-4 unicode

Christian Heimes lists at cheimes.de
Sun Jul 15 20:57:47 EDT 2007


Hello!

I'm working on PythonNet (http://pythonnet.sourceforge.net/). PythonNet
is an integration of the C library into .NET which allows a developer to
use .NET code inside Python or Python inside .NET. In the past few weeks
I've fixed a bunch of outstanding bugs and ported PythonNet to Python
2.5. It works pretty well on Windows.

However Linux with mono is a different story. Under Windows Python is
using a UCS-2 to store unicode but most Linux distributions (Debian,
Ubuntu and probably Redhat and SuSE) are compiling Python with UCS-4.
.NET supports only 2 byte unicode. My problem is perfectly explain at
http://www.mono-project.com/Interop_with_Native_Libraries#P.2FInvoke_Specification

One of the problematic function look like:

    [DllImport(Runtime.dll, CallingConvention = CallingConvention.Cdecl,
           EntryPoint = "PyUnicodeUCS4_FromUnicode",
           ExactSpelling = true, CharSet = CharSet.Unicode)]
    internal unsafe static extern IntPtr
    PyUnicode_FromUnicode(string s, int size);

More functions can be found at
https://pythonnet.svn.sourceforge.net/svnroot/pythonnet/branches/clr-2.0-python-2.5-branch/src/runtime/runtime.cs

How should I solve the issue? Has Mono some generic solution for the
general issue of UCS-4 vs. UCS-2 unicode or do I have to convert the
stuff manually by wrapping every external method? If I have to convert
it manually is System.Text.Encoding.UTF32 the right module?

Christian



More information about the Mono-list mailing list