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

Skip to content

Commit e61dd72

Browse files
committed
Start implementing interface ILibPython
1 parent 146e6ac commit e61dd72

File tree

8 files changed

+2334
-6
lines changed

8 files changed

+2334
-6
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,5 @@ cov-int/
6464
!.vscode/tasks.json
6565
!.vscode/launch.json
6666
!.vscode/extensions.json
67+
68+
pythonnet/dlls

Python.Runtime/CustomMarshaler.cs renamed to Python.Runtime.Native/CustomMarshaler.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@
33
using System.Runtime.InteropServices;
44
using System.Text;
55

6-
namespace Python.Runtime
6+
namespace Python.Runtime.Native
77
{
88
/// <summary>
99
/// Abstract class defining boiler plate methods that
1010
/// Custom Marshalers will use.
1111
/// </summary>
1212
internal abstract class MarshalerBase : ICustomMarshaler
1313
{
14+
#if UCS2 && PYTHON2
15+
internal static Encoding PyEncoding = Encoding.Unicode;
16+
internal static int UCS = 2;
17+
#else
18+
internal static Encoding PyEncoding = Encoding.UTF32;
19+
internal static int UCS = 4;
20+
#endif
21+
1422
public object MarshalNativeToManaged(IntPtr pNativeData)
1523
{
1624
throw new NotImplementedException();
@@ -42,7 +50,6 @@ public int GetNativeDataSize()
4250
internal class UcsMarshaler : MarshalerBase
4351
{
4452
private static readonly MarshalerBase Instance = new UcsMarshaler();
45-
private static readonly Encoding PyEncoding = Runtime.PyEncoding;
4653

4754
public override IntPtr MarshalManagedToNative(object managedObj)
4855
{
@@ -91,15 +98,15 @@ public static int GetUnicodeByteLength(IntPtr p)
9198
var len = 0;
9299
while (true)
93100
{
94-
#if UCS2
101+
#if UCS2 && PYTHON2
95102
int c = Marshal.ReadInt16(p, len * 2);
96103
#else
97104
int c = Marshal.ReadInt32(p, len * 4);
98105
#endif
99106

100107
if (c == 0)
101108
{
102-
return len * Runtime._UCS;
109+
return len * UCS;
103110
}
104111
checked
105112
{
@@ -157,7 +164,6 @@ public static string PtrToPy3UnicodePy2String(IntPtr p)
157164
internal class StrArrayMarshaler : MarshalerBase
158165
{
159166
private static readonly MarshalerBase Instance = new StrArrayMarshaler();
160-
private static readonly Encoding PyEncoding = Runtime.PyEncoding;
161167

162168
public override IntPtr MarshalManagedToNative(object managedObj)
163169
{
@@ -169,7 +175,7 @@ public override IntPtr MarshalManagedToNative(object managedObj)
169175
}
170176

171177
int totalStrLength = argv.Sum(arg => arg.Length + 1);
172-
int memSize = argv.Length * IntPtr.Size + totalStrLength * Runtime._UCS;
178+
int memSize = argv.Length * IntPtr.Size + totalStrLength * UCS;
173179

174180
IntPtr mem = Marshal.AllocHGlobal(memSize);
175181
try

0 commit comments

Comments
 (0)