8000 gh-127705: Move Py_INCREF_MORTAL() to the internal C API (GH-136178) · python/cpython@fa43a1e · GitHub
[go: up one dir, main page]

Skip to content

Commit fa43a1e

Browse files
authored
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.
1 parent ab7196a commit fa43a1e

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
@@ -1033,6 +1033,20 @@ enum _PyAnnotateFormat {
10331033

10341034
int _PyObject_SetDict(PyObject *obj, PyObject *value);
10351035

1036+
#ifndef Py_GIL_DISABLED
1037+
static inline Py_ALWAYS_INLINE void _Py_INCREF_MORTAL(PyObject *op)
1038+
{
1039+
assert(!_Py_IsStaticImmortal(op));
1040+
op->ob_refcnt++;
1041+
_Py_INCREF_STAT_INC();
1042+
#if defined(Py_REF_DEBUG) && !defined(Py_LIMITED_API)
1043+
if (!_Py_IsImmortal(op)) {
1044+
_Py_INCREF_IncRefTotal();
1045+
}
1046+
#endif
1047+
}
1048+
#endif
1049+
10361050
#ifdef __cplusplus
10371051
}
10381052
#endif

Include/internal/pycore_stackref.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ _PyStackRef_FromPyObjectNew(PyObject *obj)
626626
if (_Py_IsImmortal(obj)) {
627627
return (_PyStackRef){ .bits = ((uintptr_t)obj) | Py_TAG_REFCNT};
628628
}
629-
Py_INCREF_MORTAL(obj);
629+
_Py_INCREF_MORTAL(obj);
630630
_PyStackRef ref = (_PyStackRef){ .bits = (uintptr_t)obj };
631631
PyStackRef_CheckValid(ref);
632632
return ref;
@@ -637,7 +637,7 @@ static inline _PyStackRef
637637
_PyStackRef_FromPyObjectNewMortal(PyObject *obj)
638638
{
639639
assert(obj != NULL);
640-
Py_INCREF_MORTAL(obj);
640+
_Py_INCREF_MORTAL(obj);
641641
_PyStackRef ref = (_PyStackRef){ .bits = (uintptr_t)obj };
642642
PyStackRef_CheckValid(ref);
643643
return ref;
@@ -654,14 +654,14 @@ PyStackRef_FromPyObjectBorrow(PyObject *obj)
654654
/* WARNING: This macro evaluates its argument more than once */
655655
#ifdef _WIN32
656656
#define PyStackRef_DUP(REF) \
657-
(PyStackRef_RefcountOnObject(REF) ? (Py_INCREF_MORTAL(BITS_TO_PTR(REF)), (REF)) : (REF))
657+
(PyStackRef_RefcountOnObject(REF) ? (_Py_INCREF_MORTAL(BITS_TO_PTR(REF)), (REF)) : (REF))
658658
#else
659659
static inline _PyStackRef
660660
PyStackRef_DUP(_PyStackRef ref)
661661
{
662662
assert(!PyStackRef_IsNull(ref));
663663
if (PyStackRef_RefcountOnObject(ref)) {
664-
Py_INCREF_MORTAL(BITS_TO_PTR(ref));
664+
_Py_INCREF_MORTAL(BITS_TO_PTR(ref));
665665
}
666666
return ref;
667667
}

Include/refcount.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -244,20 +244,6 @@ PyAPI_FUNC(void) Py_DecRef(PyObject *);
244244
PyAPI_FUNC(void) _Py_IncRef(PyObject *);
245245
PyAPI_FUNC(void) _Py_DecRef(PyObject *);
246246

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

0 commit comments

Comments
 (0)
0