Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3f5407a

Browse files
committed
RF: check, edit, refactor Tcl / tk mini header
Move typedefs into Tcl / tk mini header. Rename typedefs for clarity. Strip older definition of Tcl_Interp. Check all defines compatible with Tcl / Tk 8.5 and current trunk (as of 21 May 2016).
1 parent 94bb457 commit 3f5407a

File tree

2 files changed

+77
-50
lines changed

2 files changed

+77
-50
lines changed

src/_tkagg.cpp

Lines changed: 34 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,15 @@
66
*
77
*/
88

9-
/* This is needed for (at least) Tk 8.4.1, otherwise the signature of
10-
** Tk_PhotoPutBlock changes.
11-
*/
12-
#define USE_COMPOSITELESS_PHOTO_PUT_BLOCK
13-
149
#include <Python.h>
1510
#include <cstdlib>
1611
#include <cstdio>
1712
#include <sstream>
1813

1914
#include "py_converters.h"
2015

21-
extern "C"
22-
{
16+
// Include our own excerpts from the Tcl / Tk headers
2317
#include "_tkmini.h"
24-
}
2518

2619
#if defined(_MSC_VER)
2720
# define SIZE_T_FORMAT "%Iu"
@@ -35,27 +28,17 @@ typedef struct
3528
Tcl_Interp *interp;
3629
} TkappObject;
3730

