bpo-39573: Add Py_SET_REFCNT() function (GH-18389) · python/cpython@c86a112 (original) (raw)
`@@ -3551,7 +3551,7 @@ slot_tp_del(PyObject *self)
`
3551
3551
``
3552
3552
`/* Temporarily resurrect the object. */
`
3553
3553
`assert(Py_REFCNT(self) == 0);
`
3554
``
`-
Py_REFCNT(self) = 1;
`
``
3554
`+
Py_SET_REFCNT(self, 1);
`
3555
3555
``
3556
3556
`/* Save the current exception, if any. */
`
3557
3557
`PyErr_Fetch(&error_type, &error_value, &error_traceback);
`
`@@ -3574,7 +3574,8 @@ slot_tp_del(PyObject *self)
`
3574
3574
` * cause a recursive call.
`
3575
3575
` */
`
3576
3576
`assert(Py_REFCNT(self) > 0);
`
3577
``
`-
if (--Py_REFCNT(self) == 0) {
`
``
3577
`+
Py_SET_REFCNT(self, Py_REFCNT(self) - 1);
`
``
3578
`+
if (Py_REFCNT(self) == 0) {
`
3578
3579
`/* this is the normal path out */
`
3579
3580
`return;
`
3580
3581
` }
`
`@@ -3585,7 +3586,7 @@ slot_tp_del(PyObject *self)
`
3585
3586
` {
`
3586
3587
`Py_ssize_t refcnt = Py_REFCNT(self);
`
3587
3588
`_Py_NewReference(self);
`
3588
``
`-
Py_REFCNT(self) = refcnt;
`
``
3589
`+
Py_SET_REFCNT(self, refcnt);
`
3589
3590
` }
`
3590
3591
`assert(!PyType_IS_GC(Py_TYPE(self)) || _PyObject_GC_IS_TRACKED(self));
`
3591
3592
`/* If Py_REF_DEBUG macro is defined, _Py_NewReference() increased
`
`@@ -4621,7 +4622,7 @@ check_pyobject_uninitialized_is_freed(PyObject *self, PyObject *Py_UNUSED(args))
`
4621
4622
`return NULL;
`
4622
4623
` }
`
4623
4624
`/* Initialize reference count to avoid early crash in ceval or GC */
`
4624
``
`-
Py_REFCNT(op) = 1;
`
``
4625
`+
Py_SET_REFCNT(op, 1);
`
4625
4626
`/* object fields like ob_type are uninitialized! */
`
4626
4627
`return test_pyobject_is_freed("check_pyobject_uninitialized_is_freed", op);
`
4627
4628
`}
`
`@@ -4636,7 +4637,7 @@ check_pyobject_forbidden_bytes_is_freed(PyObject *self, PyObject *Py_UNUSED(args
`
4636
4637
`return NULL;
`
4637
4638
` }
`
4638
4639
`/* Initialize reference count to avoid early crash in ceval or GC */
`
4639
``
`-
Py_REFCNT(op) = 1;
`
``
4640
`+
Py_SET_REFCNT(op, 1);
`
4640
4641
`/* ob_type field is after the memory block: part of "forbidden bytes"
`
4641
4642
` when using debug hooks on memory allocators! */
`
4642
4643
`return test_pyobject_is_freed("check_pyobject_forbidden_bytes_is_freed", op);
`
`@@ -4652,7 +4653,7 @@ check_pyobject_freed_is_freed(PyObject *self, PyObject *Py_UNUSED(args))
`
4652
4653
` }
`
4653
4654
`Py_TYPE(op)->tp_dealloc(op);
`
4654
4655
`/* Reset reference count to avoid early crash in ceval or GC */
`
4655
``
`-
Py_REFCNT(op) = 1;
`
``
4656
`+
Py_SET_REFCNT(op, 1);
`
4656
4657
`/* object memory is freed! */
`
4657
4658
`return test_pyobject_is_freed("check_pyobject_freed_is_freed", op);
`
4658
4659
`}
`
`@@ -5134,7 +5135,7 @@ negative_refcount(PyObject *self, PyObject *Py_UNUSED(args))
`
5134
5135
` }
`
5135
5136
`assert(Py_REFCNT(obj) == 1);
`
5136
5137
``
5137
``
`-
Py_REFCNT(obj) = 0;
`
``
5138
`+
Py_SET_REFCNT(obj, 0);
`
5138
5139
`/* Py_DECREF() must call _Py_NegativeRefcount() and abort Python */
`
5139
5140
`Py_DECREF(obj);
`
5140
5141
``