]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-127705: Move Py_INCREF_MORTAL() to the internal C API (GH-136178) (#136206)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 3 Jul 2025 06:42:17 +0000 (08:42 +0200)
committerGitHub <noreply@github.com>
Thu, 3 Jul 2025 06:42:17 +0000 (06:42 +0000)
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 fa43a1e0f8caf00a15898fa719e31767c866bd90)

Co-authored-by: Victor Stinner <vstinner@python.org>
Include/internal/pycore_object.h
Include/internal/pycore_stackref.h
Include/refcount.h

index 942de9de251029bb7a415b3ff8e9c2c746d46bb4..1f9c7b1bf55b3f30e6f93ffcfb6c694bc0b8d099 100644 (file)
@@ -1009,6 +1009,20 @@ enum _PyAnnotateFormat {
 
 int _PyObject_SetDict(PyObject *obj, PyObject *value);
 
+#ifndef Py_GIL_DISABLED
+static inline Py_ALWAYS_INLINE void _Py_INCREF_MORTAL(PyObject *op)
+{
+    assert(!_Py_IsStaticImmortal(op));
+    op->ob_refcnt++;
+    _Py_INCREF_STAT_INC();
+#if defined(Py_REF_DEBUG) && !defined(Py_LIMITED_API)
+    if (!_Py_IsImmortal(op)) {
+        _Py_INCREF_IncRefTotal();
+    }
+#endif
+}
+#endif
+
 #ifdef __cplusplus
 }
 #endif
index a2acf311ff4c654da27e0becff93a1e3485663da..4b5caca5dbd126c4367f0dcf8074bbf6b76f3aa9 100644 (file)
@@ -561,7 +561,7 @@ _PyStackRef_FromPyObjectNew(PyObject *obj)
     if (_Py_IsImmortal(obj)) {
         return (_PyStackRef){ .bits = ((uintptr_t)obj) | Py_TAG_REFCNT};
     }
-    Py_INCREF_MORTAL(obj);
+    _Py_INCREF_MORTAL(obj);
     _PyStackRef ref = (_PyStackRef){ .bits = (uintptr_t)obj };
     PyStackRef_CheckValid(ref);
     return ref;
@@ -572,7 +572,7 @@ static inline _PyStackRef
 _PyStackRef_FromPyObjectNewMortal(PyObject *obj)
 {
     assert(obj != NULL);
-    Py_INCREF_MORTAL(obj);
+    _Py_INCREF_MORTAL(obj);
     _PyStackRef ref = (_PyStackRef){ .bits = (uintptr_t)obj };
     PyStackRef_CheckValid(ref);
     return ref;
@@ -590,14 +590,14 @@ PyStackRef_FromPyObjectImmortal(PyObject *obj)
 /* WARNING: This macro evaluates its argument more than once */
 #ifdef _WIN32
 #define PyStackRef_DUP(REF) \
-    (PyStackRef_RefcountOnObject(REF) ? (Py_INCREF_MORTAL(BITS_TO_PTR(REF)), (REF)) : (REF))
+    (PyStackRef_RefcountOnObject(REF) ? (_Py_INCREF_MORTAL(BITS_TO_PTR(REF)), (REF)) : (REF))
 #else
 static inline _PyStackRef
 PyStackRef_DUP(_PyStackRef ref)
 {
     assert(!PyStackRef_IsNull(ref));
     if (PyStackRef_RefcountOnObject(ref)) {
-        Py_INCREF_MORTAL(BITS_TO_PTR(ref));
+        _Py_INCREF_MORTAL(BITS_TO_PTR(ref));
     }
     return ref;
 }
index 05f2b048dc17d2e2eeb8b2b56ece109713bb0ed3..1ecba5ee78d6858bd8edf494a98b4ee7ef09845b 100644 (file)
@@ -247,20 +247,6 @@ PyAPI_FUNC(void) Py_DecRef(PyObject *);
 PyAPI_FUNC(void) _Py_IncRef(PyObject *);
 PyAPI_FUNC(void) _Py_DecRef(PyObject *);
 
-#ifndef Py_GIL_DISABLED
-static inline Py_ALWAYS_INLINE void Py_INCREF_MORTAL(PyObject *op)
-{
-    assert(!_Py_IsStaticImmortal(op));
-    op->ob_refcnt++;
-    _Py_INCREF_STAT_INC();
-#if defined(Py_REF_DEBUG) && !defined(Py_LIMITED_API)
-    if (!_Py_IsImmortal(op)) {
-        _Py_INCREF_IncRefTotal();
-    }
-#endif
-}
-#endif
-
 static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
 {
 #if defined(Py_LIMITED_API) && (Py_LIMITED_API+0 >= 0x030c0000 || defined(Py_REF_DEBUG))