From 15bcec02d97d8789fa796cabdc76859618f22387 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 17 Apr 2012 21:12:16 +0000 Subject: make loading of tk.dll in cygwin possible reduce command table size --- generic/tkWindow.c | 127 ++++++++++++++++++++++++++--------------------------- unix/Makefile.in | 11 ++++- 2 files changed, 71 insertions(+), 67 deletions(-) diff --git a/generic/tkWindow.c b/generic/tkWindow.c index 422b27e..d3de72d 100644 --- a/generic/tkWindow.c +++ b/generic/tkWindow.c @@ -69,14 +69,14 @@ TCL_DECLARE_MUTEX(windowMutex) * events on internal windows: these events are generated internally. */ -static XWindowChanges defChanges = { +static CONST XWindowChanges defChanges = { 0, 0, 1, 1, 0, 0, Above }; #define ALL_EVENTS_MASK \ KeyPressMask|KeyReleaseMask|ButtonPressMask|ButtonReleaseMask| \ EnterWindowMask|LeaveWindowMask|PointerMotionMask|ExposureMask| \ VisibilityChangeMask|PropertyChangeMask|ColormapChangeMask -static XSetWindowAttributes defAtts= { +static CONST XSetWindowAttributes defAtts= { None, /* background_pixmap */ 0, /* background_pixel */ CopyFromParent, /* border_pixmap */ @@ -99,77 +99,74 @@ static XSetWindowAttributes defAtts= { * Tk, and the C procedures that execute them. */ +#define ISSAFE 1 +#define PASSMAINWINDOW 2 + typedef struct { - char *name; /* Name of command. */ + CONST char *name; /* Name of command. */ Tcl_CmdProc *cmdProc; /* Command's string-based procedure. */ Tcl_ObjCmdProc *objProc; /* Command's object-based procedure. */ - int isSafe; /* If !0, this command will be exposed in - * a safe interpreter. Otherwise it will be - * hidden in a safe interpreter. */ - int passMainWindow; /* 0 means provide NULL clientData to - * command procedure; 1 means pass main - * window as clientData to command - * procedure. */ + int flags; } TkCmd; -static TkCmd commands[] = { +static CONST TkCmd commands[] = { /* * Commands that are part of the intrinsics: */ - {"bell", NULL, Tk_BellObjCmd, 0, 1}, - {"bind", NULL, Tk_BindObjCmd, 1, 1}, - {"bindtags", NULL, Tk_BindtagsObjCmd, 1, 1}, - {"clipboard", NULL, Tk_ClipboardObjCmd, 0, 1}, - {"destroy", NULL, Tk_DestroyObjCmd, 1, 1}, - {"event", NULL, Tk_EventObjCmd, 1, 1}, - {"focus", NULL, Tk_FocusObjCmd, 1, 1}, - {"font", NULL, Tk_FontObjCmd, 1, 1}, - {"grab", NULL, Tk_GrabObjCmd, 0, 1}, - {"grid", NULL, Tk_GridObjCmd, 1, 1}, - {"image", NULL, Tk_ImageObjCmd, 1, 1}, - {"lower", NULL, Tk_LowerObjCmd, 1, 1}, - {"option", NULL, Tk_OptionObjCmd, 1, 1}, - {"pack", NULL, Tk_PackObjCmd, 1, 1}, - {"place", NULL, Tk_PlaceObjCmd, 1, 0}, - {"raise", NULL, Tk_RaiseObjCmd, 1, 1}, - {"selection", NULL, Tk_SelectionObjCmd, 0, 1}, - {"tk", NULL, Tk_TkObjCmd, 1, 1}, - {"tkwait", NULL, Tk_TkwaitObjCmd, 1, 1}, + {"bell", NULL, Tk_BellObjCmd, PASSMAINWINDOW}, + {"bind", NULL, Tk_BindObjCmd, PASSMAINWINDOW|ISSAFE}, + {"bindtags", NULL, Tk_BindtagsObjCmd, PASSMAINWINDOW|ISSAFE}, + {"clipboard", NULL, Tk_ClipboardObjCmd, PASSMAINWINDOW}, + {"destroy", NULL, Tk_DestroyObjCmd, PASSMAINWINDOW|ISSAFE}, + {"event", NULL, Tk_EventObjCmd, PASSMAINWINDOW|ISSAFE}, + {"focus", NULL, Tk_FocusObjCmd, PASSMAINWINDOW|ISSAFE}, + {"font", NULL, Tk_FontObjCmd, PASSMAINWINDOW|ISSAFE}, + {"grab", NULL, Tk_GrabObjCmd, PASSMAINWINDOW}, + {"grid", NULL, Tk_GridObjCmd, PASSMAINWINDOW|ISSAFE}, + {"image", NULL, Tk_ImageObjCmd, PASSMAINWINDOW|ISSAFE}, + {"lower", NULL, Tk_LowerObjCmd, PASSMAINWINDOW|ISSAFE}, + {"option", NULL, Tk_OptionObjCmd, PASSMAINWINDOW|ISSAFE}, + {"pack", NULL, Tk_PackObjCmd, PASSMAINWINDOW|ISSAFE}, + {"place", NULL, Tk_PlaceObjCmd, ISSAFE}, + {"raise", NULL, Tk_RaiseObjCmd, PASSMAINWINDOW|ISSAFE}, + {"selection", NULL, Tk_SelectionObjCmd, PASSMAINWINDOW}, + {"tk", NULL, Tk_TkObjCmd, PASSMAINWINDOW|ISSAFE}, + {"tkwait", NULL, Tk_TkwaitObjCmd, PASSMAINWINDOW|ISSAFE}, #if defined(__WIN32__) || defined(MAC_TCL) || defined(MAC_OSX_TK) - {"tk_chooseColor", NULL, Tk_ChooseColorObjCmd, 0, 1}, - {"tk_chooseDirectory", NULL, Tk_ChooseDirectoryObjCmd, 0, 1}, - {"tk_getOpenFile", NULL, Tk_GetOpenFileObjCmd, 0, 1}, - {"tk_getSaveFile", NULL, Tk_GetSaveFileObjCmd, 0, 1}, + {"tk_chooseColor", NULL, Tk_ChooseColorObjCmd, PASSMAINWINDOW}, + {"tk_chooseDirectory", NULL, Tk_ChooseDirectoryObjCmd, PASSMAINWINDOW}, + {"tk_getOpenFile", NULL, Tk_GetOpenFileObjCmd, PASSMAINWINDOW}, + {"tk_getSaveFile", NULL, Tk_GetSaveFileObjCmd, PASSMAINWINDOW}, #endif #if defined(__WIN32__) || defined(MAC_OSX_TK) - {"tk_messageBox", NULL, Tk_MessageBoxObjCmd, 0, 1}, + {"tk_messageBox", NULL, Tk_MessageBoxObjCmd, PASSMAINWINDOW}, #endif - {"update", NULL, Tk_UpdateObjCmd, 1, 1}, - {"winfo", NULL, Tk_WinfoObjCmd, 1, 1}, - {"wm", NULL, Tk_WmObjCmd, 0, 1}, + {"update", NULL, Tk_UpdateObjCmd, PASSMAINWINDOW|ISSAFE}, + {"winfo", NULL, Tk_WinfoObjCmd, PASSMAINWINDOW|ISSAFE}, + {"wm", NULL, Tk_WmObjCmd, PASSMAINWINDOW}, /* * Widget class commands. */ - {"button", NULL, Tk_ButtonObjCmd, 1, 0}, - {"canvas", NULL, Tk_CanvasObjCmd, 1, 1}, - {"checkbutton", NULL, Tk_CheckbuttonObjCmd, 1, 0}, - {"entry", NULL, Tk_EntryObjCmd, 1, 0}, - {"frame", NULL, Tk_FrameObjCmd, 1, 0}, - {"label", NULL, Tk_LabelObjCmd, 1, 0}, - {"labelframe", NULL, Tk_LabelframeObjCmd, 1, 0}, - {"listbox", NULL, Tk_ListboxObjCmd, 1, 0}, - {"menubutton", NULL, Tk_MenubuttonObjCmd, 1, 0}, - {"message", NULL, Tk_MessageObjCmd, 1, 0}, - {"panedwindow", NULL, Tk_PanedWindowObjCmd, 1, 0}, - {"radiobutton", NULL, Tk_RadiobuttonObjCmd, 1, 0}, - {"scale", NULL, Tk_ScaleObjCmd, 1, 0}, - {"scrollbar", Tk_ScrollbarCmd, NULL, 1, 1}, - {"spinbox", NULL, Tk_SpinboxObjCmd, 1, 0}, - {"text", Tk_TextCmd, NULL, 1, 1}, - {"toplevel", NULL, Tk_ToplevelObjCmd, 0, 0}, + {"button", NULL, Tk_ButtonObjCmd, ISSAFE}, + {"canvas", NULL, Tk_CanvasObjCmd, PASSMAINWINDOW|ISSAFE}, + {"checkbutton", NULL, Tk_CheckbuttonObjCmd, ISSAFE}, + {"entry", NULL, Tk_EntryObjCmd, ISSAFE}, + {"frame", NULL, Tk_FrameObjCmd, ISSAFE}, + {"label", NULL, Tk_LabelObjCmd, ISSAFE}, + {"labelframe", NULL, Tk_LabelframeObjCmd, ISSAFE}, + {"listbox", NULL, Tk_ListboxObjCmd, ISSAFE}, + {"menubutton", NULL, Tk_MenubuttonObjCmd, ISSAFE}, + {"message", NULL, Tk_MessageObjCmd, ISSAFE}, + {"panedwindow", NULL, Tk_PanedWindowObjCmd, ISSAFE}, + {"radiobutton", NULL, Tk_RadiobuttonObjCmd, ISSAFE}, + {"scale", NULL, Tk_ScaleObjCmd, ISSAFE}, + {"scrollbar", Tk_ScrollbarCmd, NULL, PASSMAINWINDOW|ISSAFE}, + {"spinbox", NULL, Tk_SpinboxObjCmd, ISSAFE}, + {"text", Tk_TextCmd, NULL, PASSMAINWINDOW|ISSAFE}, + {"toplevel", NULL, Tk_ToplevelObjCmd, 0}, /* * Misc. @@ -177,7 +174,7 @@ static TkCmd commands[] = { #if defined(MAC_TCL) || defined(MAC_OSX_TK) {"::tk::unsupported::MacWindowStyle", - NULL, TkUnsupported1ObjCmd, 1, 1}, + NULL, TkUnsupported1ObjCmd, PASSMAINWINDOW|ISSAFE}, #endif {(char *) NULL, (int (*) _ANSI_ARGS_((ClientData, Tcl_Interp *, int, CONST char **))) NULL, NULL, 0} }; @@ -857,7 +854,7 @@ TkCreateMainWindow(interp, screenName, baseName) Tcl_HashEntry *hPtr; register TkMainInfo *mainPtr; register TkWindow *winPtr; - register TkCmd *cmdPtr; + register CONST TkCmd *cmdPtr; ClientData clientData; ThreadSpecificData *tsdPtr = (ThreadSpecificData *) Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); @@ -942,9 +939,9 @@ TkCreateMainWindow(interp, screenName, baseName) isSafe = Tcl_IsSafe(interp); for (cmdPtr = commands; cmdPtr->name != NULL; cmdPtr++) { if ((cmdPtr->cmdProc == NULL) && (cmdPtr->objProc == NULL)) { - panic("TkCreateMainWindow: builtin command with NULL string and object procs"); + Tcl_Panic("TkCreateMainWindow: builtin command with NULL string and object procs"); } - if (cmdPtr->passMainWindow) { + if (cmdPtr->flags & PASSMAINWINDOW) { clientData = (ClientData) tkwin; } else { clientData = (ClientData) NULL; @@ -956,11 +953,11 @@ TkCreateMainWindow(interp, screenName, baseName) Tcl_CreateObjCommand(interp, cmdPtr->name, cmdPtr->objProc, clientData, NULL); } - if (isSafe) { - if (!(cmdPtr->isSafe)) { - Tcl_HideCommand(interp, cmdPtr->name, cmdPtr->name); - } - } + if (isSafe) { + if (!(cmdPtr->flags & ISSAFE)) { + Tcl_HideCommand(interp, cmdPtr->name, cmdPtr->name); + } + } } TkCreateMenuCmd(interp); @@ -1514,7 +1511,7 @@ Tk_DestroyWindow(tkwin) } winPtr->mainPtr->refCount--; if (winPtr->mainPtr->refCount == 0) { - register TkCmd *cmdPtr; + register CONST TkCmd *cmdPtr; /* * We just deleted the last window in the application. Delete diff --git a/unix/Makefile.in b/unix/Makefile.in index 27bbb19..b43c1ef 100644 --- a/unix/Makefile.in +++ b/unix/Makefile.in @@ -632,8 +632,15 @@ install-binaries: $(TK_LIB_FILE) $(TK_STUB_LIB_FILE) $(TK_BUILD_EXP_FILE) wish (\ relative=`echo | awk '{ORS=" "; split("$(TK_PKG_DIR)",a,"/"); for (f in a) {print ".."}}'`;\ echo "if {[package vcompare [package provide Tcl] $(TCLVERSION)] != 0} { return }";\ - echo "package ifneeded Tk $(MAJOR_VERSION).$(MINOR_VERSION)\ - [list load [file join \$$dir $${relative}$(TK_LIB_FILE)] Tk]";\ + echo "if {[string match CYGWIN* \$$::tcl_platform(os)]} {";\ + echo " if {([info exists ::env(DISPLAY)] || [lsearch -exact \$$::argv -display] > -1)} {";\ + echo " package ifneeded Tk $(MAJOR_VERSION).$(MINOR_VERSION) [list load [file join \$$dir $${relative}.. bin $(TK_LIB_FILE)] Tk]";\ + echo " } else {";\ + echo " package ifneeded Tk $(MAJOR_VERSION).$(MINOR_VERSION) [list load [file join \$$dir $${relative}.. bin tk${MAJOR_VERSION}${MINOR_VERSION}.dll] Tk]";\ + echo " }";\ + echo "} else {";\ + echo " package ifneeded Tk $(MAJOR_VERSION).$(MINOR_VERSION) [list load [file join \$$dir $${relative}$(TK_LIB_FILE)] Tk]";\ + echo "}";\ ) > $(PKG_INDEX); \ fi @echo "Installing $(LIB_FILE) to $(LIB_INSTALL_DIR)/" -- cgit v0.12 From 95c5b39b2e335c0fc08a25281ad9097a29aee1ae Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 18 Apr 2012 18:08:37 +0000 Subject: make some more internal tables CONST --- generic/tkArgv.c | 2 +- generic/tkAtom.c | 4 ++-- generic/tkButton.c | 8 ++++---- generic/tkEntry.c | 4 ++-- generic/tkFrame.c | 6 +++--- generic/tkImgBmap.c | 2 +- generic/tkListbox.c | 4 ++-- generic/tkMenubutton.c | 6 +++--- generic/tkPanedWindow.c | 2 +- generic/tkPlace.c | 2 +- generic/tkScale.c | 4 ++-- generic/tkTest.c | 4 ++-- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/generic/tkArgv.c b/generic/tkArgv.c index 4821f41..4ee3b78 100644 --- a/generic/tkArgv.c +++ b/generic/tkArgv.c @@ -355,7 +355,7 @@ PrintUsage(interp, argTable, flags) register Tk_ArgvInfo *infoPtr; int width, i, numSpaces; #define NUM_SPACES 20 - static char spaces[] = " "; + static CONST char spaces[] = " "; char tmp[TCL_DOUBLE_SPACE]; /* diff --git a/generic/tkAtom.c b/generic/tkAtom.c index f94af81..108e989 100644 --- a/generic/tkAtom.c +++ b/generic/tkAtom.c @@ -22,7 +22,7 @@ * They should match those found in xatom.h */ -static char * atomNameArray[] = { +static CONST char *atomNameArray[] = { "PRIMARY", "SECONDARY", "ARC", "ATOM", "BITMAP", "CARDINAL", "COLORMAP", "CURSOR", "CUT_BUFFER0", @@ -199,7 +199,7 @@ AtomInit(dispPtr) for (atom = 1; atom <= XA_LAST_PREDEFINED; atom++) { hPtr = Tcl_FindHashEntry(&dispPtr->atomTable, (char *) atom); if (hPtr == NULL) { - char *name; + CONST char *name; int new; name = atomNameArray[atom - 1]; diff --git a/generic/tkButton.c b/generic/tkButton.c index 3783985..e844cec 100644 --- a/generic/tkButton.c +++ b/generic/tkButton.c @@ -25,14 +25,14 @@ static Tcl_ThreadDataKey dataKey; * in tkButton.h. */ -static char *classNames[] = {"Label", "Button", "Checkbutton", "Radiobutton"}; +static CONST char *classNames[] = {"Label", "Button", "Checkbutton", "Radiobutton"}; /* * The following table defines the legal values for the -default option. * It is used together with the "enum defaultValue" declaration in tkButton.h. */ -static char *defaultStrings[] = { +static CONST char *defaultStrings[] = { "active", "disabled", "normal", (char *) NULL }; @@ -41,7 +41,7 @@ static char *defaultStrings[] = { * It is used together with the "enum state" declaration in tkButton.h. */ -static char *stateStrings[] = { +static CONST char *stateStrings[] = { "active", "disabled", "normal", (char *) NULL }; @@ -50,7 +50,7 @@ static char *stateStrings[] = { * It is used with the "enum compound" declaration in tkButton.h */ -static char *compoundStrings[] = { +static CONST char *compoundStrings[] = { "bottom", "center", "left", "none", "right", "top", (char *) NULL }; diff --git a/generic/tkEntry.c b/generic/tkEntry.c index afd6b15..c6eed1b 100644 --- a/generic/tkEntry.c +++ b/generic/tkEntry.c @@ -35,7 +35,7 @@ #define DOUBLES_EQ(d1, d2) (fabs((d1) - (d2)) < MIN_DBL_VAL) -static char *stateStrings[] = { +static CONST char *stateStrings[] = { "disabled", "normal", "readonly", (char *) NULL }; @@ -43,7 +43,7 @@ static char *stateStrings[] = { * Definitions for -validate option values: */ -static char *validateStrings[] = { +static CONST char *validateStrings[] = { "all", "key", "focus", "focusin", "focusout", "none", (char *) NULL }; enum validateType { diff --git a/generic/tkFrame.c b/generic/tkFrame.c index 453ad73..a416b22 100644 --- a/generic/tkFrame.c +++ b/generic/tkFrame.c @@ -170,7 +170,7 @@ enum labelanchor { LABELANCHOR_W, LABELANCHOR_WN, LABELANCHOR_WS }; -static char *labelAnchorStrings[] = { +static CONST char *labelAnchorStrings[] = { "e", "en", "es", "n", "ne", "nw", "s", "se", "sw", "w", "wn", "ws", (char *) NULL }; @@ -302,7 +302,7 @@ static Tk_OptionSpec labelframeOptSpec[] = { * Class names for widgets, indexed by FrameType. */ -static char *classNames[] = {"Frame", "Toplevel", "Labelframe"}; +static CONST char *classNames[] = {"Frame", "Toplevel", "Labelframe"}; /* * The following table maps from FrameType to the option template for @@ -312,7 +312,7 @@ static char *classNames[] = {"Frame", "Toplevel", "Labelframe"}; static Tk_OptionSpec *optionSpecs[] = { frameOptSpec, toplevelOptSpec, - labelframeOptSpec, + labelframeOptSpec }; /* diff --git a/generic/tkImgBmap.c b/generic/tkImgBmap.c index e1ccecb..2542697 100644 --- a/generic/tkImgBmap.c +++ b/generic/tkImgBmap.c @@ -1159,7 +1159,7 @@ ImgBmapPsImagemask(interp, width, height, data) * on the left.) The following array is used to reverse the order of bits * within a byte so that the bits will be in the order postscript expects. */ - static unsigned char bit_reverse[] = { + static CONST unsigned char bit_reverse[] = { 0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240, 8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248, 4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244, diff --git a/generic/tkListbox.c b/generic/tkListbox.c index cc73937..6f8156f 100644 --- a/generic/tkListbox.c +++ b/generic/tkListbox.c @@ -210,7 +210,7 @@ enum state { STATE_DISABLED, STATE_NORMAL }; -static char *stateStrings[] = { +static CONST char *stateStrings[] = { "disabled", "normal", (char *) NULL }; @@ -218,7 +218,7 @@ enum activeStyle { ACTIVE_STYLE_DOTBOX, ACTIVE_STYLE_NONE, ACTIVE_STYLE_UNDERLINE }; -static char *activeStyleStrings[] = { +static CONST char *activeStyleStrings[] = { "dotbox", "none", "underline", (char *) NULL }; diff --git a/generic/tkMenubutton.c b/generic/tkMenubutton.c index 8292b32..7e9a11a 100644 --- a/generic/tkMenubutton.c +++ b/generic/tkMenubutton.c @@ -21,7 +21,7 @@ * in tkMenubutton.h. */ -static char *directionStrings[] = { +static CONST char *directionStrings[] = { "above", "below", "flush", "left", "right", (char *) NULL }; @@ -30,7 +30,7 @@ static char *directionStrings[] = { * It is used together with the "enum state" declaration in tkMenubutton.h. */ -static char *stateStrings[] = { +static CONST char *stateStrings[] = { "active", "disabled", "normal", (char *) NULL }; @@ -39,7 +39,7 @@ static char *stateStrings[] = { * It is used with the "enum compound" declaration in tkMenuButton.h */ -static char *compoundStrings[] = { +static CONST char *compoundStrings[] = { "bottom", "center", "left", "none", "right", "top", (char *) NULL }; diff --git a/generic/tkPanedWindow.c b/generic/tkPanedWindow.c index 57670ba..09106dd 100644 --- a/generic/tkPanedWindow.c +++ b/generic/tkPanedWindow.c @@ -34,7 +34,7 @@ * The following table defines the legal values for the -orient option. */ -static char *orientStrings[] = { +static CONST char *orientStrings[] = { "horizontal", "vertical", (char *) NULL }; diff --git a/generic/tkPlace.c b/generic/tkPlace.c index b239947..6178d26 100644 --- a/generic/tkPlace.c +++ b/generic/tkPlace.c @@ -26,7 +26,7 @@ * master's actual window size. */ -static char *borderModeStrings[] = { +static CONST char *borderModeStrings[] = { "inside", "outside", "ignore", (char *) NULL }; diff --git a/generic/tkScale.c b/generic/tkScale.c index 676f84b..9b582fe 100644 --- a/generic/tkScale.c +++ b/generic/tkScale.c @@ -30,7 +30,7 @@ * It is used together with the "enum orient" declaration in tkScale.h. */ -static char *orientStrings[] = { +static CONST char *orientStrings[] = { "horizontal", "vertical", (char *) NULL }; @@ -39,7 +39,7 @@ static char *orientStrings[] = { * It is used together with the "enum state" declaration in tkScale.h. */ -static char *stateStrings[] = { +static CONST char *stateStrings[] = { "active", "disabled", "normal", (char *) NULL }; diff --git a/generic/tkTest.c b/generic/tkTest.c index 0d6657a..fdd70b7 100644 --- a/generic/tkTest.c +++ b/generic/tkTest.c @@ -717,7 +717,7 @@ TestobjconfigObjCmd(clientData, interp, objc, objv) Tcl_Obj *customPtr; } TypesRecord; TypesRecord *recordPtr; - static char *stringTable[] = {"one", "two", "three", "four", + static CONST char *stringTable[] = {"one", "two", "three", "four", (char *) NULL}; static Tk_OptionSpec typesSpecs[] = { {TK_OPTION_BOOLEAN, @@ -1032,7 +1032,7 @@ TestobjconfigObjCmd(clientData, interp, objc, objv) char *custom; } InternalRecord; InternalRecord *recordPtr; - static char *internalStringTable[] = { + static CONST char *internalStringTable[] = { "one", "two", "three", "four", (char *) NULL }; static Tk_OptionSpec internalSpecs[] = { -- cgit v0.12