[Mono-devel-list] Re: [patch] support utf8 strings in c# module
Joel Reed
joel.reed at ddiworld.com
Wed Nov 3 10:07:18 EST 2004
On Tue, Nov 02, 2004 at 11:17:01PM -0500, Jonathan Pryor wrote:
> On Tue, 2004-11-02 at 21:05, Joel Reed wrote:
> <snip/>
> > thanks Rafael. what i'm referring to is .Net String's which have been
> > initialized with C/C++ strings via pinvoke, in particular i was examining
> > Marshal.PtrToStringAnsi and Marshal.PtrToStringUni.
>
> A good fix for this would be to modify
> ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi (in
> mono/metadata/marshal.c) so that it usees mono_unicode_from_external()
> (declared in mono/utils/strenc.h). This way, it will examine the
> MONO_EXTERNAL_ENCODINGS environment variable to determine how the string
> should be marshaled, with UTF-8 being the default.
>
> This would likely be a 5-10 line change, for anyone interested in
> writing such a patch...
am i on the right track here? - patch attached. it seems to also fix
ves_icall_System_Runtime_InteropServices_Marshal_PtrToStringAnsi_len
we'd want a mono_unicode_from_external like function that took
a length argument that could be passed to g_convert. any recommendations?
jr
--
------------------------------------------------------------
Joel W. Reed 412-257-3881
---------- http://home.comcast.net/~joelwreed/ ----------
-------------- next part --------------
--- mono/metadata/marshal.c.orig 2004-11-03 09:34:38.000000000 -0500
+++ mono/metadata/marshal.c 2004-11-03 09:59:19.000000000 -0500
@@ -20,6 +20,7 @@
#include "mono/metadata/threads.h"
#include "mono/metadata/monitor.h"
#include "mono/metadata/metadata-internals.h"
+#include "mono/utils/strenc.h"
#include <string.h>
#include <errno.h>
@@ -5123,10 +5124,19 @@ ves_icall_System_Runtime_InteropServices
{
MONO_ARCH_SAVE_REGS;
+ gsize bytes;
+ gunichar2* utf16;
+ MonoString* str;
+
if (ptr == NULL)
return mono_string_new (mono_domain_get (), "");
else
- return mono_string_new (mono_domain_get (), ptr);
+ {
+ utf16 = mono_unicode_from_external(ptr, &bytes);
+ str = mono_string_new_utf16 (mono_domain_get (), utf16, (bytes/2)+1);
+ g_free(utf16);
+ return str;
+ }
}
MonoString *
More information about the Mono-devel-list
mailing list