Skip to content

Remove Mono.Unix dependency #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 6, 2017
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
1 change: 0 additions & 1 deletion src/runtime/Python.Runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
<Compile Include="modulefunctionobject.cs" />
<Compile Include="moduleobject.cs" />
<Compile Include="modulepropertyobject.cs" />
<Compile Include="monosupport.cs" />
<Compile Include="nativecall.cs" />
<Compile Include="overload.cs" />
<Compile Include="propertyobject.cs" />
Expand Down
44 changes: 0 additions & 44 deletions src/runtime/monosupport.cs

This file was deleted.

55 changes: 46 additions & 9 deletions src/runtime/runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
using System.Security;
using System.Text;

#if UCS4
using Mono.Unix;
#endif

namespace Python.Runtime
{
[SuppressUnmanagedCodeSecurity()]
Expand Down Expand Up @@ -1656,10 +1652,32 @@ internal unsafe static extern IntPtr
ExactSpelling = true)]
internal unsafe static extern IntPtr
PyUnicode_FromKindAndString(int kind,
[MarshalAs(UnmanagedType.CustomMarshaler,
MarshalTypeRef = typeof(Utf32Marshaler))] string s,
IntPtr s,
int size);

internal static unsafe IntPtr PyUnicode_FromKindAndString(int kind,
string s,
int size)
{
var bufLength = Math.Max(s.Length, size) * 4;

IntPtr mem = Marshal.AllocHGlobal(bufLength);
try
{
fixed (char* ps = s)
{
Encoding.UTF32.GetBytes(ps, s.Length, (byte*)mem, bufLength);
}

var result = PyUnicode_FromKindAndString(kind, mem, size);
return result;
}
finally
{
Marshal.FreeHGlobal(mem);
}
}

internal static IntPtr PyUnicode_FromUnicode(string s, int size)
{
return PyUnicode_FromKindAndString(4, s, size);
Expand Down Expand Up @@ -1702,9 +1720,28 @@ internal unsafe static extern IntPtr
EntryPoint = "PyUnicodeUCS4_FromUnicode",
ExactSpelling = true)]
internal unsafe static extern IntPtr
PyUnicode_FromUnicode(
[MarshalAs(UnmanagedType.CustomMarshaler,
MarshalTypeRef = typeof(Utf32Marshaler))] string s, int size);
PyUnicode_FromUnicode(IntPtr s, int size);

internal static unsafe IntPtr PyUnicode_FromUnicode(string s, int size)
{
var bufLength = Math.Max(s.Length, size) * 4;

IntPtr mem = Marshal.AllocHGlobal(bufLength);
try
{
fixed (char* ps = s)
{
Encoding.UTF32.GetBytes(ps, s.Length, (byte*)mem, bufLength);
}

var result = PyUnicode_FromUnicode(mem, size);
return result;
}
finally
{
Marshal.FreeHGlobal(mem);
}
}

[DllImport(Runtime.dll, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "PyUnicodeUCS4_GetSize",
Expand Down