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.
This commit is contained in:
Yay295 2023-07-05 08:33:46 -05:00
parent a09b45c5db
commit 38fd40a0ca

View File

@ -3862,7 +3862,11 @@ image_richcompare(const ImagingObject *self, const PyObject *other, const int op
// If the other object is not an ImagingObject. // If the other object is not an ImagingObject.
if (!PyImaging_Check(other)) { 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; 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->xsize != img_b->xsize
|| img_a->ysize != img_b->ysize || 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; 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 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 (const UINT8 **)img_b->image
) )
) { ) {
PyErr_Clear(); if (op == Py_EQ) {
return op == Py_EQ ? Py_False : Py_True; Py_RETURN_FALSE;
} else {
Py_RETURN_TRUE;
}
} else { } else {
PyErr_Clear(); if (op == Py_EQ) {
return op == Py_EQ ? Py_True : Py_False; Py_RETURN_TRUE;
} else {
Py_RETURN_FALSE;
}
} }
} }