Skip to content

Commit 2989918

Browse files
Address review suggestions
1 parent 45593e8 commit 2989918

File tree

6 files changed

+8
-15
lines changed

6 files changed

+8
-15
lines changed

Modules/_functoolsmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ _functools_reduce_impl(PyObject *module, PyObject *func, PyObject *seq,
10761076
for (;;) {
10771077
PyObject *op2;
10781078

1079-
if (Py_REFCNT(args) > 1) {
1079+
if (_PyObject_IsUniquelyReferenced(args)) {
10801080
Py_DECREF(args);
10811081
if ((args = PyTuple_New(2)) == NULL)
10821082
goto Fail;

Modules/_testcapi/object.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ negative_refcount(PyObject *self, PyObject *Py_UNUSED(args))
258258
if (obj == NULL) {
259259
return NULL;
260260
}
261-
assert(PyUnstable_Object_IsUniquelyReferenced(obj));
261+
assert(Py_REFCNT(obj) == 1);
262262

263263
Py_SET_REFCNT(obj, 0);
264264
/* Py_DECREF() must call _Py_NegativeRefcount() and abort Python */
@@ -275,7 +275,7 @@ decref_freed_object(PyObject *self, PyObject *Py_UNUSED(args))
275275
if (obj == NULL) {
276276
return NULL;
277277
}
278-
assert(PyUnstable_Object_IsUniquelyReferenced(obj));
278+
assert(Py_REFCNT(obj) == 1);
279279

280280
// Deallocate the memory
281281
Py_DECREF(obj);

Objects/dictobject.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5667,16 +5667,10 @@ dictiter_iternext_threadsafe(PyDictObject *d, PyObject *self,
56675667

56685668
#endif
56695669

5670-
static bool
5671-
has_unique_reference(PyObject *op)
5672-
{
5673-
return _PyObject_IsUniquelyReferenced(op) == 1;
5674-
}
5675-
56765670
static bool
56775671
acquire_iter_result(PyObject *result)
56785672
{
5679-
if (has_unique_reference(result)) {
5673+
if (_PyObject_IsUniquelyReferenced(result)) {
56805674
Py_INCREF(result);
56815675
return true;
56825676
}

Objects/listobject.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ ensure_shared_on_resize(PyListObject *self)
7979
// We can't use _Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED here because
8080
// the `CALL_LIST_APPEND` bytecode handler may lock the list without
8181
// a critical section.
82-
assert(_PyObject_IsUniquelyReferenced((PyObject *)self) ||
83-
PyMutex_IsLocked(&_PyObject_CAST(self)->ob_mutex));
82+
assert(Py_REFCNT(self) == 1 || PyMutex_IsLocked(&_PyObject_CAST(self)->ob_mutex));
8483

8584
// Ensure that the list array is freed using QSBR if we are not the
8685
// owning thread.

Objects/longobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6953,7 +6953,7 @@ PyLongWriter_Discard(PyLongWriter *writer)
69536953
}
69546954

69556955
PyLongObject *obj = (PyLongObject *)writer;
6956-
assert(_PyObject_IsUniquelyReferenced((PyObject *)obj));
6956+
assert(Py_REFCNT(obj) == 1);
69576957
Py_DECREF(obj);
69586958
}
69596959

@@ -6962,7 +6962,7 @@ PyObject*
69626962
PyLongWriter_Finish(PyLongWriter *writer)
69636963
{
69646964
PyLongObject *obj = (PyLongObject *)writer;
6965-
assert(_PyObject_IsUniquelyReferenced((PyObject *)obj));
6965+
assert(Py_REFCNT(obj) == 1);
69666966

69676967
// Normalize and get singleton if possible
69686968
obj = maybe_small_long(long_normalize(obj));

Objects/unicodeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,7 @@ unicode_dealloc(PyObject *unicode)
17171717
// Successfully popped.
17181718
assert(popped == unicode);
17191719
// Only our `popped` reference should be left; remove it too.
1720-
assert(_PyObject_IsUniquelyReferenced(unicode));
1720+
assert(Py_REFCNT(unicode) == 1);
17211721
Py_SET_REFCNT(unicode, 0);
17221722
#ifdef Py_REF_DEBUG
17231723
/* let's be pedantic with the ref total */

0 commit comments

Comments
 (0)