Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
homm committed Sep 2, 2024
1 parent 392976f commit bc83e33
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/PIL/ImageTk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


# --------------------------------------------------------------------
Expand Down
13 changes: 13 additions & 0 deletions src/Tk/tkImaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bc83e33

Please sign in to comment.