aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Include/boolobject.h
diff options
context:
space:
mode:
Diffstat (limited to 'Include/boolobject.h')
-rw-r--r--Include/boolobject.h13
1 files changed, 10 insertions, 3 deletions
diff --git a/Include/boolobject.h b/Include/boolobject.h
index 3037e61bbf6..b56e2baecaa 100644
--- a/Include/boolobject.h
+++ b/Include/boolobject.h
@@ -34,9 +34,16 @@ PyAPI_FUNC(int) Py_IsTrue(PyObject *x);
PyAPI_FUNC(int) Py_IsFalse(PyObject *x);
#define Py_IsFalse(x) Py_Is((x), Py_False)
-/* Macros for returning Py_True or Py_False, respectively */
-#define Py_RETURN_TRUE return Py_True
-#define Py_RETURN_FALSE return Py_False
+/* Macros for returning Py_True or Py_False, respectively.
+ * Only treat Py_True and Py_False as immortal in the limited C API 3.12
+ * and newer. */
+#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030c0000
+# define Py_RETURN_TRUE return Py_NewRef(Py_True)
+# define Py_RETURN_FALSE return Py_NewRef(Py_False)
+#else
+# define Py_RETURN_TRUE return Py_True
+# define Py_RETURN_FALSE return Py_False
+#endif
/* Function to return a bool from a C long */
PyAPI_FUNC(PyObject *) PyBool_FromLong(long);