Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Start implementing interface ILibPython
  • Loading branch information
filmor committed Dec 16, 2019
commit e61dd723ae505da263fe7c275c55684f0639fbfd
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ cov-int/
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

pythonnet/dlls
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@
using System.Runtime.InteropServices;
using System.Text;

namespace Python.Runtime
namespace Python.Runtime.Native
{
/// <summary>
/// Abstract class defining boiler plate methods that
/// Custom Marshalers will use.
/// </summary>
internal abstract class MarshalerBase : ICustomMarshaler
{
#if UCS2 && PYTHON2
internal static Encoding PyEncoding = Encoding.Unicode;
internal static int UCS = 2;
#else
internal static Encoding PyEncoding = Encoding.UTF32;
internal static int UCS = 4;
#endif

public object MarshalNativeToManaged(IntPtr pNativeData)
{
throw new NotImplementedException();
Expand Down Expand Up @@ -42,7 +50,6 @@ public int GetNativeDataSize()
internal class UcsMarshaler : MarshalerBase
{
private static readonly MarshalerBase Instance = new UcsMarshaler();
private static readonly Encoding PyEncoding = Runtime.PyEncoding;

public override IntPtr MarshalManagedToNative(object managedObj)
{
Expand Down Expand Up @@ -91,15 +98,15 @@ public static int GetUnicodeByteLength(IntPtr p)
var len = 0;
while (true)
{
#if UCS2
#if UCS2 && PYTHON2
int c = Marshal.ReadInt16(p, len * 2);
#else
int c = Marshal.ReadInt32(p, len * 4);
#endif

if (c == 0)
{
return len * Runtime._UCS;
return len * UCS;
}
checked
{
Expand Down Expand Up @@ -157,7 +164,6 @@ public static string PtrToPy3UnicodePy2String(IntPtr p)
internal class StrArrayMarshaler : MarshalerBase
{
private static readonly MarshalerBase Instance = new StrArrayMarshaler();
private static readonly Encoding PyEncoding = Runtime.PyEncoding;

public override IntPtr MarshalManagedToNative(object managedObj)
{
Expand All @@ -169,7 +175,7 @@ public override IntPtr MarshalManagedToNative(object managedObj)
}

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

IntPtr mem = Marshal.AllocHGlobal(memSize);
try
Expand Down
Loading