--- /dev/null
+//
+// Safe wrapper for a string and its UTF8 encoding
+//
+// Authors:
+// Aleksey Kliger <aleksey@xamarin.com>
+// Rodrigo Kumpera <kumpera@xamarin.com>
+//
+// Copyright 2016 Dot net foundation.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+using System;
+using System.Runtime.CompilerServices;
+
+namespace Mono {
+ internal struct SafeStringMarshal : IDisposable {
+ readonly string str;
+ IntPtr marshaled_string;
+
+ [MethodImplAttribute(MethodImplOptions.InternalCall)]
+ public extern static IntPtr StringToUtf8 (string str);
+
+ [MethodImplAttribute(MethodImplOptions.InternalCall)]
+ public extern static void GFree (IntPtr ptr);
+
+ public SafeStringMarshal (string str) {
+ this.str = str;
+ }
+
+ public IntPtr Value {
+ get {
+ if (marshaled_string == IntPtr.Zero)
+ marshaled_string = StringToUtf8 (str);
+ return marshaled_string;
+ }
+ }
+
+ public void Dispose () {
+ if (marshaled_string != IntPtr.Zero) {
+ GFree (marshaled_string);
+ marshaled_string = IntPtr.Zero;
+ }
+ }
+ }
+}
Mono/RuntimeStructs.cs
Mono/RuntimeHandles.cs
Mono/SafeGPtrArrayHandle.cs
+Mono/SafeStringMarshal.cs
Mono/DataConverter.cs
Mono.Interop/ComInteropProxy.cs
Mono.Interop/IDispatch.cs
ICALL_TYPE(RTPTRARRAY, "Mono.RuntimeGPtrArrayHandle", RTPTRARRAY_1)
ICALL(RTPTRARRAY_1, "GPtrArrayFree", ves_icall_Mono_RuntimeGPtrArrayHandle_GPtrArrayFree)
+ICALL_TYPE(SAFESTRMARSHAL, "Mono.SafeStringMarshal", SAFESTRMARSHAL_1)
+ICALL(SAFESTRMARSHAL_1, "GFree", ves_icall_Mono_SafeStringMarshal_GFree)
+ICALL(SAFESTRMARSHAL_2, "StringToUtf8", ves_icall_Mono_SafeStringMarshal_StringToUtf8)
+
#ifndef PLATFORM_RO_FS
ICALL_TYPE(KPAIR, "Mono.Security.Cryptography.KeyPairPersistence", KPAIR_1)
ICALL(KPAIR_1, "_CanSecure", ves_icall_Mono_Security_Cryptography_KeyPairPersistence_CanSecure)
g_ptr_array_free (ptr_array, TRUE);
}
+ICALL_EXPORT void
+ves_icall_Mono_SafeStringMarshal_GFree (void *c_str)
+{
+ g_free (c_str);
+}
+
+ICALL_EXPORT char*
+ves_icall_Mono_SafeStringMarshal_StringToUtf8 (MonoString *s)
+{
+ MonoError error;
+ char *res = mono_string_to_utf8_checked (s, &error);
+ mono_error_set_pending_exception (&error);
+ return res;
+}
+
/* System.TypeCode */
typedef enum {
TYPECODE_EMPTY,