]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-140487: Fix Py_RETURN_NOTIMPLEMENTED in limited C API 3.11 (GH-140636)...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 27 Oct 2025 13:15:49 +0000 (14:15 +0100)
committerGitHub <noreply@github.com>
Mon, 27 Oct 2025 13:15:49 +0000 (14:15 +0100)
gh-140487: Fix Py_RETURN_NOTIMPLEMENTED in limited C API 3.11 (GH-140636)

Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE have already been
fixed by commit 9258f3da9175134d03f2c8c7c7eed223802ad945 (issue gh-134989).
(cherry picked from commit c6364775236e3c634c3393c7f50fece50611245f)

Co-authored-by: Victor Stinner <vstinner@python.org>
Include/object.h
Misc/NEWS.d/next/C_API/2025-10-26-16-45-06.gh-issue-140487.fGOqss.rst [new file with mode: 0644]

index 9901815bd646049de874b78e5c1e69408173026b..4d577d0e32d791c55b010e025ac76c7e8e4c3711 100644 (file)
@@ -674,8 +674,13 @@ PyAPI_DATA(PyObject) _Py_NotImplementedStruct; /* Don't use this directly */
 #  define Py_NotImplemented (&_Py_NotImplementedStruct)
 #endif
 
-/* Macro for returning Py_NotImplemented from a function */
-#define Py_RETURN_NOTIMPLEMENTED return Py_NotImplemented
+/* Macro for returning Py_NotImplemented from a function. Only treat
+ * Py_NotImplemented as immortal in the limited C API 3.12 and newer. */
+#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030c0000
+#  define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
+#else
+#  define Py_RETURN_NOTIMPLEMENTED return Py_NotImplemented
+#endif
 
 /* Rich comparison opcodes */
 #define Py_LT 0
diff --git a/Misc/NEWS.d/next/C_API/2025-10-26-16-45-06.gh-issue-140487.fGOqss.rst b/Misc/NEWS.d/next/C_API/2025-10-26-16-45-06.gh-issue-140487.fGOqss.rst
new file mode 100644 (file)
index 0000000..16b0d9d
--- /dev/null
@@ -0,0 +1,2 @@
+Fix :c:macro:`Py_RETURN_NOTIMPLEMENTED` in limited C API 3.11 and older:
+don't treat ``Py_NotImplemented`` as immortal. Patch by Victor Stinner.