Skip to content

Commit bdf907f

Browse files
committed
Make Py_DECREF a call
1 parent 4617d68 commit bdf907f

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

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
@@ -420,19 +420,7 @@ static inline void Py_DECREF(const char *filename, int lineno, PyObject *op)
420420

421421
#else
422422

423-
static inline Py_ALWAYS_INLINE void Py_DECREF(PyObject *op)
424-
{
425-
// Non-limited C API and limited C API for Python 3.9 and older access
426-
// directly PyObject.ob_refcnt.
427-
if (_Py_IsImmortal(op)) {
428-
_Py_DECREF_IMMORTAL_STAT_INC();
429-
return;
430-
}
431-
_Py_DECREF_STAT_INC();
432-
if (--op->ob_refcnt == 0) {
433-
_Py_Dealloc(op);
434-
}
435-
}
423+
extern Py_NO_INLINE PyAPI_FUNC(void) Py_DECREF(PyObject *op);
436424
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
437425
#endif
438426

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
@@ -1892,7 +1917,7 @@ _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name,
18921917
}
18931918
done:
18941919
_PyThreadState_PopCStackRef(tstate, &cref);
1895-
Py_DECREF(tp);
1920+
Py_DECREF((PyObject *)tp);
18961921
Py_DECREF(name);
18971922
return res;
18981923
}

0 commit comments

Comments
 (0)