Tk Source Code

Artifact [ff5801f6]
Login

Artifact ff5801f6f70f1266378402831db534aad1423d38:

Attachment "tk_XID_cleanup-1.patch" to ticket [2039720f] added by georgeps 2008-08-06 11:46:14.
Index: generic/tkError.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkError.c,v
retrieving revision 1.6
diff -u -r1.6 tkError.c
--- generic/tkError.c	13 Dec 2007 15:24:14 -0000	1.6
+++ generic/tkError.c	6 Aug 2008 01:27:25 -0000
@@ -271,8 +271,7 @@
     if (errEventPtr->error_code == BadWindow) {
 	Window w = (Window) errEventPtr->resourceid;
 
-	if (Tk_IdToWindow(display, w) != NULL
-		|| TkpWindowWasRecentlyDeleted(w, dispPtr)) {
+	if (Tk_IdToWindow(display, w) != NULL) {
 	    return 0;
 	}
     }
Index: generic/tkInt.decls
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkInt.decls,v
retrieving revision 1.44
diff -u -r1.44 tkInt.decls
--- generic/tkInt.decls	13 Dec 2007 15:24:14 -0000	1.44
+++ generic/tkInt.decls	6 Aug 2008 01:27:26 -0000
@@ -278,9 +278,6 @@
 declare 75 generic {
     int TkpUseWindow(Tcl_Interp *interp, Tk_Window tkwin, CONST char *string)
 }
-declare 76 generic {
-    int TkpWindowWasRecentlyDeleted(Window win, TkDisplay *dispPtr)
-}
 declare 77 generic {
     void TkQueueEventForAllChildren(TkWindow *winPtr, XEvent *eventPtr)
 }
@@ -531,12 +528,6 @@
 declare 0 x11 {
     void TkCreateXEventSource(void)
 }
-declare 1 x11 {
-    void TkFreeWindowId(TkDisplay *dispPtr, Window w)
-}
-declare 2 x11 {
-    void TkInitXId(TkDisplay *dispPtr)
-}
 declare 3 x11 {
     int TkpCmapStressed(Tk_Window tkwin, Colormap colormap)
 }
@@ -561,9 +552,6 @@
 declare 10 x11 {
     void TkSendCleanup(TkDisplay *dispPtr)
 }
-declare 11 x11 {
-    void TkFreeXId(TkDisplay *dispPtr)
-}
 declare 12 x11 {
     int TkpWmSetState(TkWindow *winPtr, int state)
 }
Index: generic/tkIntDecls.h
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkIntDecls.h,v
retrieving revision 1.34
diff -u -r1.34 tkIntDecls.h
--- generic/tkIntDecls.h	8 Apr 2008 03:28:05 -0000	1.34
+++ generic/tkIntDecls.h	6 Aug 2008 01:27:28 -0000
@@ -477,12 +477,7 @@
 EXTERN int		TkpUseWindow (Tcl_Interp * interp, Tk_Window tkwin, 
 				CONST char * string);
 #endif
-#ifndef TkpWindowWasRecentlyDeleted_TCL_DECLARED
-#define TkpWindowWasRecentlyDeleted_TCL_DECLARED
-/* 76 */
-EXTERN int		TkpWindowWasRecentlyDeleted (Window win, 
-				TkDisplay * dispPtr);
-#endif
+/* Slot 76 is reserved */
 #ifndef TkQueueEventForAllChildren_TCL_DECLARED
 #define TkQueueEventForAllChildren_TCL_DECLARED
 /* 77 */
@@ -1039,7 +1034,7 @@
     void (*tkpRedirectKeyEvent) (TkWindow * winPtr, XEvent * eventPtr); /* 73 */
     void (*tkpSetMainMenubar) (Tcl_Interp * interp, Tk_Window tkwin, char * menuName); /* 74 */
     int (*tkpUseWindow) (Tcl_Interp * interp, Tk_Window tkwin, CONST char * string); /* 75 */
-    int (*tkpWindowWasRecentlyDeleted) (Window win, TkDisplay * dispPtr); /* 76 */
+    void *reserved76;
     void (*tkQueueEventForAllChildren) (TkWindow * winPtr, XEvent * eventPtr); /* 77 */
     int (*tkReadBitmapFile) (Display * display, Drawable d, CONST char * filename, unsigned int * width_return, unsigned int * height_return, Pixmap * bitmap_return, int * x_hot_return, int * y_hot_return); /* 78 */
     int (*tkScrollWindow) (Tk_Window tkwin, GC gc, int x, int y, int width, int height, int dx, int dy, TkRegion damageRgn); /* 79 */
@@ -1536,10 +1531,7 @@
 #define TkpUseWindow \
 	(tkIntStubsPtr->tkpUseWindow) /* 75 */
 #endif
-#ifndef TkpWindowWasRecentlyDeleted
-#define TkpWindowWasRecentlyDeleted \
-	(tkIntStubsPtr->tkpWindowWasRecentlyDeleted) /* 76 */
-#endif
+/* Slot 76 is reserved */
 #ifndef TkQueueEventForAllChildren
 #define TkQueueEventForAllChildren \
 	(tkIntStubsPtr->tkQueueEventForAllChildren) /* 77 */
Index: generic/tkIntPlatDecls.h
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkIntPlatDecls.h,v
retrieving revision 1.32
diff -u -r1.32 tkIntPlatDecls.h
--- generic/tkIntPlatDecls.h	8 Apr 2008 15:00:43 -0000	1.32
+++ generic/tkIntPlatDecls.h	6 Aug 2008 01:27:28 -0000
@@ -484,16 +484,8 @@
 /* 0 */
 EXTERN void		TkCreateXEventSource (void);
 #endif
-#ifndef TkFreeWindowId_TCL_DECLARED
-#define TkFreeWindowId_TCL_DECLARED
-/* 1 */
-EXTERN void		TkFreeWindowId (TkDisplay * dispPtr, Window w);
-#endif
-#ifndef TkInitXId_TCL_DECLARED
-#define TkInitXId_TCL_DECLARED
-/* 2 */
-EXTERN void		TkInitXId (TkDisplay * dispPtr);
-#endif
+/* Slot 1 is reserved */
+/* Slot 2 is reserved */
 #ifndef TkpCmapStressed_TCL_DECLARED
 #define TkpCmapStressed_TCL_DECLARED
 /* 3 */
@@ -535,11 +527,7 @@
 /* 10 */
 EXTERN void		TkSendCleanup (TkDisplay * dispPtr);
 #endif
-#ifndef TkFreeXId_TCL_DECLARED
-#define TkFreeXId_TCL_DECLARED
-/* 11 */
-EXTERN void		TkFreeXId (TkDisplay * dispPtr);
-#endif
+/* Slot 11 is reserved */
 #ifndef TkpWmSetState_TCL_DECLARED
 #define TkpWmSetState_TCL_DECLARED
 /* 12 */
@@ -654,8 +642,8 @@
 #endif /* AQUA */
 #if !(defined(__WIN32__) || defined(MAC_OSX_TK)) /* X11 */
     void (*tkCreateXEventSource) (void); /* 0 */
-    void (*tkFreeWindowId) (TkDisplay * dispPtr, Window w); /* 1 */
-    void (*tkInitXId) (TkDisplay * dispPtr); /* 2 */
+    void *reserved1;
+    void *reserved2;
     int (*tkpCmapStressed) (Tk_Window tkwin, Colormap colormap); /* 3 */
     void (*tkpSync) (Display * display); /* 4 */
     Window (*tkUnixContainerId) (TkWindow * winPtr); /* 5 */
@@ -664,7 +652,7 @@
     int (*tkpScanWindowId) (Tcl_Interp * interp, CONST char * string, Window * idPtr); /* 8 */
     void (*tkWmCleanup) (TkDisplay * dispPtr); /* 9 */
     void (*tkSendCleanup) (TkDisplay * dispPtr); /* 10 */
-    void (*tkFreeXId) (TkDisplay * dispPtr); /* 11 */
+    void *reserved11;
     int (*tkpWmSetState) (TkWindow * winPtr, int state); /* 12 */
     int (*tkpTestsendCmd) (ClientData clientData, Tcl_Interp * interp, int argc, CONST char ** argv); /* 13 */
 #endif /* X11 */
@@ -1022,14 +1010,8 @@
 #define TkCreateXEventSource \
 	(tkIntPlatStubsPtr->tkCreateXEventSource) /* 0 */
 #endif
-#ifndef TkFreeWindowId
-#define TkFreeWindowId \
-	(tkIntPlatStubsPtr->tkFreeWindowId) /* 1 */
-#endif
-#ifndef TkInitXId
-#define TkInitXId \
-	(tkIntPlatStubsPtr->tkInitXId) /* 2 */
-#endif
+/* Slot 1 is reserved */
+/* Slot 2 is reserved */
 #ifndef TkpCmapStressed
 #define TkpCmapStressed \
 	(tkIntPlatStubsPtr->tkpCmapStressed) /* 3 */
@@ -1062,10 +1044,7 @@
 #define TkSendCleanup \
 	(tkIntPlatStubsPtr->tkSendCleanup) /* 10 */
 #endif
-#ifndef TkFreeXId
-#define TkFreeXId \
-	(tkIntPlatStubsPtr->tkFreeXId) /* 11 */
-#endif
+/* Slot 11 is reserved */
 #ifndef TkpWmSetState
 #define TkpWmSetState \
 	(tkIntPlatStubsPtr->tkpWmSetState) /* 12 */
Index: generic/tkStubInit.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkStubInit.c,v
retrieving revision 1.63
diff -u -r1.63 tkStubInit.c
--- generic/tkStubInit.c	27 Apr 2008 22:38:58 -0000	1.63
+++ generic/tkStubInit.c	6 Aug 2008 01:27:31 -0000
@@ -128,7 +128,7 @@
     TkpRedirectKeyEvent, /* 73 */
     TkpSetMainMenubar, /* 74 */
     TkpUseWindow, /* 75 */
-    TkpWindowWasRecentlyDeleted, /* 76 */
+    NULL, /* 76 */
     TkQueueEventForAllChildren, /* 77 */
     TkReadBitmapFile, /* 78 */
     TkScrollWindow, /* 79 */
@@ -410,8 +410,8 @@
 #endif /* AQUA */
 #if !(defined(__WIN32__) || defined(MAC_OSX_TK)) /* X11 */
     TkCreateXEventSource, /* 0 */
-    TkFreeWindowId, /* 1 */
-    TkInitXId, /* 2 */
+    NULL, /* 1 */
+    NULL, /* 2 */
     TkpCmapStressed, /* 3 */
     TkpSync, /* 4 */
     TkUnixContainerId, /* 5 */
@@ -420,7 +420,7 @@
     TkpScanWindowId, /* 8 */
     TkWmCleanup, /* 9 */
     TkSendCleanup, /* 10 */
-    TkFreeXId, /* 11 */
+    NULL, /* 11 */
     TkpWmSetState, /* 12 */
     TkpTestsendCmd, /* 13 */
 #endif /* X11 */
Index: generic/tkWindow.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/generic/tkWindow.c,v
retrieving revision 1.95
diff -u -r1.95 tkWindow.c
--- generic/tkWindow.c	27 Apr 2008 22:38:58 -0000	1.95
+++ generic/tkWindow.c	6 Aug 2008 01:27:34 -0000
@@ -521,8 +521,6 @@
 	    dispPtr->name = (char *) ckalloc((unsigned) (length+1));
 	    strncpy(dispPtr->name, screenName, length);
 	    dispPtr->name[length] = '\0';
-
-	    TkInitXId(dispPtr);
 	    break;
 	}
 	if ((strncmp(dispPtr->name, screenName, length) == 0)
@@ -1461,7 +1459,6 @@
 	    XDestroyWindow(winPtr->display, winPtr->window);
 	}
 #endif
