Skip to content

Commit 8dcf3ed

Browse files
[3.14] gh-127705: Move Py_INCREF_MORTAL() to the internal C API (GH-136178) (#136206)
gh-127705: Move Py_INCREF_MORTAL() to the internal C API (GH-136178) Rename Py_INCREF_MORTAL() to _Py_INCREF_MORTAL() and move it to pycore_object.h internal header. (cherry picked from commit fa43a1e) Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 5216a6c commit 8dcf3ed

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

Include/internal/pycore_object.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,20 @@ enum _PyAnnotateFormat {
10091009

10101010
int _PyObject_SetDict(PyObject *obj, PyObject *value);
10111011

1012+
#ifndef Py_GIL_DISABLED
1013+
static inline Py_ALWAYS_INLINE void _Py_INCREF_MORTAL(PyObject *op)
1014+
{
1015+
assert(!_Py_IsStaticImmortal(op));
1016+
op->ob_refcnt++;
1017+
_Py_INCREF_STAT_INC();
1018+
#if defined(Py_REF_DEBUG) && !defined(Py_LIMITED_API)
1019+
if (!_Py_IsImmortal(op)) {
1020+
_Py_INCREF_IncRefTotal();
1021+
}
1022+
#endif
1023+
}
1024+
#endif
1025+
10121026
#ifdef __cplusplus
10131027
}
10141028
#endif

Include/internal/pycore_stackref.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ _PyStackRef_FromPyObjectNew(PyObject *obj)
561561
if (_Py_IsImmortal(obj)) {
562562
return (_PyStackRef){ .bits = ((uintptr_t)obj) | Py_TAG_REFCNT};
563563
}
564-
Py_INCREF_MORTAL(obj);
564+
_Py_INCREF_MORTAL(obj);
565565
_PyStackRef ref = (_PyStackRef){ .bits = (uintptr_t)obj };
566566
PyStackRef_CheckValid(ref);
567567
return ref;
@@ -572,7 +572,7 @@ static inline _PyStackRef
572572
_PyStackRef_FromPyObjectNewMortal(PyObject *obj)
573573
{
574574
assert(obj != NULL);
575-
Py_INCREF_MORTAL(obj);
575+
_Py_INCREF_MORTAL(obj);
576576
_PyStackRef ref = (_PyStackRef){ .bits = (uintptr_t)obj };
577577
PyStackRef_CheckValid(ref);
578578
return ref;
@@ -590,14 +590,14 @@ PyStackRef_FromPyObjectImmortal(PyObject *obj)
590590
/* WARNING: This macro evaluates its argument more than once */
591591
#ifdef _WIN32
592592
#define PyStackRef_DUP(REF) \
593-
(PyStackRef_RefcountOnObject(REF) ? (Py_INCREF_MORTAL(BITS_TO_PTR(REF)), (REF)) : (REF))
593+
(PyStackRef_RefcountOnObject(REF) ? (_Py_INCREF_MORTAL(BITS_TO_PTR(REF)), (REF)) : (REF))
594594
#else
595595
static inline _PyStackRef
596596
PyStackRef_DUP(_PyStackRef ref)
597597
{
598598
assert(!PyStackRef_IsNull(ref));
599599
if (PyStackRef_RefcountOnObject(ref)) {
600-
Py_INCREF_MORTAL(BITS_TO_PTR(ref));
600+
_Py_INCREF_MORTAL(BITS_TO_PTR(ref));
601601
}
602602
return ref;
603603
}

Include/refcount.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -247,20 +247,6 @@ PyAPI_FUNC(void) Py_DecRef(PyObject *);
247247
PyAPI_FUNC(void) _Py_IncRef(PyObject *);
248248
PyAPI_FUNC(void) _Py_DecRef(PyObject *);
249249

250-
#ifndef Py_GIL_DISABLED
251-
static inline Py_ALWAYS_INLINE void Py_INCREF_MORTAL(PyObject *op)
252-
{
253-
assert(!_Py_IsStaticImmortal(op));
254-
op->ob_refcnt++;
255-
_Py_INCREF_STAT_INC();
256-
#if defined(Py_REF_DEBUG) && !defined(Py_LIMITED_API)
257-
if (!_Py_IsImmortal(op)) {
258-
_Py_INCREF_IncRefTotal();
259-
}
260-
#endif
261-
}
262-
#endif
263-
264250
static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
265251
{
266252
#if defined(Py_LIMITED_API) && (Py_LIMITED_API+0 >= 0x030c0000 || defined(Py_REF_DEBUG))

0 commit comments

Comments
 (0)