Transfer the ownership of method's thunk to caller(split from #958) by amos402 · Pull Request #1003 · pythonnet/pythonnet · GitHub
Skip to content
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
43 changes: 29 additions & 14 deletions src/runtime/interop.cs
6 changes: 4 additions & 2 deletions src/runtime/methodwrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ internal class MethodWrapper
public IntPtr ptr;
private bool _disposed = false;

private ThunkInfo _thunk;

public MethodWrapper(Type type, string name, string funcType = null)
{
// Turn the managed method into a function pointer

IntPtr fp = Interop.GetThunk(type.GetMethod(name), funcType);
_thunk = Interop.GetThunk(type.GetMethod(name), funcType);

// Allocate and initialize a PyMethodDef structure to represent
// the managed method, then create a PyCFunction.

mdef = Runtime.PyMem_Malloc(4 * IntPtr.Size);
TypeManager.WriteMethodDef(mdef, name, fp, 0x0003);
TypeManager.WriteMethodDef(mdef, name, _thunk.Address, 0x0003);
ptr = Runtime.PyCFunction_NewEx(mdef, IntPtr.Zero, IntPtr.Zero);
}

Expand Down
17 changes: 10 additions & 7 deletions src/runtime/typemanager.cs