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

[Build] Add a patch to check whether we have .NET 4.6 at build time. #164

Merged
merged 1 commit into from
Sep 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions configure.in.in
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,19 @@ OFF_T_FLAGS="-define:OFF_T_$ac_cv_sizeof_off_t"
AC_SUBST(OFF_T_FLAGS)

MONO_REQUIRED_VERSION=1.0
FIRST_MONO_VERSION_WITH_NET_4_6_SUPPORT=4.4
PKG_CHECK_MODULES(MONO_DEPENDENCY, mono >= $MONO_REQUIRED_VERSION, has_mono=true, has_mono=false)
if test "x$has_mono" = "xfalse" ; then
PKG_CHECK_MODULES(MONO_DEPENDENCY, mono-2 >= $MONO_REQUIRED_VERSION, has_mono=true, has_mono=false)
if test "x$has_mono" = "xtrue" ; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beware, you placed this if test "x$has_mono" = "xtrue" check inside a has_mono=xfalse block, so potentially this may always evaluate to false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the above pkg check resets the value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh oops, disregard this.

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)
fi
else
PKG_CHECK_MODULES(MONO_DEPENDENCY, mono >= $FIRST_MONO_VERSION_WITH_NET_4_6_SUPPORT, NET_4_6_SUPPORT=true, NET_4_6_SUPPORT=false)
fi

if test "x$platform_win32" = "xyes"; then
NET_4_6_SUPPORT=true
fi

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

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

if test "x$NET_4_6_SUPPORT" = "xtrue" ; then
CSFLAGS="$CSFLAGS -define:HAVE_NET_4_6"
fi
PKG_CHECK_MODULES(GLIB_2_31,
glib-2.0 >= 2.31,
HAVE_GLIB_2_31_OR_HIGHER=yes, HAVE_GLIB_2_31_OR_HIGHER=no)
Expand Down
22 changes: 8 additions & 14 deletions glib/Marshaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,23 @@ public static string FilenamePtrToStringGFree (IntPtr ptr)

[DllImport("glibsharpglue-2", CallingConvention=CallingConvention.Cdecl)]
static extern UIntPtr glibsharp_strlen (IntPtr mem);

static string Utf8PtrToStringFast (IntPtr ptr, int len)
{
unsafe
{
var p = (byte*)ptr;
return System.Text.Encoding.UTF8.GetString (p, len);
}
}

static bool hasFastGetStringOverload = typeof (System.Text.Encoding).GetMethod ("GetString", new [] { typeof (byte*), typeof (int) }) != null;
public static string Utf8PtrToString (IntPtr ptr)
{
if (ptr == IntPtr.Zero)
return null;

int len = (int) (uint)glibsharp_strlen (ptr);
if (hasFastGetStringOverload)
return Utf8PtrToStringFast (ptr, len);

#if HAVE_NET_4_6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about wrapping the old 3 lines with #if UTF8_SLOWPATH , and after them, return Utf8PtrToStringFast (ptr, len); this way removing this build check in the future will be easier and cause less diff noise

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see it done ;)

Copy link
Contributor Author

@Therzok Therzok Sep 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff is still here since you commented on the define, see below, the Utf8PtrStringFast is inlined now under the same HAVE_NET_4_6.

This way, you can use unifdef to remove the segments.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant this way: #165

unsafe
{
var p = (byte*)ptr;
return System.Text.Encoding.UTF8.GetString (p, len);
}
#else
byte [] bytes = new byte [len];
Marshal.Copy (ptr, bytes, 0, len);
return System.Text.Encoding.UTF8.GetString (bytes);
#endif
}

public static string[] Utf8PtrToString (IntPtr[] ptrs) {
Expand Down