Skip to content

Commit f1da55e

Browse files
jmlidbetterfilmor
authored andcommitted
Fixes bug where there is casting on delegates -- this is explicitly in the NET standard documentation for GetDelegateForFunctionPointer (pythonnet#936)
1 parent 51a1868 commit f1da55e

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
1717
- Moved wheel import in setup.py inside of a try/except to prevent pip collection failures
1818
- Removes PyLong_GetMax and PyClass_New when targetting Python3
1919
- Added support for converting python iterators to C# arrays
20+
- Changed usage of obselete function GetDelegateForFunctionPointer(IntPtr, Type) to GetDelegateForFunctionPointer<TDelegate>(IntPtr)
2021

2122
### Fixed
2223

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

2628
## [2.4.0][]
2729

src/runtime/nativecall.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,21 @@ internal class NativeCall
3232

3333
public static void Void_Call_1(IntPtr fp, IntPtr a1)
3434
{
35-
((Void_1_Delegate)Marshal.GetDelegateForFunctionPointer(fp, typeof(Void_1_Delegate)))(a1);
35+
var d = Marshal.GetDelegateForFunctionPointer<Interop.DestructorFunc>(fp);
36+
d(a1);
3637
}
3738

3839
public static IntPtr Call_3(IntPtr fp, IntPtr a1, IntPtr a2, IntPtr a3)
3940
{
40-
var d = (Interop.TernaryFunc)Marshal.GetDelegateForFunctionPointer(fp, typeof(Interop.TernaryFunc));
41+
var d = Marshal.GetDelegateForFunctionPointer<Interop.TernaryFunc>(fp);
4142
return d(a1, a2, a3);
4243
}
4344

4445

4546
public static int Int_Call_3(IntPtr fp, IntPtr a1, IntPtr a2, IntPtr a3)
4647
{
47-
return ((Int_3_Delegate)Marshal.GetDelegateForFunctionPointer(fp, typeof(Int_3_Delegate)))(a1, a2, a3);
48+
var d = Marshal.GetDelegateForFunctionPointer<Interop.ObjObjArgFunc>(fp);
49+
return d(a1, a2, a3);
4850
}
4951
#else
5052
private static AssemblyBuilder aBuilder;

0 commit comments

Comments
 (0)