Skip to content

Added CoreCLR 2.0 build target. Compile issues fixed. #519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Sep 21, 2017
Merged
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
NetCoreApp 2.0 fix. EmitCalli does not supports cdecl. Falling-back t…
…o a slow Marshal-based solution. + x86 fix.
  • Loading branch information
dse committed Aug 27, 2017
commit 2edbc873e26682adf931c581a1a0fefa6df2b9d3
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ init:
install:
- pip install --upgrade -r requirements.txt --quiet
- choco install vswhere -y
# - cmd: curl -O https://download.microsoft.com/download/5/6/B/56BFEF92-9045-4414-970C-AB31E0FC07EC/dotnet-runtime-2.0.0-win-x86.exe
# - cmd: dotnet-runtime-2.0.0-win-x86.exe /install /quiet /norestart /log install.log
- cmd: curl -O https://download.microsoft.com/download/5/6/B/56BFEF92-9045-4414-970C-AB31E0FC07EC/dotnet-runtime-2.0.0-win-x86.exe
- cmd: dotnet-runtime-2.0.0-win-x86.exe /install /quiet /norestart /log install.log

# Install OpenCover. Can't put on `packages.config`, not Mono compatible
- .\tools\nuget\nuget.exe install OpenCover -OutputDirectory packages -Verbosity quiet
Expand Down
3 changes: 0 additions & 3 deletions src/runtime/importhook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ internal static void Shutdown()
if (Runtime.Py_IsInitialized() != 0)
{
Runtime.XDecref(py_clr_module);
// TODO: Very strange behavior under CoreCLR. System.ExecutionEngineException (Crash)
#if !NETCOREAPP
Runtime.XDecref(root.pyHandle);
#endif
Runtime.XDecref(py_import);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/metatype.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Runtime.InteropServices;

namespace Python.Runtime
Expand Down Expand Up @@ -201,7 +201,7 @@ public static int tp_setattro(IntPtr tp, IntPtr name, IntPtr value)
IntPtr fp = Marshal.ReadIntPtr(dt, TypeOffset.tp_descr_set);
if (fp != IntPtr.Zero)
{
return NativeCall.Impl.Int_Call_3(fp, descr, name, value);
return NativeCall.Int_Call_3(fp, descr, name, value);
}
Exceptions.SetError(Exceptions.AttributeError, "attribute is read-only");
return -1;
Expand Down
39 changes: 30 additions & 9 deletions src/runtime/nativecall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,32 @@ namespace Python.Runtime
/// </summary>
internal class NativeCall
{
#if NETCOREAPP
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void Void_1_Delegate(IntPtr a1);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate IntPtr IntPtr_3_Delegate(IntPtr a1, IntPtr a2, IntPtr a3);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate int Int_3_Delegate(IntPtr a1, IntPtr a2, IntPtr a3);

public static void Void_Call_1(IntPtr fp, IntPtr a1)
{
((Void_1_Delegate)Marshal.GetDelegateForFunctionPointer(fp, typeof(Void_1_Delegate)))(a1);
}

public static IntPtr Call_3(IntPtr fp, IntPtr a1, IntPtr a2, IntPtr a3)
{
return ((IntPtr_3_Delegate)Marshal.GetDelegateForFunctionPointer(fp, typeof(IntPtr_3_Delegate)))(a1, a2, a3);
}


public static int Int_Call_3(IntPtr fp, IntPtr a1, IntPtr a2, IntPtr a3)
{
return ((Int_3_Delegate)Marshal.GetDelegateForFunctionPointer(fp, typeof(Int_3_Delegate)))(a1, a2, a3);
}
#else
private static AssemblyBuilder aBuilder;
private static ModuleBuilder mBuilder;

Expand Down Expand Up @@ -106,19 +132,12 @@ private static void GenerateThunk(TypeBuilder tb, MethodInfo method)

il.Emit(OpCodes.Ldarg_1);

#if NETCOREAPP
il.EmitCalli(OpCodes.Calli,
CallingConventions.ExplicitThis,
method.ReturnType,
nargs, null
);
#else
il.EmitCalli(OpCodes.Calli,
CallingConvention.Cdecl,
method.ReturnType,
nargs
);
#endif

il.Emit(OpCodes.Ret);

tb.DefineMethodOverride(mb, method);
Expand All @@ -139,9 +158,10 @@ public static int Int_Call_3(IntPtr fp, IntPtr a1, IntPtr a2, IntPtr a3)
{
return Impl.Int_Call_3(fp, a1, a2, a3);
}
#endif
}


#if !NETCORAPP
/// <summary>
/// Defines native call signatures to be generated by NativeCall.
/// </summary>
Expand All @@ -155,4 +175,5 @@ public interface INativeCall

IntPtr Call_3(IntPtr funcPtr, IntPtr a1, IntPtr a2, IntPtr a3);
}
#endif
}
4 changes: 2 additions & 2 deletions src/runtime/runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ internal static Type[] PythonArgsToTypeArray(IntPtr arg, bool mangleObjects)
/// </summary>
internal static unsafe void XIncref(IntPtr op)
{
#if PYTHON_WITH_PYDEBUG
#if PYTHON_WITH_PYDEBUG || NETCOREAPP
Py_IncRef(op);
return;
#else
Expand All @@ -543,7 +543,7 @@ internal static unsafe void XIncref(IntPtr op)

internal static unsafe void XDecref(IntPtr op)
{
#if PYTHON_WITH_PYDEBUG
#if PYTHON_WITH_PYDEBUG || NETCOREAPP
Py_DecRef(op);
return;
#else
Expand Down