Skip to content

Commit 6cfe8e1

Browse files
committed
Make Py_DECREF a call
1 parent 490eea0 commit 6cfe8e1

3 files changed

Lines changed: 30 additions & 23 deletions

File tree

Include/internal/pycore_object.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -474,14 +474,8 @@ static inline void _Py_DECREF_MORTAL_SPECIALIZED(const char *filename, int linen
474474

475475
#else
476476

477-
static inline void Py_DECREF_MORTAL(PyObject *op)
478-
{
479-
assert(!_Py_IsStaticImmortal(op));
480-
_Py_DECREF_STAT_INC();
481-
if (--op->ob_refcnt == 0) {
482-
_Py_Dealloc(op);
483-
}
484-
}
477+
extern Py_NO_INLINE PyAPI_FUNC(void) Py_DECREF_MORTAL(PyObject *op);
478+
485479
#define Py_DECREF_MORTAL(op) Py_DECREF_MORTAL(_PyObject_CAST(op))
486480

487481
static inline void Py_DECREF_MORTAL_SPECIALIZED(PyObject *op, destructor destruct)

Include/refcount.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -403,19 +403,7 @@ static inline void Py_DECREF(const char *filename, int lineno, PyObject *op)
403403

404404
#else
405405

406-
static inline Py_ALWAYS_INLINE void Py_DECREF(PyObject *op)
407-
{
408-
// Non-limited C API and limited C API for Python 3.9 and older access
409-
// directly PyObject.ob_refcnt.
410-
if (_Py_IsImmortal(op)) {
411-
_Py_DECREF_IMMORTAL_STAT_INC();
412-
return;
413-
}
414-
_Py_DECREF_STAT_INC();
415-
if (--op->ob_refcnt == 0) {
416-
_Py_Dealloc(op);
417-
}
418-
}
406+
extern Py_NO_INLINE PyAPI_FUNC(void) Py_DECREF(PyObject *op);
419407
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
420408
#endif
421409

Objects/object.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,31 @@ _Py_AddToAllObjects(PyObject *op)
264264
}
265265
#endif /* Py_TRACE_REFS */
266266

267+
#undef Py_DECREF_MORTAL
268+
Py_NO_INLINE void Py_DECREF_MORTAL(PyObject *op)
269+
{
270+
assert(!_Py_IsStaticImmortal(op));
271+
_Py_DECREF_STAT_INC();
272+
if (--op->ob_refcnt == 0) {
273+
_Py_Dealloc(op);
274+
}
275+
}
276+
277+
#undef Py_DECREF
278+
Py_NO_INLINE void Py_DECREF(PyObject *op)
279+
{
280+
// Non-limited C API and limited C API for Python 3.9 and older access
281+
// directly PyObject.ob_refcnt.
282+
if (_Py_IsImmortal(op)) {
283+
_Py_DECREF_IMMORTAL_STAT_INC();
284+
return;
285+
}
286+
_Py_DECREF_STAT_INC();
287+
if (--op->ob_refcnt == 0) {
288+
_Py_Dealloc(op);
289+
}
290+
}
291+
267292
#ifdef Py_REF_DEBUG
268293
/* Log a fatal error; doesn't return. */
269294
void
@@ -916,7 +941,7 @@ free_object(void *obj)
916941
PyObject *op = (PyObject *)obj;
917942
PyTypeObject *tp = Py_TYPE(op);
918943
tp->tp_free(op);
919-
Py_DECREF(tp);
944+
Py_DECREF((PyObject *)tp);
920945
}
921946

922947
void
@@ -2026,7 +2051,7 @@ _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name,
20262051
}
20272052
done:
20282053
_PyThreadState_PopCStackRef(tstate, &cref);
2029-
Py_DECREF(tp);
2054+
Py_DECREF((PyObject *)tp);
20302055
Py_DECREF(name);
20312056
return res;
20322057
}

0 commit comments

Comments
 (0)