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

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
Move interface to separate DLL for simpler dynamic loading
  • Loading branch information
filmor committed Dec 16, 2019
commit 908f0f09ba10382fd011471e3f244106c8f68f65
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Threading;
using System.Collections.Generic;

namespace Python.Runtime.Native
namespace Python.Runtime.Interfaces
{
public interface ILibPython
{
Expand Down Expand Up @@ -347,6 +347,7 @@ public interface ILibPython
int Py_AddPendingCall(IntPtr func, IntPtr arg);
int Py_MakePendingCalls();

int Py_NoSiteFlag { get; set; }
int GetPyNoSiteFlag();
void SetPyNoSiteFlag(int val);
}
}
7 changes: 7 additions & 0 deletions Python.Runtime.Interfaces/Python.Runtime.Interfaces.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

</Project>
6 changes: 0 additions & 6 deletions Python.Runtime.Native/AssemblyInfo.cs

This file was deleted.

4 changes: 4 additions & 0 deletions Python.Runtime.Native/Python.Runtime.Native.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@
<PackageReference Include="AdvancedDLSupport" Version="3.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Python.Runtime.Interfaces\Python.Runtime.Interfaces.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public static ICustomMarshaler GetInstance(string cookie)
internal class Utf8Marshaler : MarshalerBase
{
private static readonly MarshalerBase Instance = new Utf8Marshaler();
private static readonly Encoding PyEncoding = Encoding.UTF8;
private static new readonly Encoding PyEncoding = Encoding.UTF8;

public override IntPtr MarshalManagedToNative(object managedObj)
{
Expand Down
1 change: 1 addition & 0 deletions Python.Runtime/Python.Runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<ItemGroup>
<ProjectReference Include="..\Python.Runtime.Native\Python.Runtime.Native.csproj" />
<ProjectReference Include="..\Python.Runtime.Interfaces\Python.Runtime.Interfaces.csproj" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions Python.Runtime/runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -979,9 +979,9 @@ internal static IntPtr PyMem_Realloc(IntPtr ptr, long size)

internal static void SetNoSiteFlag()
{
Py_NoSiteFlag = 1;
SetPyNoSiteFlag(1);
}

static Native.ILibPython LibPython;
static Interfaces.ILibPython LibPython;
}
}
6 changes: 2 additions & 4 deletions Python.Runtime/runtime_.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,7 @@ partial class Runtime {
internal static System.IntPtr PyMethod_Function(System.IntPtr ob) => LibPython.PyMethod_Function(ob);
internal static System.Int32 Py_AddPendingCall(System.IntPtr func, System.IntPtr arg) => LibPython.Py_AddPendingCall(func, arg);
internal static System.Int32 Py_MakePendingCalls() => LibPython.Py_MakePendingCalls();
internal static System.Int32 Py_NoSiteFlag {
get => LibPython.Py_NoSiteFlag;
set { LibPython.Py_NoSiteFlag = value; }
}
internal static System.Int32 GetPyNoSiteFlag() => LibPython.GetPyNoSiteFlag();
internal static void SetPyNoSiteFlag(System.Int32 val) => LibPython.SetPyNoSiteFlag(val);
}
}
4 changes: 2 additions & 2 deletions Python.Runtime/runtime_.tt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ namespace Python.Runtime {
return type.ToString();
}

var path = $"{Directory.GetCurrentDirectory()}/Python.Runtime.Native/bin/Debug/netstandard2.0/Python.Runtime.Native.dll";
var path = $"{Directory.GetCurrentDirectory()}/Python.Runtime.Interfaces/bin/Debug/netstandard2.0/Python.Runtime.Interfaces.dll";
var assembly = Assembly.LoadFile(path);
var type = assembly.GetType("Python.Runtime.Native.ILibPython");
var type = assembly.GetType("Python.Runtime.Interfaces.ILibPython");
const BindingFlags flags = BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance;
var methods = type.GetMethods(flags);

Expand Down