-
Notifications
You must be signed in to change notification settings - Fork 749
Reset the type slots (split from #958) #1016
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
118c21a
953b5b5
515b227
f5c53a1
e0960d0
61dbb8d
03674d2
e7effd8
8baad6a
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 |
---|---|---|
|
@@ -11,17 +11,30 @@ namespace Python.Runtime | |
internal class MetaType : ManagedType | ||
{ | ||
private static IntPtr PyCLRMetaType; | ||
|
||
private static SlotsHolder _metaSlotsHodler; | ||
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. I just noticed the typo here. This is holding slots, not bitcoin. |
||
|
||
/// <summary> | ||
/// Metatype initialization. This bootstraps the CLR metatype to life. | ||
/// </summary> | ||
public static IntPtr Initialize() | ||
{ | ||
PyCLRMetaType = TypeManager.CreateMetaType(typeof(MetaType)); | ||
PyCLRMetaType = TypeManager.CreateMetaType(typeof(MetaType), out _metaSlotsHodler); | ||
return PyCLRMetaType; | ||
} | ||
|
||
public static void Release() | ||
{ | ||
if (PyCLRMetaType == IntPtr.Zero) | ||
{ | ||
throw new ObjectDisposedException("PyCLRMetaType"); | ||
} | ||
if (Runtime.Refcount(PyCLRMetaType) > 1) | ||
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. Not sure I understand the reasoning behind 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. I think the reasoning is the same as with the similar pattern in typemanager.cs#38. The only way I can see this class tracking it's allocation is to look if the 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. The logic is: If the refcount is 1, then at line 31 when decref, it'll go to zero and the entire type will be released. In that case we don't care about clearing the slots. It's a standard optimization in a ref-counting framework. It's correct assuming that ReleaseTypeSlots doesn't also release refcounts that otherwise won't be released. That said: Do we have coverage on line 29? I'm not sure I really understand under what circumstance it happens. 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. I'd put the expression into |
||
{ | ||
_metaSlotsHodler.ResetSlots(); | ||
} | ||
Runtime.Py_CLEAR(ref PyCLRMetaType); | ||
_metaSlotsHodler = null; | ||
} | ||
|
||
/// <summary> | ||
/// Metatype __new__ implementation. This is called to create a new | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ internal class MethodWrapper | |
public IntPtr mdef; | ||
public IntPtr ptr; | ||
private bool _disposed = false; | ||
|
||
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 you add this empty line back in you remove an entire file from the squash-commit. |
||
private ThunkInfo _thunk; | ||
|
||
public MethodWrapper(Type type, string name, string funcType = null) | ||
|
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.
Please, add the following link as a comment: https://docs.python.org/3/c-api/structures.html#c.PyMethodDef