Skip to content

geometry: clean up imOut if operation fails#9785

Open
akx wants to merge 2 commits into
python-pillow:mainfrom
akx:geometry-cleanup
Open

geometry: clean up imOut if operation fails#9785
akx wants to merge 2 commits into
python-pillow:mainfrom
akx:geometry-cleanup

Conversation

@akx

@akx akx commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Sibling of #9784 - an earlier iteration of it uncovered Python complaining about a value being returned while an exception was set. _transpose did indeed just wholesale toss out the retval of the underlying operation function...

@akx akx marked this pull request as ready for review July 9, 2026 09:19
@radarhere

Copy link
Copy Markdown
Member

I understand completely that you dislike that the return value is ignored.

However, the return value only indicates failure if the modes or the sizes don't match, and _transpose creates imOut from those aspects of imIn, and ImagingBoxBlur (the only other places one of these functions is called from) does almost the same. It seems to me that there is no way that the return value would ever be a failure.

Is it worth considering the alternative solution of removing the mode and size checks from ImagingFlipLeftRight through to ImagingTransverse, so that there is no return value at all, and documenting this in a comment?

@akx

akx commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

It seems to me that there is no way that the return value would ever be a failure.

As noted, an earlier iteration of #9784 had an issue where I'd carelessly copy-pasted all checks across Geometry.c the same, even though some of the functions actually needed to check whether imIn's size is the transposition of imOut's size, not the same size.

That in turn caused CPython RuntimeErrors because we were both returning a value from a C extension function while having set an exception, because this function wasn't checking correctly... If this function had behaved correctly CPython-API-wise, I would've spent less time debugging that exception, and more time figuring I was a dummy for copy-pasting blindly :)

Given, as you note, that the Imaging* functions are libImaging internal APIs that are used by other functions, I'd want them to have the same checks that other libImaging functions do.

Comment thread src/_imaging.c Outdated
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants