Skip to content
Prev Previous commit
Next Next commit
Fix typo
  • Loading branch information
colesbury authored and corona10 committed Oct 30, 2023
commit 3c85ca12a73636fa040482a77e3119a4d76477cc
2 changes: 1 addition & 1 deletion Include/internal/pycore_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static inline void _Py_RefcntAdd(PyObject* op, Py_ssize_t n)
#if !defined(Py_NOGIL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this worth the extra code?
_Py_RefcntAdd is only used in list_repeat and tuplerepeat. Multiplying tuples and lists by ints is hardly a common operation.
Would it perhaps make more sense to remove _Py_RefcntAdd and use plain Py_INCREF in those functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting removing _Py_RefcntAdd in general or just for Py_NOGIL?

op->ob_refcnt += n;
#else
if (_Py_IsOnwedByCurrentThread(op)) {
if (_Py_IsOwnedByCurrentThread(op)) {
uint32_t local = op->ob_ref_local;
Py_ssize_t refcnt = (Py_ssize_t)local + n;
# if PY_SSIZE_T_MAX > UINT32_MAX
Expand Down
10 changes: 5 additions & 5 deletions Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ _Py_ThreadId(void)

#if defined(Py_NOGIL) && !defined(Py_LIMITED_API)
static inline Py_ALWAYS_INLINE int
_Py_IsOnwedByCurrentThread(PyObject *ob)
_Py_IsOwnedByCurrentThread(PyObject *ob)
{
return ob->ob_tid == _Py_ThreadId();
}
Expand Down Expand Up @@ -340,7 +340,7 @@ static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {
#if !defined(Py_NOGIL)
ob->ob_refcnt = refcnt;
#else
if (_Py_IsOnwedByCurrentThread(ob)) {
if (_Py_IsOwnedByCurrentThread(ob)) {
// Set local refcount to desired refcount and shared refcount to zero,
// but preserve the shared refcount flags.
assert(refcnt < UINT32_MAX);
Expand Down Expand Up @@ -738,7 +738,7 @@ static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
if (new_local == 0) {
return;
}
if (_Py_IsOnwedByCurrentThread(op)) {
if (_Py_IsOwnedByCurrentThread(op)) {
_Py_atomic_store_uint32_relaxed(&op->ob_ref_local, new_local);
}
else {
Expand Down Expand Up @@ -805,7 +805,7 @@ static inline void Py_DECREF(const char *filename, int lineno, PyObject *op)
}
_Py_DECREF_STAT_INC();
_Py_DECREF_DecRefTotal();
if (_Py_IsOnwedByCurrentThread(op)) {
if (_Py_IsOwnedByCurrentThread(op)) {
if (local == 0) {
_Py_NegativeRefcount(filename, lineno, op);
}
Expand All @@ -829,7 +829,7 @@ static inline void Py_DECREF(PyObject *op)
return;
}
_Py_DECREF_STAT_INC();
if (_Py_IsOnwedByCurrentThread(op)) {
if (_Py_IsOwnedByCurrentThread(op)) {
local--;
_Py_atomic_store_uint32_relaxed(&op->ob_ref_local, local);
if (local == 0) {
Expand Down