-	TkFreeWindowId(dispPtr, winPtr->window);
 	Tcl_DeleteHashEntry(Tcl_FindHashEntry(&dispPtr->winTable,
 		(char *) winPtr->window));
 	winPtr->window = None;
Index: macosx/tkMacOSXPort.h
===================================================================
RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXPort.h,v
retrieving revision 1.13
diff -u -r1.13 tkMacOSXPort.h
--- macosx/tkMacOSXPort.h	13 Dec 2007 15:27:10 -0000	1.13
+++ macosx/tkMacOSXPort.h	6 Aug 2008 01:27:34 -0000
@@ -140,8 +140,6 @@
  * The following functions are not used on the Mac, so we stub them out.
  */
 
-#define TkFreeWindowId(dispPtr,w)
-#define TkInitXId(dispPtr)
 #define TkpButtonSetDefaults(specPtr) {}
 #define TkpCmapStressed(tkwin,colormap) (0)
 #define TkpFreeColor(tkColPtr)
Index: macosx/tkMacOSXXStubs.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXXStubs.c,v
retrieving revision 1.28
diff -u -r1.28 tkMacOSXXStubs.c
--- macosx/tkMacOSXXStubs.c	12 Jun 2008 06:32:11 -0000	1.28
+++ macosx/tkMacOSXXStubs.c	6 Aug 2008 01:27:35 -0000
@@ -323,33 +323,6 @@
 /*
  *----------------------------------------------------------------------
  *
- * TkpWindowWasRecentlyDeleted --
- *
- *	Tries to determine whether the given window was recently deleted.
- *	Called from the generic code error handler to attempt to deal with
- *	async BadWindow errors under some circumstances.
- *
- * Results:
- *	Always 0, we do not keep this information on the Mac, so we do not
- *	know whether the window was destroyed.
- *
- * Side effects:
- *	None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-TkpWindowWasRecentlyDeleted(
-    Window win,
-    TkDisplay *dispPtr)
-{
-    return 0;
-}
-
-/*
- *----------------------------------------------------------------------
- *
  * DefaultErrorHandler --
  *
  *	This procedure is the default X error handler. Tk uses it's own error
Index: unix/tkUnixEvent.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/unix/tkUnixEvent.c,v
retrieving revision 1.28
diff -u -r1.28 tkUnixEvent.c
--- unix/tkUnixEvent.c	27 Apr 2008 22:39:13 -0000	1.28
+++ unix/tkUnixEvent.c	6 Aug 2008 01:27:36 -0000
@@ -156,8 +156,6 @@
 {
     TkSendCleanup(dispPtr);
 
-    TkFreeXId(dispPtr);
-
     TkWmCleanup(dispPtr);
 
 #ifdef TK_USE_INPUT_METHODS
Index: unix/tkUnixXId.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/unix/tkUnixXId.c,v
retrieving revision 1.11
diff -u -r1.11 tkUnixXId.c
--- unix/tkUnixXId.c	27 Apr 2008 22:39:14 -0000	1.11
+++ unix/tkUnixXId.c	6 Aug 2008 01:27:36 -0000
@@ -1,15 +1,6 @@
 /*
  * tkUnixXId.c --
  *
- *	This file provides a replacement function for the default X resource
- *	allocator (_XAllocID). The problem with the default allocator is that
- *	it never re-uses ids, which causes long-lived applications to crash
- *	when X resource identifiers wrap around. The replacement functions in
- *	this file re-use old identifiers to prevent this problem.
- *
- *	The code in this file is based on similar implementations by
- *	George C. Kaplan and Michael Hoegeman.
- *
  * Copyright (c) 1993 The Regents of the University of California.
  * Copyright (c) 1994-1997 Sun Microsystems, Inc.
  *
@@ -19,170 +10,8 @@
  * RCS: @(#) $Id: tkUnixXId.c,v 1.11 2008/04/27 22:39:14 dkf Exp $
  */
 
