Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a6cbf32

Browse filesBrowse files
ksundenanntzer
andcommitted
Use both TCL_SETVAR and TCL_SETVAR2 for tcl 9 support
Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
1 parent c740fc8 commit a6cbf32
Copy full SHA for a6cbf32

File tree

Expand file treeCollapse file tree

2 files changed

+19
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+19
-4
lines changed

‎src/_tkagg.cpp

Copy file name to clipboardExpand all lines: src/_tkagg.cpp
+16-4Lines changed: 16 additions & 4 deletions
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 and 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

Copy file name to clipboardExpand all lines: src/_tkmini.h
+3Lines changed: 3 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.