-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-135228: When @dataclass(slots=True) replaces a dataclass, make the original class collectible (take 2) #137047
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
916ce1b
6dc0f48
b9fb155
52c7d2b
250f3e9
a9483b4
8c2c1e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2666,13 +2666,22 @@ sys__clear_type_descriptors(PyObject *module, PyObject *type) | |
return NULL; | ||
} | ||
PyObject *dict = _PyType_GetDict(typeobj); | ||
if (PyDict_PopString(dict, "__dict__", NULL) < 0) { | ||
PyObject *dunder_dict = NULL; | ||
if (PyDict_PopString(dict, "__dict__", &dunder_dict) < 0) { | ||
return NULL; | ||
} | ||
if (PyDict_PopString(dict, "__weakref__", NULL) < 0) { | ||
PyObject *dunder_weakref = NULL; | ||
if (PyDict_PopString(dict, "__weakref__", &dunder_weakref) < 0) { | ||
JelleZijlstra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
PyType_Modified(typeobj); | ||
Py_XDECREF(dunder_dict); | ||
return NULL; | ||
} | ||
PyType_Modified(typeobj); | ||
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. This seems to be technically not thread-safe, because somebody in another thread may be working with the type between the PopString calls and the PyType_Modified call. However, this is also true for the various functions in 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. Could anything be deallocated as a result of these pops? Could have a reentrancy problem even without threads present. 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 guess to prevent that we can hold onto a reference to the old value (by passing the third arg to PyDict_PopString) and DECREF it only after we call PyType_Modified. 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. Yeah, that seems safer. |
||
// We try to hold onto a reference to these until after we call | ||
// PyType_Modified(), in case their deallocation triggers somer user code | ||
// that tries to do something to the type. | ||
Py_XDECREF(dunder_dict); | ||
Py_XDECREF(dunder_weakref); | ||
Py_RETURN_NONE; | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.