Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit 4e6206d

Browse files
committed
[Build] Add a patch to check whether we have .NET 4.6 at build time.
1 parent 8abc2ba commit 4e6206d

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

configure.in.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,19 @@ OFF_T_FLAGS="-define:OFF_T_$ac_cv_sizeof_off_t"
106106
AC_SUBST(OFF_T_FLAGS)
107107

108108
MONO_REQUIRED_VERSION=1.0
109+
FIRST_MONO_VERSION_WITH_NET_4_6_SUPPORT=4.4
109110
PKG_CHECK_MODULES(MONO_DEPENDENCY, mono >= $MONO_REQUIRED_VERSION, has_mono=true, has_mono=false)
110111
if test "x$has_mono" = "xfalse" ; then
111112
PKG_CHECK_MODULES(MONO_DEPENDENCY, mono-2 >= $MONO_REQUIRED_VERSION, has_mono=true, has_mono=false)
113+
if test "x$has_mono" = "xtrue" ; then
114+
PKG_CHECK_MODULES(MONO_DEPENDENCY, mono-2 >= $FIRST_MONO_VERSION_WITH_NET_4_6_SUPPORT, NET_4_6_SUPPORT=true, NET_4_6_SUPPORT=false)
115+
fi
116+
else
117+
PKG_CHECK_MODULES(MONO_DEPENDENCY, mono >= $FIRST_MONO_VERSION_WITH_NET_4_6_SUPPORT, NET_4_6_SUPPORT=true, NET_4_6_SUPPORT=false)
118+
fi
119+
120+
if test "x$platform_win32" = "xyes"; then
121+
NET_4_6_SUPPORT=true
112122
fi
113123

114124
AC_PATH_PROG(GACUTIL, gacutil, no)
@@ -224,6 +234,9 @@ AM_CONDITIONAL(ENABLE_MONOGETOPTIONS, test "x$has_mono" = "xtrue")
224234

225235
CSFLAGS="$DEBUG_FLAGS $CSDEFINES $WIN64DEFINES -unsafe"
226236

237+
if test "x$NET_4_6_SUPPORT" = "xtrue" ; then
238+
CSFLAGS="$CSFLAGS -define:HAVE_NET_4_6"
239+
fi
227240
PKG_CHECK_MODULES(GLIB_2_31,
228241
glib-2.0 >= 2.31,
229242
HAVE_GLIB_2_31_OR_HIGHER=yes, HAVE_GLIB_2_31_OR_HIGHER=no)

glib/Marshaller.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,23 @@ public static string FilenamePtrToStringGFree (IntPtr ptr)
7878

7979
[DllImport("glibsharpglue-2", CallingConvention=CallingConvention.Cdecl)]
8080
static extern UIntPtr glibsharp_strlen (IntPtr mem);
81-
82-
static string Utf8PtrToStringFast (IntPtr ptr, int len)
83-
{
84-
unsafe
85-
{
86-
var p = (byte*)ptr;
87-
return System.Text.Encoding.UTF8.GetString (p, len);
88-
}
89-
}
90-
91-
static bool hasFastGetStringOverload = typeof (System.Text.Encoding).GetMethod ("GetString", new [] { typeof (byte*), typeof (int) }) != null;
9281
public static string Utf8PtrToString (IntPtr ptr)
9382
{
9483
if (ptr == IntPtr.Zero)
9584
return null;
9685

9786
int len = (int) (uint)glibsharp_strlen (ptr);
98-
if (hasFastGetStringOverload)
99-
return Utf8PtrToStringFast (ptr, len);
100-
87+
#if HAVE_NET_4_6
88+
unsafe
89+
{
90+
var p = (byte*)ptr;
91+
return System.Text.Encoding.UTF8.GetString (p, len);
92+
}
93+
#else
10194
byte [] bytes = new byte [len];
10295
Marshal.Copy (ptr, bytes, 0, len);
10396
return System.Text.Encoding.UTF8.GetString (bytes);
97+
#endif
10498
}
10599

106100
public static string[] Utf8PtrToString (IntPtr[] ptrs) {

0 commit comments

Comments
 (0)