mirror of
https://github.com/python/cpython.git
synced 2025-11-24 20:30:18 +00:00
gh-140061: Use _PyObject_IsUniquelyReferenced() to check if objects are uniquely referenced (gh-140062)
The previous `Py_REFCNT(x) == 1` checks can have data races in the free threaded build. `_PyObject_IsUniquelyReferenced(x)` is a more conservative check that is safe in the free threaded build and is identical to `Py_REFCNT(x) == 1` in the default GIL-enabled build.
This commit is contained in:
parent
fe9ac7fc8c
commit
32c264982e
10 changed files with 29 additions and 36 deletions
|
|
@ -3171,7 +3171,7 @@ PyBytes_Concat(PyObject **pv, PyObject *w)
|
|||
return;
|
||||
}
|
||||
|
||||
if (Py_REFCNT(*pv) == 1 && PyBytes_CheckExact(*pv)) {
|
||||
if (_PyObject_IsUniquelyReferenced(*pv) && PyBytes_CheckExact(*pv)) {
|
||||
/* Only one reference, so we can resize in place */
|
||||
Py_ssize_t oldsize;
|
||||
Py_buffer wb;
|
||||
|
|
@ -3256,7 +3256,7 @@ _PyBytes_Resize(PyObject **pv, Py_ssize_t newsize)
|
|||
Py_DECREF(v);
|
||||
return 0;
|
||||
}
|
||||
if (Py_REFCNT(v) != 1) {
|
||||
if (!_PyObject_IsUniquelyReferenced(v)) {
|
||||
if (oldsize < newsize) {
|
||||
*pv = _PyBytes_FromSize(newsize, 0);
|
||||
if (*pv) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue