Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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