FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Remove Mono.Unix dependency by vmuriart · Pull Request #360 · pythonnet/pythonnet · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cs  (2) .csproj  (1) All 2 file types selected
Only manifest files
Deleted files Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 0 additions & 1 deletion src/runtime/Python.Runtime.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL