Author: joncham
Date: 2008-01-24 10:34:25 -0500 (Thu, 24 Jan 2008)
New Revision: 93805
Modified:
trunk/mono/mono/metadata/ChangeLog
trunk/mono/mono/metadata/marshal.c
trunk/mono/mono/tests/ChangeLog
trunk/mono/mono/tests/libtest.c
trunk/mono/mono/tests/pinvoke2.cs
Log:
2008-01-24 Jonathan Chambers <[EMAIL PROTECTED]>
* marshal.c (emit_marshal_string): Fix out string marshalling
to use specified encoding. Fixes #323900.
Code is contributed under MIT/X11 license.
2008-01-24 Jonathan Chambers <[EMAIL PROTECTED]>
* libtest.c: Allocate memory for out string parameters.
* pinvoke2.cs: Add tests for marshalling strings as out paramters.
Code is contributed under MIT/X11 license.
Modified: trunk/mono/mono/metadata/ChangeLog
===================================================================
--- trunk/mono/mono/metadata/ChangeLog 2008-01-24 15:33:21 UTC (rev 93804)
+++ trunk/mono/mono/metadata/ChangeLog 2008-01-24 15:34:25 UTC (rev 93805)
@@ -1,3 +1,10 @@
+2008-01-24 Jonathan Chambers <[EMAIL PROTECTED]>
+
+ * marshal.c (emit_marshal_string): Fix out string marshalling
+ to use specified encoding. Fixes #323900.
+
+ Code is contributed under MIT/X11 license.
+
2008-01-24 Raja R Harinath <[EMAIL PROTECTED]>
* class.c (mono_class_inflate_generic_method_full): Don't modify
Modified: trunk/mono/mono/metadata/marshal.c
===================================================================
--- trunk/mono/mono/metadata/marshal.c 2008-01-24 15:33:21 UTC (rev 93804)
+++ trunk/mono/mono/metadata/marshal.c 2008-01-24 15:34:25 UTC (rev 93805)
@@ -2533,6 +2533,7 @@
switch (encoding) {
case MONO_NATIVE_LPWSTR:
+ *need_free = FALSE;
return MONO_MARSHAL_CONV_LPWSTR_STR;
case MONO_NATIVE_LPSTR:
return MONO_MARSHAL_CONV_LPSTR_STR;
@@ -5989,26 +5990,27 @@
break;
case MARSHAL_ACTION_CONV_OUT:
+ conv = mono_marshal_get_ptr_to_string_conv (m->piinfo, spec,
&need_free);
+ if (conv == -1) {
+ char *msg = g_strdup_printf ("string marshalling
conversion %d not implemented", encoding);
+ mono_mb_emit_exception_marshal_directive (mb, msg);
+ break;
+ }
+
if (t->byref && (t->attrs & PARAM_ATTRIBUTE_OUT)) {
mono_mb_emit_ldarg (mb, argnum);
mono_mb_emit_ldloc (mb, conv_arg);
- if (conv == MONO_MARSHAL_CONV_STR_BSTR) {
- mono_mb_emit_icall (mb, conv_to_icall
(MONO_MARSHAL_CONV_BSTR_STR));
- // BSTRs always need freed
- mono_mb_emit_ldloc (mb, conv_arg);
+ mono_mb_emit_icall (mb, conv_to_icall (conv));
+ mono_mb_emit_byte (mb, CEE_STIND_REF);
+
+ }
+
+ if (need_free || (t->byref && (t->attrs &
PARAM_ATTRIBUTE_OUT))) {
+ mono_mb_emit_ldloc (mb, conv_arg);
+ if (conv == MONO_MARSHAL_CONV_BSTR_STR)
mono_mb_emit_icall (mb, mono_free_bstr);
- }
else
- mono_mb_emit_icall (mb, conv_to_icall
(MONO_MARSHAL_CONV_LPSTR_STR));
- mono_mb_emit_byte (mb, CEE_STIND_REF);
- } else {
- if (mono_marshal_need_free (t, m->piinfo, spec)) {
- mono_mb_emit_ldloc (mb, conv_arg);
- if (conv == MONO_MARSHAL_CONV_STR_BSTR)
- mono_mb_emit_icall (mb, mono_free_bstr);
- else
- mono_mb_emit_icall (mb,
mono_marshal_free);
- }
+ mono_mb_emit_icall (mb, mono_marshal_free);
}
break;
Modified: trunk/mono/mono/tests/ChangeLog
===================================================================
--- trunk/mono/mono/tests/ChangeLog 2008-01-24 15:33:21 UTC (rev 93804)
+++ trunk/mono/mono/tests/ChangeLog 2008-01-24 15:34:25 UTC (rev 93805)
@@ -1,3 +1,11 @@
+2008-01-24 Jonathan Chambers <[EMAIL PROTECTED]>
+
+ * libtest.c: Allocate memory for out string parameters.
+
+ * pinvoke2.cs: Add tests for marshalling strings as out paramters.
+
+ Code is contributed under MIT/X11 license.
+
2008-01-08 Zoltan Varga <[EMAIL PROTECTED]>
* Makefile.am (DISABLED_TESTS): Disable bug-77127.exe for now to make
the
Modified: trunk/mono/mono/tests/libtest.c
===================================================================
--- trunk/mono/mono/tests/libtest.c 2008-01-24 15:33:21 UTC (rev 93804)
+++ trunk/mono/mono/tests/libtest.c 2008-01-24 15:34:25 UTC (rev 93805)
@@ -31,13 +31,22 @@
#endif
}
+static void* marshal_alloc (gsize size)
+{
+#ifdef WIN32
+ CoTaskMemAlloc (size);
+#else
+ g_malloc (size);
+#endif
+}
+
STDCALL unsigned short*
test_lpwstr_marshal (unsigned short* chars, long length)
{
int i = 0;
unsigned short *res;
- res = malloc (2 * (length + 1));
+ res = marshal_alloc (2 * (length + 1));
// printf("test_lpwstr_marshal()\n");
@@ -52,6 +61,24 @@
return res;
}
+
+STDCALL void
+test_lpwstr_marshal_out (unsigned short** chars)
+{
+ int i = 0;
+ const char abc[] = "ABC";
+ glong len = strlen(abc);
+
+ *chars = marshal_alloc (2 * (len + 1));
+
+ while ( i < len ) {
+ (*chars) [i] = abc[i];
+ i++;
+ }
+
+ (*chars) [i] = 0;
+}
+
typedef struct {
int b;
int a;
@@ -1194,7 +1221,7 @@
STDCALL void
string_marshal_test1 (const char **str)
{
- *str = "TEST1";
+ *str = g_strdup ("TEST1");
}
STDCALL int
Modified: trunk/mono/mono/tests/pinvoke2.cs
===================================================================
--- trunk/mono/mono/tests/pinvoke2.cs 2008-01-24 15:33:21 UTC (rev 93804)
+++ trunk/mono/mono/tests/pinvoke2.cs 2008-01-24 15:34:25 UTC (rev 93805)
@@ -1205,7 +1205,32 @@
string s,
int length );
+ [DllImport("libtest", EntryPoint="test_lpwstr_marshal_out")]
+ private static extern void mono_test_marshal_lpwstr_out_marshal(
+ [MarshalAs(UnmanagedType.LPWStr)] out string s);
+
+ [DllImport("libtest", EntryPoint="test_lpwstr_marshal_out",
CharSet=CharSet.Unicode)]
+ private static extern void mono_test_marshal_lpwstr_out_marshal2(
+ out string s);
+
public static int test_0_pass_return_lwpstr () {
+ string s;
+
+ mono_test_marshal_lpwstr_out_marshal (out s);
+
+ if (s != "ABC")
+ return 1;
+
+ s = null;
+ mono_test_marshal_lpwstr_out_marshal2 (out s);
+
+ if (s != "ABC")
+ return 2;
+
+ return 0;
+ }
+
+ public static int test_0_out_lwpstr () {
string s = "ABC";
string res = mono_test_marshal_lpwstr_marshal (s, s.Length);
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches