Overview
| Artifact ID: | 6ad392168b5d029986d85b62bc4c6243fd097b90 |
|---|---|
| Ticket: | 2919042fffffffffffffffffffffffffffffffff
Exit reform lost valgrindability |
| User & Date: | juddgilbert on 2011-04-21 05:39:38 |
Changes
- icomment:
strike that, it won't let me attach the files so I'll paste them in. tlcBasic.rej *************** *** 1353,1366 **** Tcl_HashTable *hTablePtr; ResolverScheme *resPtr, *nextResPtr; int i; /* - * Punt if there is an error in the Tcl_Release/Tcl_Preserve matchup. */ - if (iPtr->numLevels > 0) { Tcl_Panic("DeleteInterpProc called with active evals"); } /* * The interpreter should already be marked deleted; otherwise how did we --- 1353,1367 ---- Tcl_HashTable *hTablePtr; ResolverScheme *resPtr, *nextResPtr; int i; /* + * Punt if there is an error in the Tcl_Release/Tcl_Preserve matchup, + * unless we are exiting. */ + if ((iPtr->numLevels > 0) && !TclInExit()) { Tcl_Panic("DeleteInterpProc called with active evals"); } /* * The interpreter should already be marked deleted; otherwise how did we *************** *** 1480,1490 **** /* * Pop the root frame pointer and finish deleting the global * namespace. The order is important [Bug 1658572]. */ - if (iPtr->framePtr != iPtr->rootFramePtr) { Tcl_Panic("DeleteInterpProc: popping rootCallFrame with other frames on top"); } Tcl_PopCallFrame(interp); ckfree(iPtr->rootFramePtr); iPtr->rootFramePtr = NULL; --- 1481,1491 ---- /* * Pop the root frame pointer and finish deleting the global * namespace. The order is important [Bug 1658572]. */ + if ((iPtr->framePtr != iPtr->rootFramePtr) && !TclInExit()) { Tcl_Panic("DeleteInterpProc: popping rootCallFrame with other frames on top"); } Tcl_PopCallFrame(interp); ckfree(iPtr->rootFramePtr); iPtr->rootFramePtr = NULL; *************** *** 1601,1624 **** * Location stack for uplevel/eval/... scripts which were passed through * proc arguments. Actually we track all arguments as we do not and cannot * know which arguments will be used as scripts and which will not. */ - if (iPtr->lineLAPtr->numEntries) { /* * When the interp goes away we have nothing on the stack, so there * are no arguments, so this table has to be empty. */ Tcl_Panic("Argument location tracking table not empty"); } Tcl_DeleteHashTable(iPtr->lineLAPtr); - ckfree(iPtr->lineLAPtr); iPtr->lineLAPtr = NULL; - if (iPtr->lineLABCPtr->numEntries) { /* * When the interp goes away we have nothing on the stack, so there * are no arguments, so this table has to be empty. */ --- 1602,1625 ---- * Location stack for uplevel/eval/... scripts which were passed through * proc arguments. Actually we track all arguments as we do not and cannot * know which arguments will be used as scripts and which will not. */ + if (iPtr->lineLAPtr->numEntries && !TclInExit()) { /* * When the interp goes away we have nothing on the stack, so there * are no arguments, so this table has to be empty. */ Tcl_Panic("Argument location tracking table not empty"); } Tcl_DeleteHashTable(iPtr->lineLAPtr); + ckfree((char *) iPtr->lineLAPtr); iPtr->lineLAPtr = NULL; + if (iPtr->lineLABCPtr->numEntries && !TclInExit()) { /* * When the interp goes away we have nothing on the stack, so there * are no arguments, so this table has to be empty. */ tclEvent.rej *************** *** 951,981 **** */ currentAppExitPtr(INT2PTR(status)); Tcl_Panic("AppExitProc returned unexpectedly"); } else { - /* - * Use default handling. - */ - - InvokeExitHandlers(); - - /* - * Ensure the thread-specific data is initialised as it is used in - * Tcl_FinalizeThread() - */ - - (void) TCL_TSD_INIT(&dataKey); - - /* - * Now finalize the calling thread only (others are not safely - * reachable). Among other things, this triggers a flush of the - * Tcl_Channels that may have data enqueued. - */ - - Tcl_FinalizeThread(); - TclpExit(status); Tcl_Panic("OS exit failed!"); } } --- 951,1004 ---- */ currentAppExitPtr(INT2PTR(status)); Tcl_Panic("AppExitProc returned unexpectedly"); } else { + const char *fin; + Tcl_DString ds; + int finalize = 0; + + fin = TclGetEnv("TCL_FINALIZE_ON_EXIT", &ds); + finalize = ((fin != NULL) && strcmp(fin, "0")); + if (fin != NULL) { + Tcl_DStringFree(&ds); + } + + #ifdef PURIFY + finalize = 1; + #endif + if (finalize) { + + /* + * Thorough finalization for Valgrind et al. + */ + + Tcl_Finalize(); + + } else { + + /* + * Fast and deterministic exit (default behavior) + */ + + InvokeExitHandlers(); + + /* + * Ensure the thread-specific data is initialised as it is used in + * Tcl_FinalizeThread() + */ + + (void) TCL_TSD_INIT(&dataKey); + + /* + * Now finalize the calling thread only (others are not safely + * reachable). Among other things, this triggers a flush of the + * Tcl_Channels that may have data enqueued. + */ + + Tcl_FinalizeThread(); + } TclpExit(status); Tcl_Panic("OS exit failed!"); } } tclExecute.rej *************** *** 932,945 **** DeleteExecStack(tmpPtr); } TclDecrRefCount(eePtr->constants[0]); TclDecrRefCount(eePtr->constants[1]); - if (eePtr->callbackPtr) { - Tcl_Panic("Deleting execEnv with pending NRE callbacks!"); } - if (eePtr->corPtr) { Tcl_Panic("Deleting execEnv with existing coroutine"); } ckfree(eePtr); } --- 936,949 ---- DeleteExecStack(tmpPtr); } TclDecrRefCount(eePtr->constants[0]); TclDecrRefCount(eePtr->constants[1]); + if (eePtr->callbackPtr && !cachedInExit) { + Tcl_Panic("Deleting execEnv with pending TEOV callbacks!"); } + if (eePtr->corPtr && !cachedInExit) { Tcl_Panic("Deleting execEnv with existing coroutine"); } ckfree(eePtr); } tclMain.rej *************** *** 123,132 **** */ MODULE_SCOPE Tcl_MainLoopProc *TclGetMainLoop(void); static voidPrompt(Tcl_Interp *interp, InteractiveState *isPtr); static voidStdinProc(ClientData clientData, int mask); #ifndef TCL_ASCII_MAIN static Tcl_ThreadDataKey dataKey; /* *---------------------------------------------------------------------- --- 123,133 ---- */ MODULE_SCOPE Tcl_MainLoopProc *TclGetMainLoop(void); static voidPrompt(Tcl_Interp *interp, InteractiveState *isPtr); static voidStdinProc(ClientData clientData, int mask); + static void FreeMainInterp(ClientData clientData); #ifndef TCL_ASCII_MAIN static Tcl_ThreadDataKey dataKey; /* *---------------------------------------------------------------------- *************** *** 386,395 **** } if (Tcl_LimitExceeded(interp)) { goto done; } /* * Invoke the script specified on the command line, if any. Must fetch it * again, as the appInitProc might have reset it. */ --- 387,402 ---- } if (Tcl_LimitExceeded(interp)) { goto done; } + /* + * Arrange for final deletion of the main interp + */ + // ARGH Munchhausen effect + Tcl_CreateExitHandler(FreeMainInterp, (ClientData)interp); + /* * Invoke the script specified on the command line, if any. Must fetch it * again, as the appInitProc might have reset it. */ *************** *** 600,629 **** Tcl_IncrRefCount(cmd); Tcl_EvalObjEx(interp, cmd, TCL_EVAL_GLOBAL); Tcl_DecrRefCount(cmd); } - /* * If Tcl_EvalObjEx returns, trying to eval [exit], something unusual * is happening. Maybe interp has been deleted; maybe [exit] was * redefined, maybe we've blown up because of an exceeded limit. We * still want to cleanup and exit. */ - - if (!Tcl_InterpDeleted(interp)) { - Tcl_DeleteInterp(interp); - } - } - Tcl_SetStartupScript(NULL, NULL); - - /* - * If we get here, the master interp has been deleted. Allow its - * destruction with the last matching Tcl_Release. - */ - - Tcl_Release(interp); Tcl_Exit(exitCode); } #ifndef UNICODE void --- 607,623 ---- Tcl_IncrRefCount(cmd); Tcl_EvalObjEx(interp, cmd, TCL_EVAL_GLOBAL); Tcl_DecrRefCount(cmd); } + } /* * If Tcl_EvalObjEx returns, trying to eval [exit], something unusual * is happening. Maybe interp has been deleted; maybe [exit] was * redefined, maybe we've blown up because of an exceeded limit. We * still want to cleanup and exit. */ Tcl_Exit(exitCode); } #ifndef UNICODE void *************** *** 876,889 **** chan = Tcl_GetStdChannel(TCL_STDOUT); if (chan != NULL) { Tcl_Flush(chan); } isPtr->prompt = PROMPT_NONE; } /* * Local Variables: * mode: c * c-basic-offset: 4 * fill-column: 78 * End: */ --- 870,909 ---- chan = Tcl_GetStdChannel(TCL_STDOUT); if (chan != NULL) { Tcl_Flush(chan); } isPtr->prompt = PROMPT_NONE; + } + + /* + *---------------------------------------------------------------------- + * + * FreeMainInterp -- + * + *Exit handler used to cleanup the main interpreter and ancillary startup + *script storage at exit. + * + *---------------------------------------------------------------------- + */ + + static void + FreeMainInterp( + ClientData clientData) + { + Tcl_Interp *interp = (Tcl_Interp *) clientData; + + //if (TclInExit()) return; + + if (!Tcl_InterpDeleted(interp)) { + Tcl_DeleteInterp(interp); + } + Tcl_SetStartupScript(NULL, NULL); + Tcl_Release(interp); } /* * Local Variables: * mode: c * c-basic-offset: 4 * fill-column: 78 * End: */ - login: "juddgilbert"
- mimetype: "text/plain"
- username: "juddgilbert"