Skip to content

Commit 9c72a6d

Browse files
authored
Merge pull request #6549 from radarhere/interp
2 parents ad7be55 + 7b0e56b commit 9c72a6d

2 files changed

Lines changed: 12 additions & 32 deletions

File tree

src/PIL/ImageTk.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,18 @@ def _pyimagingtkcall(command, photo, id):
6868
# may raise an error if it cannot attach to Tkinter
6969
from . import _imagingtk
7070

71-
try:
72-
if hasattr(tk, "interp"):
73-
# Required for PyPy, which always has CFFI installed
74-
from cffi import FFI
71+
if hasattr(tk, "interp"):
72+
# Required for PyPy, which always has CFFI installed
73+
from cffi import FFI
7574

76-
ffi = FFI()
75+
ffi = FFI()
7776

78-
# PyPy is using an FFI CDATA element
79-
# (Pdb) self.tk.interp
80-
# <cdata 'Tcl_Interp *' 0x3061b50>
81-
_imagingtk.tkinit(int(ffi.cast("uintptr_t", tk.interp)), 1)
82-
else:
83-
_imagingtk.tkinit(tk.interpaddr(), 1)
84-
except AttributeError:
85-
_imagingtk.tkinit(id(tk), 0)
77+
# PyPy is using an FFI CDATA element
78+
# (Pdb) self.tk.interp
79+
# <cdata 'Tcl_Interp *' 0x3061b50>
80+
_imagingtk.tkinit(int(ffi.cast("uintptr_t", tk.interp)))
81+
else:
82+
_imagingtk.tkinit(tk.interpaddr())
8683
tk.call(command, photo, id)
8784

8885

src/_imagingtk.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,16 @@ TkImaging_Init(Tcl_Interp *interp);
2323
extern int
2424
load_tkinter_funcs(void);
2525

26-
/* copied from _tkinter.c (this isn't as bad as it may seem: for new
27-
versions, we use _tkinter's interpaddr hook instead, and all older
28-
versions use this structure layout) */
29-
30-
typedef struct {
31-
PyObject_HEAD Tcl_Interp *interp;
32-
} TkappObject;
33-
3426
static PyObject *
3527
_tkinit(PyObject *self, PyObject *args) {
3628
Tcl_Interp *interp;
3729

3830
PyObject *arg;
39-
int is_interp;
40-
if (!PyArg_ParseTuple(args, "Oi", &arg, &is_interp)) {
31+
if (!PyArg_ParseTuple(args, "O", &arg)) {
4132
return NULL;
4233
}
4334

44-
if (is_interp) {
45-
interp = (Tcl_Interp *)PyLong_AsVoidPtr(arg);
46-
} else {
47-
TkappObject *app;
48-
/* Do it the hard way. This will break if the TkappObject
49-
layout changes */
50-
app = (TkappObject *)PyLong_AsVoidPtr(arg);
51-
interp = app->interp;
52-
}
35+
interp = (Tcl_Interp *)PyLong_AsVoidPtr(arg);
5336

5437
/* This will bomb if interp is invalid... */
5538
TkImaging_Init(interp);

0 commit comments

Comments
 (0)