From bc83e33b49571942bc6549be0b7ca7096fcb0542 Mon Sep 17 00:00:00 2001 From: Aleksandr Karpinskii Date: Mon, 2 Sep 2024 12:48:31 +0400 Subject: [PATCH] debug --- src/PIL/ImageTk.py | 5 ++--- src/Tk/tkImaging.c | 13 +++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/PIL/ImageTk.py b/src/PIL/ImageTk.py index e51eeff6a36..279a21716b2 100644 --- a/src/PIL/ImageTk.py +++ b/src/PIL/ImageTk.py @@ -51,16 +51,15 @@ def _pyimagingtkcall( command: str, photo: PhotoImage | tkinter.PhotoImage, ptr: object ) -> None: tk = photo.tk - ptr_str = repr(ptr).strip("<>") try: - tk.call(command, photo, ptr_str) + tk.call(command, photo, repr(ptr)) except tkinter.TclError: # activate Tkinter hook # may raise an error if it cannot attach to Tkinter from . import _imagingtk _imagingtk.tkinit(tk.interpaddr()) - tk.call(command, photo, ptr_str) + tk.call(command, photo, repr(ptr)) # -------------------------------------------------------------------- diff --git a/src/Tk/tkImaging.c b/src/Tk/tkImaging.c index 9c0acdf0875..3b95963caec 100644 --- a/src/Tk/tkImaging.c +++ b/src/Tk/tkImaging.c @@ -57,14 +57,27 @@ static Tk_PhotoPutBlock_t TK_PHOTO_PUT_BLOCK; static Imaging ImagingFind(const char *name) { PyObject *capsule; + int direct_pointer = 0; const char *expected = "capsule object \"" IMAGING_MAGIC "\" at 0x"; + if (name[0] == '<') { + name++; + } else { + // Special case for pypy, where string representation of Capsule reffers + // to the pointer itself, not to PyCapsule object. + direct_pointer = 1; + } + if (strncmp(name, expected, strlen(expected))) { return NULL; } capsule = (PyObject *)strtoull(name + strlen(expected), NULL, 16); + if (direct_pointer) { + return (Imaging)capsule; + } + if (!PyCapsule_IsValid(capsule, IMAGING_MAGIC)) { PyErr_Format( PyExc_TypeError, "Expected PyCapsule with '%s' name.", IMAGING_MAGIC