Skip to content

Commit 359e541

Browse files
authored
Merge pull request #360 from vmuriart/remove_mono_unix_dep
Remove Mono.Unix dependency
2 parents 4f71a94 + d2ba88a commit 359e541

File tree

3 files changed

+46
-54
lines changed

3 files changed

+46
-54
lines changed

src/runtime/Python.Runtime.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@
116116
<Compile Include="modulefunctionobject.cs" />
117117
<Compile Include="moduleobject.cs" />
118118
<Compile Include="modulepropertyobject.cs" />
119-
<Compile Include="monosupport.cs" />
120119
<Compile Include="nativecall.cs" />
121120
<Compile Include="overload.cs" />
122121
<Compile Include="propertyobject.cs" />

src/runtime/monosupport.cs

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/runtime/runtime.cs

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
using System.Security;
44
using System.Text;
55

6-
#if UCS4
7-
using Mono.Unix;
8-
#endif
9-
106
namespace Python.Runtime
117
{
128
[SuppressUnmanagedCodeSecurity()]
@@ -1656,10 +1652,32 @@ internal unsafe static extern IntPtr
16561652
ExactSpelling = true)]
16571653
internal unsafe static extern IntPtr
16581654
PyUnicode_FromKindAndString(int kind,
1659-
[MarshalAs(UnmanagedType.CustomMarshaler,
1660-
MarshalTypeRef = typeof(Utf32Marshaler))] string s,
1655+
IntPtr s,
16611656
int size);
16621657

1658+
internal static unsafe IntPtr PyUnicode_FromKindAndString(int kind,
1659+
string s,
1660+
int size)
1661+
{
1662+
var bufLength = Math.Max(s.Length, size) * 4;
1663+
1664+
IntPtr mem = Marshal.AllocHGlobal(bufLength);
1665+
try
1666+
{
1667+
fixed (char* ps = s)
1668+
{
1669+
Encoding.UTF32.GetBytes(ps, s.Length, (byte*)mem, bufLength);
1670+
}
1671+
1672+
var result = PyUnicode_FromKindAndString(kind, mem, size);
1673+
return result;
1674+
}
1675+
finally
1676+
{
1677+
Marshal.FreeHGlobal(mem);
1678+
}
1679+
}
1680+
16631681
internal static IntPtr PyUnicode_FromUnicode(string s, int size)
16641682
{
16651683
return PyUnicode_FromKindAndString(4, s, size);
@@ -1702,9 +1720,28 @@ internal unsafe static extern IntPtr
17021720
EntryPoint = "PyUnicodeUCS4_FromUnicode",
17031721
ExactSpelling = true)]
17041722
internal unsafe static extern IntPtr
1705-
PyUnicode_FromUnicode(
1706-
[MarshalAs(UnmanagedType.CustomMarshaler,
1707-
MarshalTypeRef = typeof(Utf32Marshaler))] string s, int size);
1723+
PyUnicode_FromUnicode(IntPtr s, int size);
1724+
1725+
internal static unsafe IntPtr PyUnicode_FromUnicode(string s, int size)
1726+
{
1727+
var bufLength = Math.Max(s.Length, size) * 4;
1728+
1729+
IntPtr mem = Marshal.AllocHGlobal(bufLength);
1730+
try
1731+
{
1732+
fixed (char* ps = s)
1733+
{
1734+
Encoding.UTF32.GetBytes(ps, s.Length, (byte*)mem, bufLength);
1735+
}
1736+
1737+
var result = PyUnicode_FromUnicode(mem, size);
1738+
return result;
1739+
}
1740+
finally
1741+
{
1742+
Marshal.FreeHGlobal(mem);
1743+
}
1744+
}
17081745

17091746
[DllImport(Runtime.dll, CallingConvention = CallingConvention.Cdecl,
17101747
EntryPoint = "PyUnicodeUCS4_GetSize",

0 commit comments

Comments
 (0)