Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tp_richcompare handler for Imaging_Type/ImagingCore #7260

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
Yay295 committed Oct 12, 2024
commit 38fd40a0cacdd90b2f5faba096f69fe2b8e420fa
32 changes: 25 additions & 7 deletions src/_imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
}

Expand All @@ -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;
}
}
}

Expand Down