-
Notifications
You must be signed in to change notification settings - Fork 143
[Build] Add a patch to check whether we have .NET 4.6 at build time. #164
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see it done ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh oops, disregard this.