Skip to content

Commit

Permalink
Make TkCygwinMainEx() work when Tk 8.7 is compiled against Tcl 9.0 (c…
Browse files Browse the repository at this point in the history
…ygwin-only change)

Make Tk_MainEx() TCL_NORETURN1, since it never returns
  • Loading branch information
jan.nijtmans committed Apr 29, 2024
2 parents 3c8ae9a + d5378b9 commit a0c6d54
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
6 changes: 3 additions & 3 deletions generic/tk.decls
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ declare 211 {
Tk_OptionTable optionToken, Tk_Window tkwin)
}
declare 212 {nostub {Don't use this function in a stub-enabled extension}} {
void Tk_MainEx(Tcl_Size argc, char **argv, Tcl_AppInitProc *appInitProc,
TCL_NORETURN1 void Tk_MainEx(Tcl_Size argc, char **argv, Tcl_AppInitProc *appInitProc,
Tcl_Interp *interp)
}
declare 213 {
Expand Down Expand Up @@ -1216,11 +1216,11 @@ export {
int exact)
}
export {
void Tk_MainEx(Tcl_Size argc, char **argv, Tcl_AppInitProc *appInitProc,
TCL_NORETURN1 void Tk_MainEx(Tcl_Size argc, char **argv, Tcl_AppInitProc *appInitProc,
Tcl_Interp *interp)
}
export {
void Tk_MainExW(Tcl_Size argc, wchar_t **argv,
TCL_NORETURN1 void Tk_MainExW(Tcl_Size argc, wchar_t **argv,
Tcl_AppInitProc *appInitProc, Tcl_Interp *interp);
}

Expand Down
2 changes: 1 addition & 1 deletion generic/tkConfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -2176,7 +2176,7 @@ GetObjectForOption(
objPtr = Tcl_NewStringObj(*((char **)internalPtr), TCL_INDEX_NONE);
break;
case TK_OPTION_STRING_TABLE: {
int value;
int value = 0;
if (optionPtr->specPtr->flags & TYPE_MASK) {
if ((optionPtr->specPtr->flags & TYPE_MASK) == TK_OPTION_VAR(char)) {
value = *((signed char *)internalPtr);
Expand Down
4 changes: 2 additions & 2 deletions generic/tkDecls.h
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ EXTERN int Tk_GetScrollInfoObj(Tcl_Interp *interp,
EXTERN int Tk_InitOptions(Tcl_Interp *interp, void *recordPtr,
Tk_OptionTable optionToken, Tk_Window tkwin);
/* 212 */
EXTERN void Tk_MainEx(Tcl_Size argc, char **argv,
EXTERN TCL_NORETURN1 void Tk_MainEx(Tcl_Size argc, char **argv,
Tcl_AppInitProc *appInitProc,
Tcl_Interp *interp);
/* 213 */
Expand Down Expand Up @@ -1149,7 +1149,7 @@ typedef struct TkStubs {
int (*tk_GetReliefFromObj) (Tcl_Interp *interp, Tcl_Obj *objPtr, int *resultPtr); /* 209 */
int (*tk_GetScrollInfoObj) (Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[], double *dblPtr, int *intPtr); /* 210 */
int (*tk_InitOptions) (Tcl_Interp *interp, void *recordPtr, Tk_OptionTable optionToken, Tk_Window tkwin); /* 211 */
TCL_DEPRECATED_API("Don't use this function in a stub-enabled extension") void (*tk_MainEx) (Tcl_Size argc, char **argv, Tcl_AppInitProc *appInitProc, Tcl_Interp *interp); /* 212 */
TCL_DEPRECATED_API("Don't use this function in a stub-enabled extension") TCL_NORETURN1 void (*tk_MainEx) (Tcl_Size argc, char **argv, Tcl_AppInitProc *appInitProc, Tcl_Interp *interp); /* 212 */
void (*tk_RestoreSavedOptions) (Tk_SavedOptions *savePtr); /* 213 */
int (*tk_SetOptions) (Tcl_Interp *interp, void *recordPtr, Tk_OptionTable optionTable, Tcl_Size objc, Tcl_Obj *const objv[], Tk_Window tkwin, Tk_SavedOptions *savePtr, int *maskPtr); /* 214 */
void (*tk_InitConsoleChannels) (Tcl_Interp *interp); /* 215 */
Expand Down
12 changes: 6 additions & 6 deletions generic/tkMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

#include "tkInt.h"

extern int TkCygwinMainEx(Tcl_Size, char **, Tcl_AppInitProc *, Tcl_Interp *);
#if defined(_WIN32) && !defined(UNICODE) && !defined(STATIC_BUILD)
MODULE_SCOPE void TkCygwinMainEx(Tcl_Size, char **, Tcl_AppInitProc *, Tcl_Interp *);
#endif

/*
* The default prompt used when the user has not overridden it.
Expand Down Expand Up @@ -161,7 +163,7 @@ static void StdinProc(void *clientData, int mask);
*----------------------------------------------------------------------
*/

void
TCL_NORETURN1 void
Tk_MainEx(
Tcl_Size argc, /* Number of arguments. */
TCHAR **argv, /* Array of argument strings. */
Expand Down Expand Up @@ -204,10 +206,8 @@ Tk_MainEx(
* Tk_MainEx function of libtk8.?.dll, not this one. */
if (Tcl_GetVar2(interp, "env", "DISPLAY", TCL_GLOBAL_ONLY)) {
loadCygwinTk:
if (TkCygwinMainEx(argc, argv, appInitProc, interp)) {
/* Should never reach here. */
return;
}
TkCygwinMainEx(argc, argv, appInitProc, interp);
/* Only returns when Tk_MainEx() was not found */
} else {
Tcl_Size j;

Expand Down
25 changes: 12 additions & 13 deletions generic/tkWindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -2943,7 +2943,7 @@ DeleteWindowsExitProc(
tsdPtr->initialized = 0;
}

#if defined(_WIN32)
#if defined(_WIN32) && !defined(STATIC_BUILD)

static HMODULE tkcygwindll = NULL;

Expand All @@ -2954,9 +2954,8 @@ static HMODULE tkcygwindll = NULL;
* This means that the system encoding is utf-8, so we don't have to do any
* encoding conversions.
*/
extern int TkCygwinMainEx(Tcl_Size, char **, Tcl_AppInitProc *, Tcl_Interp *);

int
MODULE_SCOPE void
TkCygwinMainEx(
Tcl_Size argc, /* Number of arguments. */
char **argv, /* Array of argument strings. */
Expand All @@ -2975,20 +2974,20 @@ TkCygwinMainEx(
name[len-2] = '.';
name[len-1] = name[len-5];
wcscpy(name+len, L".dll");
#if TCL_MAJOR_VERSION > 8
memcpy(name+len-12, L"libtcl9tk8", 10 * sizeof(WCHAR));
#else
memcpy(name+len-8, L"libtk8", 6 * sizeof(WCHAR));
#endif

tkcygwindll = LoadLibraryW(name);
if (!tkcygwindll) {
/* dll is not present */
return 0;
}
tkmainex = (void (*)(Tcl_Size, char **, Tcl_AppInitProc *, Tcl_Interp *))
(void *)GetProcAddress(tkcygwindll, "Tk_MainEx");
if (!tkmainex) {
return 0;
if (tkcygwindll) {
tkmainex = (void (*)(Tcl_Size, char **, Tcl_AppInitProc *, Tcl_Interp *))
(void *)GetProcAddress(tkcygwindll, "Tk_MainEx");
if (tkmainex) {
tkmainex(argc, argv, appInitProc, interp);
}
}
tkmainex(argc, argv, appInitProc, interp);
return 1;
}
#endif /* _WIN32 */

Expand Down

0 comments on commit a0c6d54

Please sign in to comment.