Tk Source Code

Check-in [45ce45eb]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:3235256 - Keep menu entry IDs out of system values. Thanks Colin McDonald.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core-8-4-branch
Files: files | file ages | folders
SHA1: 45ce45eba444b798c21115f235681e60184c9c48
User & Date: dgp 2011-12-22 18:39:16
Context
2012-01-25
22:00
Bug-2433260: non-critical error in Tk_PhotoPutBlock check-in: a2b769a6 user: jan.nijtmans tags: core-8-4-branch
2011-12-22
18:42
3235256 - Keep menu entry IDs out of system values. Thanks Colin McDonald. check-in: 39071084 user: dgp tags: core-8-5-branch
18:39
3235256 - Keep menu entry IDs out of system values. Thanks Colin McDonald. check-in: 45ce45eb user: dgp tags: core-8-4-branch
2011-11-22
16:53
[Bug 1945073]: Demo square.tcl cannot run; need package tktest check-in: 43a8cf52 user: jan.nijtmans tags: core-8-4-branch
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to win/tkWinMenu.c.

193
194
195
196
197
198
199
200
201
202
203
204
205

206

207

208
209
210

211
212


213


214
215
216
217
218
219
220
221
222
223
224

225
226
227
228
229
230
231

232
233
234
235
236
237
238
 */

static int
GetNewID(mePtr, menuIDPtr)
    TkMenuEntry *mePtr;		/* The menu we are working with */
    WORD *menuIDPtr;		/* The resulting id */
{
    int found = 0;
    int newEntry;
    Tcl_HashEntry *commandEntryPtr;
    WORD returnID;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *) 
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));



    WORD curID = tsdPtr->lastCommandID + 1;


    /*
     * The following code relies on WORD wrapping when the highest value is

     * incremented.
     */


    


    while (curID != tsdPtr->lastCommandID) {
    	commandEntryPtr = Tcl_CreateHashEntry(&tsdPtr->commandTable,
		(char *) curID, &newEntry);
    	if (newEntry == 1) {
    	    found = 1;
    	    returnID = curID;
    	    break;
    	}
    	curID++;
    }


    if (found) {
    	Tcl_SetHashValue(commandEntryPtr, (char *) mePtr);
    	*menuIDPtr = returnID;
    	tsdPtr->lastCommandID = returnID;
    	return TCL_OK;
    } else {
    	return TCL_ERROR;

    }
}

/*
 *----------------------------------------------------------------------
 *
 * FreeID --







<
<
<
<

|
>

>
|
>

|
<
>
|
|
>
>
|
>
>
|
<
<
<
<
|
<
|
<
|
|
>
|
|
|
|
|
<
<
>







193
194
195
196
197
198
199




200
201
202
203
204
205
206
207
208

209
210
211
212
213
214
215
216
217




218

219

220
221
222
223
224
225
226
227


228
229
230
231
232
233
234
235
 */

static int
GetNewID(mePtr, menuIDPtr)
    TkMenuEntry *mePtr;		/* The menu we are working with */
    WORD *menuIDPtr;		/* The resulting id */
{




    ThreadSpecificData *tsdPtr = (ThreadSpecificData *) 
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    WORD curID = tsdPtr->lastCommandID;

    while (1) {
	Tcl_HashEntry *commandEntryPtr;
	int new;

	/*

	 * Try the next ID number, taking care to wrap rather than stray
	 * into the system menu IDs.  [Bug 3235256]
	 */
	if (++curID >= 0xF000) {
	    curID = 1;
	}

	/* Return error when we've checked all IDs without success. */
	if (curID == tsdPtr->lastCommandID) {




	    return TCL_ERROR;

	}


	commandEntryPtr = Tcl_CreateHashEntry(&tsdPtr->commandTable,
		(char *) curID, &new);
	if (new) {
	    Tcl_SetHashValue(commandEntryPtr, (char *) mePtr);
	    *menuIDPtr = curID;
	    tsdPtr->lastCommandID = curID;
	    return TCL_OK;


	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * FreeID --