-
Notifications
You must be signed in to change notification settings - Fork 750
Release method wrapper(split from #958) #1002
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
Changes from all commits
7f530f2
2ce0561
c86fa27
2dbdc34
27f72cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ internal class MethodWrapper | |
{ | ||
public IntPtr mdef; | ||
public IntPtr ptr; | ||
private bool _disposed = false; | ||
|
||
public MethodWrapper(Type type, string name, string funcType = null) | ||
{ | ||
|
@@ -31,5 +32,21 @@ public IntPtr Call(IntPtr args, IntPtr kw) | |
{ | ||
return Runtime.PyCFunction_Call(ptr, args, kw); | ||
} | ||
|
||
public void Release() | ||
{ | ||
if (_disposed) | ||
{ | ||
return; | ||
} | ||
_disposed = true; | ||
bool freeDef = Runtime.Refcount(ptr) == 1; | ||
Runtime.XDecref(ptr); | ||
if (freeDef && mdef != IntPtr.Zero) | ||
{ | ||
Runtime.PyMem_Free(mdef); | ||
mdef = IntPtr.Zero; | ||
} | ||
Comment on lines
+43
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @amos402 Could you comment on this question? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It won't release anymore, here's the only chance for now. Assume the ptr deallocating in another domain in the future, the cod in this domain had already been invalid, unless we use a C extension take place the ptr's |
||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid introducing another compile-time check, and use version info from
Runtime
class instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, in the modernisation branch I gave up on the idea of having Python 2 and 3 in the same codebase, especially considering the imminent EoL of Python 2. I do that by defaulting to Python 3 and letting the user supply
PYTHON2
explicitly for the Py2 version. So here, to stay in line with that, it would be enough to change to#if !PYTHON2
.