38-
// Load TCL / Tk symbols from tkinter extension module at run-time.
39-
// Typedefs, global vars for TCL / Tk library functions.
40-
typedef Tcl_Command (*tcl_cc)(Tcl_Interp *interp,
41-
const char *cmdName, Tcl_CmdProc *proc,
42-
ClientData clientData,
43-
Tcl_CmdDeleteProc *deleteProc);
44-
static tcl_cc TCL_CREATE_COMMAND;
45-
typedef void (*tcl_app_res) (Tcl_Interp *interp, ...);
46-
static tcl_app_res TCL_APPEND_RESULT;
47-
typedef Tk_Window (*tk_mw) (Tcl_Interp *interp);
48-
static tk_mw TK_MAIN_WINDOW;
49-
typedef Tk_PhotoHandle (*tk_fp) (Tcl_Interp *interp, const char *imageName);
50-
static tk_fp TK_FIND_PHOTO;
51-
typedef void (*tk_ppb_nc) (Tk_PhotoHandle handle,
52-
Tk_PhotoImageBlock *blockPtr, int x, int y,
53-
int width, int height);
54-
static tk_ppb_nc TK_PHOTO_PUTBLOCK;
55-
typedef void (*tk_pb) (Tk_PhotoHandle handle);
56-
static tk_pb TK_PHOTO_BLANK;
57-
58-
static int PyAggImagePhoto(ClientData clientdata, Tcl_Interp *interp, int argc, char **argv)
31+
// Global vars for Tcl / Tk functions. We load these symbols from the tkinter
32+
// extension module or loaded Tcl / Tk libraries at run-time.
33+
static Tcl_CreateCommand_t TCL_CREATE_COMMAND;
34+
static Tcl_AppendResult_t TCL_APPEND_RESULT;
35+
static Tk_MainWindow_t TK_MAIN_WINDOW;
36+
static Tk_FindPhoto_t TK_FIND_PHOTO;
37+
static Tk_PhotoPutBlock_NoComposite_t TK_PHOTO_PUT_BLOCK_NO_COMPOSITE;
38+
static Tk_PhotoBlank_t TK_PHOTO_BLANK;
39+
40+
static int PyAggImagePhoto(ClientData clientdata, Tcl_Interp *interp, int
41+
argc, char **argv)
5942
{
6043
Tk_PhotoHandle photo;
6144
Tk_PhotoImageBlock block;
@@ -178,7 +161,8 @@ static int PyAggImagePhoto(ClientData clientdata, Tcl_Interp *interp, int argc,
178161
block.pitch = deststride;
179162
block.pixelPtr = destbuffer;
180163

181-
TK_PHOTO_PUTBLOCK(photo, &block, destx, desty, destwidth, destheight);
164+
TK_PHOTO_PUT_BLOCK_NO_COMPOSITE(photo, &block, destx, desty,
165+
destwidth, destheight);
182166
delete[] destbuffer;
183167

184168
} else {
@@ -190,7 +174,8 @@ static int PyAggImagePhoto(ClientData clientdata, Tcl_Interp *interp, int argc,
190174
/* Clear current contents */
191175
TK_PHOTO_BLANK(photo);
192176
/* Copy opaque block to photo image, and leave the rest to TK */
193-
TK_PHOTO_PUTBLOCK(photo, &block, 0, 0, block.width, block.height);
177+
TK_PHOTO_PUT_BLOCK_NO_COMPOSITE(photo, &block, 0, 0, block.width,
178+
block.height);
194179
}
195180

196181
return TCL_OK;
@@ -279,11 +264,13 @@ int get_tcl(HMODULE hMod)
279264
// Try to fill TCL global vars with function pointers. Return 0 for no
280265
// functions found, 1 for all functions found, -1 for some but not all
281266
// functions found.
282-
TCL_CREATE_COMMAND = (tcl_cc) GetProcAddress(hMod, "Tcl_CreateCommand");
267+
TCL_CREATE_COMMAND = (Tcl_CreateCommand_t)
268+
GetProcAddress(hMod, "Tcl_CreateCommand");
283269
if (TCL_CREATE_COMMAND == NULL) { // Maybe not TCL module
284270
return 0;
285271
}
286-
TCL_APPEND_RESULT = (tcl_app_res) _dfunc(hMod, "Tcl_AppendResult");
272+
TCL_APPEND_RESULT = (Tcl_AppendResult_t) _dfunc(hMod,
273+
"Tcl_AppendResult");
287274
return (TCL_APPEND_RESULT == NULL) ? -1 : 1;
288275
}
289276

@@ -292,15 +279,18 @@ int get_tk(HMODULE hMod)
292279
// Try to fill Tk global vars with function pointers. Return 0 for no
293280
// functions found, 1 for all functions found, -1 for some but not all
294281
// functions found.
295-
TK_MAIN_WINDOW = (tk_mw) GetProcAddress(hMod, "Tk_MainWindow");
282+
TK_MAIN_WINDOW = (Tk_MainWindow_t)
283+
GetProcAddress(hMod, "Tk_MainWindow");
296284
if (TK_MAIN_WINDOW == NULL) { // Maybe not Tk module
297285
return 0;
298286
}
299-
return ( // -1 if any are NULL
300-
((TK_FIND_PHOTO = (tk_fp) _dfunc(hMod, "Tk_FindPhoto")) == NULL) ||
301-
((TK_PHOTO_PUTBLOCK = (tk_ppb_nc)
287+
return ( // -1 if any remaining symbols are NULL
288+
((TK_FIND_PHOTO = (Tk_FindPhoto_t)
289+
_dfunc(hMod, "Tk_FindPhoto")) == NULL) ||
290+
((TK_PHOTO_PUT_BLOCK_NO_COMPOSITE = (Tk_PhotoPutBlock_NoComposite_t)
302291
_dfunc(hMod, "Tk_PhotoPutBlock_NoComposite")) == NULL) ||
303-
((TK_PHOTO_BLANK = (tk_pb) _dfunc(hMod, "Tk_PhotoBlank")) == NULL))
292+
((TK_PHOTO_BLANK = (Tk_PhotoBlank_t)
293+
_dfunc(hMod, "Tk_PhotoBlank")) == NULL))
304294
? -1 : 1;
305295
}
306296

@@ -397,17 +387,17 @@ int _func_loader(void *lib)
397387
// Fill global function pointers from dynamic lib.
398388
// Return 1 if any pointer is NULL, 0 otherwise.
399389
return (
400-
((TCL_CREATE_COMMAND = (tcl_cc)
390+
((TCL_CREATE_COMMAND = (Tcl_CreateCommand_t)
401391
_dfunc(lib, "Tcl_CreateCommand")) == NULL) ||
402-
((TCL_APPEND_RESULT = (tcl_app_res)
392+
((TCL_APPEND_RESULT = (Tcl_AppendResult_t)
403393
_dfunc(lib, "Tcl_AppendResult")) == NULL) ||
404-
((TK_MAIN_WINDOW = (tk_mw)
394+
((TK_MAIN_WINDOW = (Tk_MainWindow_t)
405395
_dfunc(lib, "Tk_MainWindow")) == NULL) ||
406-
((TK_FIND_PHOTO = (tk_fp)
396+
((TK_FIND_PHOTO = (Tk_FindPhoto_t)
407397
_dfunc(lib, "Tk_FindPhoto")) == NULL) ||
408-
((TK_PHOTO_PUTBLOCK = (tk_ppb_nc)
398+
((TK_PHOTO_PUT_BLOCK_NO_COMPOSITE = (Tk_PhotoPutBlock_NoComposite_t)
409399
_dfunc(lib, "Tk_PhotoPutBlock_NoComposite")) == NULL) ||
410-
((TK_PHOTO_BLANK = (tk_pb)
400+
((TK_PHOTO_BLANK = (Tk_PhotoBlank_t)
411401
_dfunc(lib, "Tk_PhotoBlank")) == NULL));
412402
}
413403

src/_tkmini.h

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,24 @@
5757
* license
5858
*/
5959

60+
/*
61+
* Unless otherwise noted, these definitions are stable from Tcl / Tk 8.5
62+
* through Tck / Tk master as of 21 May 2016
63+
*/
64+
65+
#ifdef __cplusplus
66+
extern "C" {
67+
#endif
68+
6069
/* Tcl header excerpts */
6170
#define TCL_OK 0
6271
#define TCL_ERROR 1
6372

64-
typedef struct Tcl_Interp
65-
{
66-
char *result;
67-
void (*freeProc) (char *);
68-
int errorLine;
69-
} Tcl_Interp;
73+
/*
74+
* Users of versions of Tcl >= 8.6 encouraged to tread Tcl_Interp as an opaque
75+
* pointer. The following definition results when TCL_NO_DEPRECATED defined.
76+
*/
77+
typedef struct Tcl_Interp Tcl_Interp;
7078

7179
typedef struct Tcl_Command_ *Tcl_Command;
7280
typedef void *ClientData;
@@ -75,6 +83,15 @@ typedef int (Tcl_CmdProc) (ClientData clientData, Tcl_Interp
7583
*interp, int argc, const char *argv[]);
7684
typedef void (Tcl_CmdDeleteProc) (ClientData clientData);
7785

86+
/* Typedefs derived from function signatures in Tcl header */
87+
/* Tcl_CreateCommand */
88+
typedef Tcl_Command (*Tcl_CreateCommand_t)(Tcl_Interp *interp,
89+
const char *cmdName, Tcl_CmdProc *proc,
90+
ClientData clientData,
91+
Tcl_CmdDeleteProc *deleteProc);
92+
/* Tcl_AppendResult */
93+
typedef void (*Tcl_AppendResult_t) (Tcl_Interp *interp, ...);
94+
7895
/* Tk header excerpts */
7996
typedef struct Tk_Window_ *Tk_Window;
8097

@@ -89,3 +106,23 @@ typedef struct Tk_PhotoImageBlock
89106
int pixelSize;
90107
int offset[4];
91108
} Tk_PhotoImageBlock;
109+
110+
/* Typedefs derived from function signatures in Tk header */
111+
/* Tk_MainWindow */
112+
typedef Tk_Window (*Tk_MainWindow_t) (Tcl_Interp *interp);
113+
typedef Tk_PhotoHandle (*Tk_FindPhoto_t) (Tcl_Interp *interp, const char
114+
*imageName);
115+
/* Tk_PhotoPutBLock_NoComposite typedef */
116+
typedef void (*Tk_PhotoPutBlock_NoComposite_t) (Tk_PhotoHandle handle,
117+
Tk_PhotoImageBlock *blockPtr, int x, int y,
118+
int width, int height);
119+
/* Tk_PhotoBlank */
120+
typedef void (*Tk_PhotoBlank_t) (Tk_PhotoHandle handle);
121+
122+
/*
123+
* end block for C++
124+
*/
125+
126+
#ifdef __cplusplus
127+
}
128+
#endif

0 commit comments

Comments
 (0)