From 38fd40a0cacdd90b2f5faba096f69fe2b8e420fa Mon Sep 17 00:00:00 2001 From: Yay295 Date: Wed, 5 Jul 2023 08:33:46 -0500 Subject: [PATCH] use Py_RETURN_* macros for Py_True/Py_False Py_True and Py_False were only made immortal in Python 3.12, so we have to properly increment their refcount for versions before that. --- src/_imaging.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/_imaging.c b/src/_imaging.c index e1284501d..f7f8b64c4 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -3862,7 +3862,11 @@ image_richcompare(const ImagingObject *self, const PyObject *other, const int op // If the other object is not an ImagingObject. if (!PyImaging_Check(other)) { - return op == Py_EQ ? Py_False : Py_True; + if (op == Py_EQ) { + Py_RETURN_FALSE; + } else { + Py_RETURN_TRUE; + } } const Imaging img_a = self->image; @@ -3881,7 +3885,11 @@ image_richcompare(const ImagingObject *self, const PyObject *other, const int op || img_a->xsize != img_b->xsize || img_a->ysize != img_b->ysize ) { - return op == Py_EQ ? Py_False : Py_True; + if (op == Py_EQ) { + Py_RETURN_FALSE; + } else { + Py_RETURN_TRUE; + } } const ImagingPalette palette_a = img_a->palette; @@ -3911,7 +3919,11 @@ image_richcompare(const ImagingObject *self, const PyObject *other, const int op palette_b_data_ptr ) ) { - return op == Py_EQ ? Py_False : Py_True; + if (op == Py_EQ) { + Py_RETURN_FALSE; + } else { + Py_RETURN_TRUE; + } } } @@ -3930,11 +3942,17 @@ image_richcompare(const ImagingObject *self, const PyObject *other, const int op (const UINT8 **)img_b->image ) ) { - PyErr_Clear(); - return op == Py_EQ ? Py_False : Py_True; + if (op == Py_EQ) { + Py_RETURN_FALSE; + } else { + Py_RETURN_TRUE; + } } else { - PyErr_Clear(); - return op == Py_EQ ? Py_True : Py_False; + if (op == Py_EQ) { + Py_RETURN_TRUE; + } else { + Py_RETURN_FALSE; + } } }