Skip to content

Remove delegate casting #936

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 1 commit into from
Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
Fixes bug where there is casting on delegates -- this is explicitly i…
…n the NET standard documentation for GetDelegateForFunctionPointer
  • Loading branch information
jmlidbetter committed Aug 7, 2019
commit 7dc3aa17c5a237d7b44d275cff4979cbef279e3b
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
- Moved wheel import in setup.py inside of a try/except to prevent pip collection failures
- Removes PyLong_GetMax and PyClass_New when targetting Python3
- Added support for converting python iterators to C# arrays
- Changed usage of obselete function GetDelegateForFunctionPointer(IntPtr, Type) to GetDelegateForFunctionPointer<TDelegate>(IntPtr)

### Fixed

- Fixed runtime that fails loading when using pythonnet in an environment
together with Nuitka
- Fixes bug where delegates get casts (dotnetcore)

## [2.4.0][]

Expand Down
8 changes: 5 additions & 3 deletions src/runtime/nativecall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,21 @@ internal class NativeCall

public static void Void_Call_1(IntPtr fp, IntPtr a1)
{
((Void_1_Delegate)Marshal.GetDelegateForFunctionPointer(fp, typeof(Void_1_Delegate)))(a1);
var d = Marshal.GetDelegateForFunctionPointer<Interop.DestructorFunc>(fp);
d(a1);
}

public static IntPtr Call_3(IntPtr fp, IntPtr a1, IntPtr a2, IntPtr a3)
{
var d = (Interop.TernaryFunc)Marshal.GetDelegateForFunctionPointer(fp, typeof(Interop.TernaryFunc));
var d = Marshal.GetDelegateForFunctionPointer<Interop.TernaryFunc>(fp);
return d(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);
var d = Marshal.GetDelegateForFunctionPointer<Interop.ObjObjArgFunc>(fp);
return d(a1, a2, a3);
}
#else
private static AssemblyBuilder aBuilder;
Expand Down