Skip to content

Commit 183b04f

Browse files
authored
Merge pull request #29144 from ksunden/tcl9
2 parents c740fc8 + a6a442d commit 183b04f

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/_tkagg.cpp

+16-4
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ static Tk_PhotoPutBlock_t TK_PHOTO_PUT_BLOCK;
9292
// Global vars for Tcl functions. We load these symbols from the tkinter
9393
// extension module or loaded Tcl libraries at run-time.
9494
static Tcl_SetVar_t TCL_SETVAR;
95+
static Tcl_SetVar2_t TCL_SETVAR2;
9596

9697
static void
9798
mpl_tk_blit(py::object interp_obj, const char *photo_name,
@@ -173,7 +174,15 @@ DpiSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
173174
std::string dpi = std::to_string(LOWORD(wParam));
174175

175176
Tcl_Interp* interp = (Tcl_Interp*)dwRefData;
176-
TCL_SETVAR(interp, var_name.c_str(), dpi.c_str(), 0);
177+
if (TCL_SETVAR) {
178+
TCL_SETVAR(interp, var_name.c_str(), dpi.c_str(), 0);
179+
} else if (TCL_SETVAR2) {
180+
TCL_SETVAR2(interp, var_name.c_str(), NULL, dpi.c_str(), 0);
181+
} else {
182+
// This should be prevented at import time, and therefore unreachable.
183+
// But defensively throw just in case.
184+
throw std::runtime_error("Unable to call Tcl_SetVar or Tcl_SetVar2");
185+
}
177186
}
178187
return 0;
179188
case WM_NCDESTROY:
@@ -246,13 +255,16 @@ bool load_tcl_tk(T lib)
246255
if (auto ptr = dlsym(lib, "Tcl_SetVar")) {
247256
TCL_SETVAR = (Tcl_SetVar_t)ptr;
248257
}
258+
if (auto ptr = dlsym(lib, "Tcl_SetVar2")) {
259+
TCL_SETVAR2 = (Tcl_SetVar2_t)ptr;
260+
}
249261
if (auto ptr = dlsym(lib, "Tk_FindPhoto")) {
250262
TK_FIND_PHOTO = (Tk_FindPhoto_t)ptr;
251263
}
252264
if (auto ptr = dlsym(lib, "Tk_PhotoPutBlock")) {
253265
TK_PHOTO_PUT_BLOCK = (Tk_PhotoPutBlock_t)ptr;
254266
}
255-
return TCL_SETVAR && TK_FIND_PHOTO && TK_PHOTO_PUT_BLOCK;
267+
return (TCL_SETVAR || TCL_SETVAR2) && TK_FIND_PHOTO && TK_PHOTO_PUT_BLOCK;
256268
}
257269

258270
#ifdef WIN32_DLL
@@ -343,8 +355,8 @@ PYBIND11_MODULE(_tkagg, m, py::mod_gil_not_used())
343355
throw py::error_already_set();
344356
}
345357

346-
if (!TCL_SETVAR) {
347-
throw py::import_error("Failed to load Tcl_SetVar");
358+
if (!(TCL_SETVAR || TCL_SETVAR2)) {
359+
throw py::import_error("Failed to load Tcl_SetVar or Tcl_SetVar2");
348360
} else if (!TK_FIND_PHOTO) {
349361
throw py::import_error("Failed to load Tk_FindPhoto");
350362
} else if (!TK_PHOTO_PUT_BLOCK) {

src/_tkmini.h

+3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ typedef int (*Tk_PhotoPutBlock_t) (Tcl_Interp *interp, Tk_PhotoHandle handle,
104104
/* Tcl_SetVar typedef */
105105
typedef const char *(*Tcl_SetVar_t)(Tcl_Interp *interp, const char *varName,
106106
const char *newValue, int flags);
107+
/* Tcl_SetVar2 typedef */
108+
typedef const char *(*Tcl_SetVar2_t)(Tcl_Interp *interp, const char *part1, const char *part2,
109+
const char *newValue, int flags);
107110

108111
#ifdef __cplusplus
109112
}

0 commit comments

Comments
 (0)