File tree Expand file tree Collapse file tree 3 files changed +20
-5
lines changed Expand file tree Collapse file tree 3 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -34,9 +34,16 @@ PyAPI_FUNC(int) Py_IsTrue(PyObject *x);
34
34
PyAPI_FUNC (int ) Py_IsFalse (PyObject * x );
35
35
#define Py_IsFalse (x ) Py_Is((x), Py_False)
36
36
37
- /* Macros for returning Py_True or Py_False, respectively */
38
- #define Py_RETURN_TRUE return Py_True
39
- #define Py_RETURN_FALSE return Py_False
37
+ /* Macros for returning Py_True or Py_False, respectively.
38
+ * Only treat Py_True and Py_False as immortal in the limited C API 3.12
39
+ * and newer. */
40
+ #if defined(Py_LIMITED_API ) && Py_LIMITED_API + 0 < 0x030c0000
41
+ # define Py_RETURN_TRUE return Py_NewRef(Py_True)
42
+ # define Py_RETURN_FALSE return Py_NewRef(Py_False)
43
+ #else
44
+ # define Py_RETURN_TRUE return Py_True
45
+ # define Py_RETURN_FALSE return Py_False
46
+ #endif
40
47
41
48
/* Function to return a bool from a C long */
42
49
PyAPI_FUNC (PyObject * ) PyBool_FromLong (long );
Original file line number Diff line number Diff line change @@ -654,8 +654,13 @@ PyAPI_DATA(PyObject) _Py_NoneStruct; /* Don't use this directly */
654
654
PyAPI_FUNC (int ) Py_IsNone (PyObject * x );
655
655
#define Py_IsNone (x ) Py_Is((x), Py_None)
656
656
657
- /* Macro for returning Py_None from a function */
658
- #define Py_RETURN_NONE return Py_None
657
+ /* Macro for returning Py_None from a function.
658
+ * Only treat Py_None as immortal in the limited C API 3.12 and newer. */
659
+ #if defined(Py_LIMITED_API ) && Py_LIMITED_API + 0 < 0x030c0000
660
+ # define Py_RETURN_NONE return Py_NewRef(Py_None)
661
+ #else
662
+ # define Py_RETURN_NONE return Py_None
663
+ #endif
659
664
660
665
/*
661
666
Py_NotImplemented is a singleton used to signal that an operation is
Original file line number Diff line number Diff line change
1
+ Fix ``Py_RETURN_NONE ``, ``Py_RETURN_TRUE `` and ``Py_RETURN_FALSE `` macros in
2
+ the limited C API 3.11 and older: don't treat ``Py_None ``, ``Py_True `` and
3
+ ``Py_False `` as immortal. Patch by Victor Stinner.
You can’t perform that action at this time.
Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!
Check out: eBank.nz (Art Generator) |
Netwrck.com (AI Tools) |
Text-Generator.io (AI API) |
BitBank.nz (Crypto AI) |
ReadingTime (Kids Reading) |
RewordGame |
BigMultiplayerChess |
WebFiddle |
How.nz |
Helix AI Assistant
0 commit comments