-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-135832: implement Py_DECREF specializations for Py_GIL_DISABLED build #135833
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?
gh-135832: implement Py_DECREF specializations for Py_GIL_DISABLED build #135833
Conversation
static inline void | ||
_Py_DECREF_NO_DEALLOC(PyObject *op) |
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'm not sure this function is used anymore.
@@ -272,17 +272,93 @@ _Py_DECREF_NO_DEALLOC(PyObject *op) | |||
} | |||
|
|||
#else | |||
// TODO: implement Py_DECREF specializations for Py_GIL_DISABLED build | |||
|
|||
static inline void | |||
_Py_DECREF_SPECIALIZED(PyObject *op, const destructor destruct) |
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.
This function is barely used now, but there's a similar function PyStackRef_CLOSE_SPECIALIZED
.
There are two possible reasons to implement this as something that's not just Py_DECREF
:
- Performance, but it's not really clear that it's going to be any faster
- To avoid
_Py_Dealloc
so that you can enable this assertionLines 3166 to 3170 in 6227662
#if !defined(Py_GIL_DISABLED) && !defined(Py_STACKREF_DEBUG) /* This assertion doesn't hold for the free-threading build, as * PyStackRef_CLOSE_SPECIALIZED is not implemented */ assert(tstate->current_frame == NULL || tstate->current_frame->stackpointer != NULL); #endif _Py_MergeZeroLocalRefcount
because that internally may call_Py_Dealloc
I think (2) would be difficult to achieve because of _Py_brc_queue_object
.
&op->ob_ref_shared, | ||
&shared, | ||
new_shared)) { | ||
if (new_shared == 0) { |
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.
You can only safely deallocate if the reference count is zero and it's merged (i.e., new_shared is _Py_REF_MERGED
)
Py_ssize_t new_shared = shared - (1 << _Py_REF_SHARED_SHIFT); | ||
if (_Py_atomic_compare_exchange_ssize( |
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.
This is missing important parts of _Py_DecRefShared
: if the shared reference count becomes negative, the object must be queued so that the owning thread merges the two reference count fields.
Uh oh!
There was an error while loading. Please reload this page.