Skip to content

Commit bc83e33

Browse files
committed
debug
1 parent 392976f commit bc83e33

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/PIL/ImageTk.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,15 @@ def _pyimagingtkcall(
5151
command: str, photo: PhotoImage | tkinter.PhotoImage, ptr: object
5252
) -> None:
5353
tk = photo.tk
54-
ptr_str = repr(ptr).strip("<>")
5554
try:
56-
tk.call(command, photo, ptr_str)
55+
tk.call(command, photo, repr(ptr))
5756
except tkinter.TclError:
5857
# activate Tkinter hook
5958
# may raise an error if it cannot attach to Tkinter
6059
from . import _imagingtk
6160

6261
_imagingtk.tkinit(tk.interpaddr())
63-
tk.call(command, photo, ptr_str)
62+
tk.call(command, photo, repr(ptr))
6463

6564

6665
# --------------------------------------------------------------------

src/Tk/tkImaging.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,27 @@ static Tk_PhotoPutBlock_t TK_PHOTO_PUT_BLOCK;
5757
static Imaging
5858
ImagingFind(const char *name) {
5959
PyObject *capsule;
60+
int direct_pointer = 0;
6061
const char *expected = "capsule object \"" IMAGING_MAGIC "\" at 0x";
6162

63+
if (name[0] == '<') {
64+
name++;
65+
} else {
66+
// Special case for pypy, where string representation of Capsule reffers
67+
// to the pointer itself, not to PyCapsule object.
68+
direct_pointer = 1;
69+
}
70+
6271
if (strncmp(name, expected, strlen(expected))) {
6372
return NULL;
6473
}
6574

6675
capsule = (PyObject *)strtoull(name + strlen(expected), NULL, 16);
6776

77+
if (direct_pointer) {
78+
return (Imaging)capsule;
79+
}
80+
6881
if (!PyCapsule_IsValid(capsule, IMAGING_MAGIC)) {
6982
PyErr_Format(
7083
PyExc_TypeError, "Expected PyCapsule with '%s' name.", IMAGING_MAGIC

0 commit comments

Comments
 (0)