Skip to content

Commit ce1deb9

Browse files
[3.14] gh-140487: Fix Py_RETURN_NOTIMPLEMENTED in limited C API 3.11 (GH-140636) (#140668)
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 9258f3d (issue gh-134989). (cherry picked from commit c636477) Co-authored-by: Victor Stinner <[email protected]>
1 parent 87afee2 commit ce1deb9

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Include/object.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,13 @@ PyAPI_DATA(PyObject) _Py_NotImplementedStruct; /* Don't use this directly */
674674
# define Py_NotImplemented (&_Py_NotImplementedStruct)
675675
#endif
676676

677-
/* Macro for returning Py_NotImplemented from a function */
678-
#define Py_RETURN_NOTIMPLEMENTED return Py_NotImplemented
677+
/* Macro for returning Py_NotImplemented from a function. Only treat
678+
* Py_NotImplemented as immortal in the limited C API 3.12 and newer. */
679+
#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030c0000
680+
# define Py_RETURN_NOTIMPLEMENTED return Py_NewRef(Py_NotImplemented)
681+
#else
682+
# define Py_RETURN_NOTIMPLEMENTED return Py_NotImplemented
683+
#endif
679684

680685
/* Rich comparison opcodes */
681686
#define Py_LT 0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :c:macro:`Py_RETURN_NOTIMPLEMENTED` in limited C API 3.11 and older:
2+
don't treat ``Py_NotImplemented`` as immortal. Patch by Victor Stinner.

0 commit comments

Comments
 (0)