-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Use ImagingCore.ptr instead of ImagingCore.id #8341
base: main
Are you sure you want to change the base?
Conversation
1fddcce
to
9bd6434
Compare
PytestUnraisableExceptionWarning: Exception ignored in: <function PhotoImage.__del__> AttributeError: 'PhotoImage' object has no attribute '_PhotoImage__photo'
830a245
to
491e637
Compare
@python-pillow/pillow-team I need help here) Could anyone debug pypy3.10 on windows? I can't get what's wrong, since as I can see, the capsule object is correctly restored from the pointer and the capsule object itself is alive. |
10db853
to
bc83e33
Compare
Get it! In pypy https://github.com/pypy/pypy/blob/branches/py3.10/pypy/objspace/std/capsuleobject.py#L39 |
So is the motivation here just to simplify the code? Also, we don't necessarily need the deprecations - #4532 (comment)
|
Added description to PR.
While |
PytestUnraisableExceptionWarning: Exception ignored in: <function PhotoImage.__del__> AttributeError: 'PhotoImage' object has no attribute '_PhotoImage__photo'
Use CapsuleType hint in Python >= 3.13
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
@@ -349,19 +349,17 @@ def point(self, im: Image.Image) -> Image.Image: | |||
return self.apply(im) | |||
|
|||
def apply(self, im: Image.Image, imOut: Image.Image | None = None) -> Image.Image: | |||
im.load() | |||
if imOut is None: | |||
imOut = Image.new(self.output_mode, im.size, None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imOut = Image.new(self.output_mode, im.size, None) | |
im.load() | |
imOut = Image.new(self.output_mode, im.size, None) |
This call can still make a difference - it is possible for the size of an image to change after it loads.
from PIL import Image
im = Image.open("Tests/images/g4_orientation_5.tif")
print(im.size) # (88, 590)
im.load()
print(im.size) # (590, 88)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is possible for the size of an image to change after it loads
I'm considering this as bug and have patched it in our production brunch: uploadcare@1d77bfe
Do you want I made a PR for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A separate PR would be good, rather than including it here, yeah, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it is: #8387
Partially suppress #8340
The non-primary extensions in Pillow don't have direct access to Python's
_imaging
types, such asImaging_Type
andImagingObject
. However, they often still need to interact with objects passed from Python code. Currently, the raw memory pointer to anImaging
object (ImageCore.id
) is passed as an integer and then cast to a memory pointer:It's not safe and can lead to segmentation faults. Python has Capsule objects, which provide a safer way to pass pointers to C code. These are exposed through
ImageCore.ptr
.This PR deprecates the raw pointer properties
ImageCore.id
andImageCore.unsafe_ptrs
, and migrates non-primary extensions to interact with Capsule objects.