-/*
- * The definition below is needed on some systems so that we can access the
- * resource_alloc field of Display structures in order to replace the resource
- * allocator.
- */
-
-#define XLIB_ILLEGAL_ACCESS 1
-
 #include "tkUnixInt.h"
 
-/*
- * A structure of the following type is used to hold one or more available
- * resource identifiers. There is a list of these structures for each display.
- */
-
-#define IDS_PER_STACK 10
-typedef struct TkIdStack {
-    XID ids[IDS_PER_STACK];	/* Array of free identifiers. */
-    int numUsed;		/* Indicates how many of the entries in ids
-				 * are currently in use. */
-    TkDisplay *dispPtr;		/* Display to which ids belong. */
-    struct TkIdStack *nextPtr;	/* Next bunch of free identifiers for the same
-				 * display. */
-} TkIdStack;
-
-/*
- * Forward declarations for functions defined in this file:
- */
-
-static XID		AllocXId(Display *display);
-static Tk_RestrictAction CheckRestrictProc(ClientData clientData,
-			    XEvent *eventPtr);
-static void		WindowIdCleanup(ClientData clientData);
-static void		WindowIdCleanup2(ClientData clientData);
-
-/*
- *----------------------------------------------------------------------
- *
- * TkInitXId --
- *
- *	This function is called to initialize the id allocator for a given
- *	display.
- *
- * Results:
- *	None.
- *
- * Side effects:
- *	The official allocator for the display is set up to be AllocXId.
- *
- *----------------------------------------------------------------------
- */
-
-void
-TkInitXId(
-    TkDisplay *dispPtr)		/* Tk's information about the display. */
-{
-    dispPtr->idStackPtr = NULL;
-    dispPtr->defaultAllocProc = (XID (*) (Display *display))
-	    dispPtr->display->resource_alloc;
-    dispPtr->display->resource_alloc = AllocXId;
-    dispPtr->windowStackPtr = NULL;
-    dispPtr->idCleanupScheduled = (Tcl_TimerToken) 0;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * TkFreeXId --
- *
- *	This function is called to free resources for the id allocator for a
- *	given display.
- *
- * Results:
- *	None.
- *
- * Side effects:
- *	Frees the id and window stack pools.
- *
- *----------------------------------------------------------------------
- */
-
-void
-TkFreeXId(
-    TkDisplay *dispPtr)		/* Tk's information about the display. */
-{
-    TkIdStack *stackPtr, *freePtr;
-
-    if (dispPtr->idCleanupScheduled) {
-	Tcl_DeleteTimerHandler(dispPtr->idCleanupScheduled);
-    }
-
-    for (stackPtr = dispPtr->idStackPtr; stackPtr != NULL; ) {
-	freePtr = stackPtr;
-	stackPtr = stackPtr->nextPtr;
-	ckfree((char *) freePtr);
-    }
-    dispPtr->idStackPtr = NULL;
-
-    for (stackPtr = dispPtr->windowStackPtr; stackPtr != NULL; ) {
-	freePtr = stackPtr;
-	stackPtr = stackPtr->nextPtr;
-	ckfree((char *) freePtr);
-    }
-    dispPtr->windowStackPtr = NULL;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * AllocXId --
- *
- *	This function is invoked by Xlib as the resource allocator for a
- *	display.
- *
- * Results:
- *	The return value is an X resource identifier that isn't currently in
- *	use.
- *
- * Side effects:
- *	The identifier is removed from the stack of free identifiers, if it
- *	was previously on the stack.
- *
- *----------------------------------------------------------------------
- */
-
-static XID
-AllocXId(
-    Display *display)		/* Display for which to allocate. */
-{
-    TkDisplay *dispPtr;
-    TkIdStack *stackPtr;
-
-    /*
-     * Find Tk's information about the display.
-     */
-
-    dispPtr = TkGetDisplay(display);
-
-    /*
-     * If the topmost chunk on the stack is empty then free it. Then check for
-     * a free id on the stack and return it if it exists.
-     */
-
-    stackPtr = dispPtr->idStackPtr;
-    if (stackPtr != NULL) {
-	while (stackPtr->numUsed == 0) {
-	    dispPtr->idStackPtr = stackPtr->nextPtr;
-	    ckfree((char *) stackPtr);
-	    stackPtr = dispPtr->idStackPtr;
-	    if (stackPtr == NULL) {
-		goto defAlloc;
-	    }
-	}
-	stackPtr->numUsed--;
-	return stackPtr->ids[stackPtr->numUsed];
-    }
-
-    /*
-     * No free ids in the stack: just get one from the default allocator.
-     */
-
-  defAlloc:
-    return (*dispPtr->defaultAllocProc)(display);
-}
 
 /*
  *----------------------------------------------------------------------
@@ -207,268 +36,15 @@
     Display *display,		/* Display for which xid was allocated. */
     XID xid)			/* Identifier that is no longer in use. */
 {
-    TkDisplay *dispPtr;
-    TkIdStack *stackPtr;
-
-    /*
-     * Find Tk's information about the display.
-     */
-
-    dispPtr = TkGetDisplay(display);
-
     /*
-     * Add a new chunk to the stack if the current chunk is full.
+     * This does nothing, because the XC-MISC extension takes care of 
+     * freeing XIDs for us.  It has been a standard X11 extension for
+     * about 15 years as of 2008.  Keith Packard and another X.org
+     * developer suggested that we remove the previous code that used:
+     * #define XLIB_ILLEGAL_ACCESS.
      */
-
-    stackPtr = dispPtr->idStackPtr;
-    if ((stackPtr == NULL) || (stackPtr->numUsed >= IDS_PER_STACK)) {
-	stackPtr = (TkIdStack *) ckalloc(sizeof(TkIdStack));
-	stackPtr->numUsed = 0;
-	stackPtr->dispPtr = dispPtr;
-	stackPtr->nextPtr = dispPtr->idStackPtr;
-	dispPtr->idStackPtr = stackPtr;
-    }
-
-    /*
-     * Add the id to the current chunk.
-     */
-
-    stackPtr->ids[stackPtr->numUsed] = xid;
-    stackPtr->numUsed++;
 }
-
-/*
- *----------------------------------------------------------------------
- *
- * TkFreeWindowId --
- *
- *	This function is invoked instead of TkFreeXId for window ids. See
- *	below for the reason why.
- *
- * Results:
- *	None.
- *
- * Side effects:
- *	The id given by w will eventually be freed, so that it can be reused
- *	for other resources.
- *
- * Design:
- *	Freeing window ids is very tricky because there could still be events
- *	pending for a window in the event queue (or even in the server) at the
- *	time the window is destroyed. If the window id were to get reused
- *	immediately for another window, old events could "drop in" on the new
- *	window, causing unexpected behavior.
- *
- *	Thus we have to wait to re-use a window id until we know that there
- *	are no events left for it. Right now this is done in two steps. First,
- *	we wait until we know that the server has seen the XDestroyWindow
- *	request, so we can be sure that it won't generate more events for the
- *	window and that any existing events are in our queue. Second, we make
- *	sure that there are no events whatsoever in our queue (this is
- *	conservative but safe).
- *
- *	The first step is done by remembering the request id of the
- *	XDestroyWindow request and using LastKnownRequestProcessed to see what
- *	events the server has processed. If multiple windows get destroyed at
- *	about the same time, we just remember the most recent request number
- *	for any of them (again, conservative but safe).
- *
- *	There are a few other complications as well. When Tk destroys a
- *	sub-tree of windows, it only issues a single XDestroyWindow call, at
- *	the very end for the root of the subtree. We can't free any of the
- *	window ids until the final XDestroyWindow call. To make sure that this
- *	happens, we have to keep track of deletions in progress, hence the
- *	need for the "destroyCount" field of the display.
- *
- *	One final problem. Some servers, like Sun X11/News servers still seem
- *	to have problems with ids getting reused too quickly. I'm not
- *	completely sure why this is a problem, but delaying the recycling of
- *	ids appears to eliminate it. Therefore, we wait an additional few
- *	seconds, even after "the coast is clear" before reusing the ids.
- *
- *----------------------------------------------------------------------
- */
-
-void
-TkFreeWindowId(
-    TkDisplay *dispPtr,		/* Display that w belongs to. */
-    Window w)			/* X identifier for window on dispPtr. */
-{
-    TkIdStack *stackPtr;
-
-    /*
-     * Put the window id on a separate stack of window ids, rather than the
-     * main stack, so it won't get reused right away. Add a new chunk to the
-     * stack if the current chunk is full.
-     */
-
-    stackPtr = dispPtr->windowStackPtr;
-    if ((stackPtr == NULL) || (stackPtr->numUsed >= IDS_PER_STACK)) {
-	stackPtr = (TkIdStack *) ckalloc(sizeof(TkIdStack));
-	stackPtr->numUsed = 0;
-	stackPtr->dispPtr = dispPtr;
-	stackPtr->nextPtr = dispPtr->windowStackPtr;
-	dispPtr->windowStackPtr = stackPtr;
-    }
-
-    /*
-     * Add the id to the current chunk.
-     */
-
-    stackPtr->ids[stackPtr->numUsed] = w;
-    stackPtr->numUsed++;
-
-    /*
-     * Schedule a call to WindowIdCleanup if one isn't already scheduled.
-     */
-
-    if (!dispPtr->idCleanupScheduled) {
-	dispPtr->idCleanupScheduled = Tcl_CreateTimerHandler(100,
-		WindowIdCleanup, dispPtr);
-    }
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * WindowIdCleanup --
- *
- *	See if we can now free up all the accumulated ids of deleted windows.
- *
- * Results:
- *	None.
- *
- * Side effects:
- *	If it's safe to move the window ids back to the main free list, we
- *	schedule this to happen after a few mores seconds of delay. If it's
- *	not safe to move them yet, a timer handler gets invoked to try again
- *	later.
- *
- *----------------------------------------------------------------------
- */
-
-static void
-WindowIdCleanup(
-    ClientData clientData)	/* Pointer to TkDisplay for display */
-{
-    TkDisplay *dispPtr = clientData;
-    int anyEvents, delta;
-    Tk_RestrictProc *oldProc;
-    ClientData oldData;
-    static Tcl_Time timeout = {0, 0};
-
-    dispPtr->idCleanupScheduled = (Tcl_TimerToken) 0;
-
-    /*
-     * See if it's safe to recycle the window ids. It's safe if:
-     * (a) no deletions are in progress.
-     * (b) the server has seen all of the requests up to the last
-     *     XDestroyWindow request.
-     * (c) there are no events in the event queue; the only way to test for
-     *     this right now is to create a restrict proc that will filter the
-     *     events, then call Tcl_DoOneEvent to see if the function gets
-     *     invoked.
-     */
-
-    if (dispPtr->destroyCount > 0) {
-	goto tryAgain;
-    }
-    delta = LastKnownRequestProcessed(dispPtr->display)
-	    - dispPtr->lastDestroyRequest;
-    if (delta < 0) {
-	XSync(dispPtr->display, False);
-    }
-    anyEvents = 0;
-    oldProc = Tk_RestrictEvents(CheckRestrictProc, &anyEvents, &oldData);
-    TkUnixDoOneXEvent(&timeout);
-    Tk_RestrictEvents(oldProc, oldData, &oldData);
-    if (anyEvents) {
-	goto tryAgain;
-    }
-
-    /*
-     * These ids look safe to recycle, but we still need to delay a bit more
-     * (see comments for TkFreeWindowId). Schedule the final freeing.
-     */
-
-    if (dispPtr->windowStackPtr != NULL) {
-	Tcl_CreateTimerHandler(5000, WindowIdCleanup2,
-		dispPtr->windowStackPtr);
-	dispPtr->windowStackPtr = NULL;
-    }
-    return;
-
-    /*
-     * It's still not safe to free up the ids. Try again a bit later.
-     */
-
-  tryAgain:
-    dispPtr->idCleanupScheduled = Tcl_CreateTimerHandler(500,
-	    WindowIdCleanup, dispPtr);
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * WindowIdCleanup2 --
- *
- *	This function is the last one in the chain that recycles window ids.
- *	It takes all of the ids indicated by its argument and adds them back
- *	to the main id free list.
- *
- * Results:
- *	None.
- *
- * Side effects:
- *	Window ids get added to the main free list for their display.
- *
- *----------------------------------------------------------------------
- */
-
-static void
-WindowIdCleanup2(
-    ClientData clientData)	/* Pointer to TkIdStack list. */
-{
-    TkIdStack *stackPtr = clientData;
-    TkIdStack *lastPtr;
-
-    lastPtr = stackPtr;
-    while (lastPtr->nextPtr != NULL) {
-	lastPtr = lastPtr->nextPtr;
-    }
-    lastPtr->nextPtr = stackPtr->dispPtr->idStackPtr;
-    stackPtr->dispPtr->idStackPtr = stackPtr;
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * CheckRestrictProc --
- *
- *	This function is a restrict function, called by Tcl_DoOneEvent to
- *	filter X events. All it does is to set a flag to indicate that there
- *	are X events present.
- *
- * Results:
- *	Sets the integer pointed to by the argument, then returns
- *	TK_DEFER_EVENT.
- *
- * Side effects:
- *	None.
- *
- *----------------------------------------------------------------------
- */
-
-static Tk_RestrictAction
-CheckRestrictProc(
-    ClientData clientData,	/* Pointer to flag to set. */
-    XEvent *eventPtr)		/* Event to filter; not used. */
-{
-    int *flag = clientData;
 
-    *flag = 1;
-    return TK_DEFER_EVENT;
-}
 
 /*
  *----------------------------------------------------------------------
@@ -524,44 +100,7 @@
     XFreePixmap(display, pixmap);
     Tk_FreeXId(display, (XID) pixmap);
 }
-
-/*
- *----------------------------------------------------------------------
- *
- * TkpWindowWasRecentlyDeleted --
- *
- *	Checks whether the window was recently deleted. This is called by the
- *	generic error handler to detect asynchronous notification of errors
- *	due to operations by Tk on a window that was already deleted by the
- *	server.
- *
- * Results:
- *	1 if the window was deleted recently, 0 otherwise.
- *
- * Side effects:
- *	None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-TkpWindowWasRecentlyDeleted(
-    Window win,			/* The window to check for. */
-    TkDisplay *dispPtr)		/* The window belongs to this display. */
-{
-    TkIdStack *stackPtr;
-    int i;
 
-    for (stackPtr = dispPtr->windowStackPtr; stackPtr != NULL;
-	    stackPtr = stackPtr->nextPtr) {
-	for (i = 0; i < stackPtr->numUsed; i++) {
-	    if ((Window) stackPtr->ids[i] == win) {
-		return 1;
-	    }
-	}
-    }
-    return 0;
-}
 
 /*
  *----------------------------------------------------------------------
Index: win/tkWinPort.h
===================================================================
RCS file: /cvsroot/tktoolkit/tk/win/tkWinPort.h,v
retrieving revision 1.10
diff -u -r1.10 tkWinPort.h
--- win/tkWinPort.h	28 Sep 2005 18:31:57 -0000	1.10
+++ win/tkWinPort.h	6 Aug 2008 01:27:36 -0000
@@ -85,8 +85,6 @@
  * under Windows.
  */
 
-#define TkFreeWindowId(dispPtr,w)
-#define TkInitXId(dispPtr)
 #define TkpCmapStressed(tkwin,colormap) (0)
 #define XFlush(display)
 #define XGrabServer(display)
Index: win/tkWinWindow.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/win/tkWinWindow.c,v
retrieving revision 1.17
diff -u -r1.17 tkWinWindow.c
--- win/tkWinWindow.c	26 Jul 2008 11:17:25 -0000	1.17
+++ win/tkWinWindow.c	6 Aug 2008 01:27:36 -0000
@@ -784,32 +784,6 @@
 }
 
 /*
- *----------------------------------------------------------------------
- *
- * TkpWindowWasRecentlyDeleted --
- *
- *	Determines whether we know if the window given as argument was
- *	recently deleted. Called by the generic code error handler to handle
- *	BadWindow events.
- *
- * Results:
- *	Always 0. We do not keep this information on Windows.
- *
- * Side effects:
- *	None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-TkpWindowWasRecentlyDeleted(
-    Window win,
-    TkDisplay *dispPtr)
-{
-    return 0;
-}
-
-/*
  * Local Variables:
  * mode: c
  * c-basic-offset: 4