-
Notifications
You must be signed in to change notification settings - Fork 289
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
Preparation for finalizer code, refactoring some simple_destructor logic. #666
Conversation
|
Oh nice I have PR 666 😈 |
f0695a8
to
ad9c048
Compare
808b807
to
252f8d6
Compare
@@ -4080,6 +4080,30 @@ static PyMethodDef module_methods[] = { | |||
{NULL, NULL} /* sentinel */ | |||
}; | |||
|
|||
PyTypeObject* Itertool_SafeDealloc_Types[] = { | |||
// &combinations_type, | |||
// &cwr_type, |
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.
are these commented out because they're not actually safe?
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.
I copied the static array from PyTypeObject *typelist[]
that has all the types in the file, then commented out those that I wasn't sure was safe yeah.
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.
definitely add that to the comment (maybe with a TODO
to take a further look). confusing otherwise.
7d96a26
to
2b595e7
Compare
Updated -- ready for review again. That |
lgtm (pending #662) though I think it'd be nice to address proxy_to_tp_clear. I kicked travis-ci so it's retesting and should hopefully not hit that threading_local issue a second time :) |
f95dbf3
to
2f0bf7d
Compare
Ok, I replaced that to use the default |
Actually no that's not true. |
030a20e
to
a5cf65a
Compare
what does "address proxy_to_tp_clear" mean? missing context :) |
Replacing |
hm, I think it will if weakref_dealloc is just:
and proxy_dealloc is just:
The wildcards are and PyObject_GC_Del appears to call (through a few macro expansions) PyObject_Free which does gc_compat_free, which definitely won't work for this. okay, I'm convinced. |
That one is fine, I tried setting
|
static void setTypeGCProxy(BoxedClass* cls) { | ||
cls->tp_alloc = PystonType_GenericAlloc; | ||
cls->gc_visit = proxy_to_tp_traverse; | ||
cls->tp_dealloc = proxy_to_tp_clear; |
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.
might be good to add a comment here "we can't use the normal tp_dealloc here, since proxy_dealloc explicitly frees self but doesn't go through tp_free, etc..." so we don't forget and ask the questions again :)
Replace the function pointer to the simple_destructor with a boolean indicating that the tp_dealloc function is safe to call whenever the simple_destructor used to be instead. A few additional classes are also specified to have a safe_tp_dealloc. For exceptions, use a hack where we look for the creation of exception classes and store them in a list so we can set their destructor at the same time as other classes.
I think we're a bit off-track on the proxy_to_tp_clear issue -- tp_clear is the wrong attribute for us to be relying on, and tp_dealloc is the right one. There's nothing particularly special about the proxy_dealloc method, and while it's ok for us to make some restrictions on the c extension code we'll support, it seems like this is a pretty bad workaround for a case that we need to support anyway. |
nod. I mean we can just change the proxy tp_dealloc to do the same tp_free invocation that weakref_dealloc does (and set tp_free to default_free). The only reason I didn't feel too strongly either way about this is that this particular method is already very specialized and only used for the weakref types. is there any reason we couldn't just change PyObject_GC_Del(o) to go through tp_free? |
@rudi-c okay, so steps forward from here are, I think:
sound good? |
Preparation for finalizer code, refactoring some simple_destructor logic.
👍 |
Mostly moving simple_destructor functions into tp_dealloc instead of their own field. Replace the field with a boolean to indicate whether the tp_dealloc has the safety properties of a simple_destructor. Assign simple_destructor to more builtin types.
Depends on gcfinalizers2 PR.