diff options
-rw-r--r-- | ChangeLog | 21 | ||||
-rw-r--r-- | doc/BackgdErr.3 | 51 | ||||
-rw-r--r-- | doc/interp.n | 46 | ||||
-rw-r--r-- | generic/tcl.decls | 7 | ||||
-rw-r--r-- | generic/tclDecls.h | 13 | ||||
-rw-r--r-- | generic/tclEvent.c | 8 | ||||
-rw-r--r-- | generic/tclIO.c | 6 | ||||
-rw-r--r-- | generic/tclIOCmd.c | 4 | ||||
-rw-r--r-- | generic/tclInt.decls | 9 | ||||
-rw-r--r-- | generic/tclIntDecls.h | 16 | ||||
-rw-r--r-- | generic/tclInterp.c | 6 | ||||
-rw-r--r-- | generic/tclStubInit.c | 5 | ||||
-rw-r--r-- | generic/tclTimer.c | 4 |
13 files changed, 123 insertions, 73 deletions
@@ -1,3 +1,24 @@ +2008-12-09 Don Porter <dgp@users.sourceforge.net> + + TIP #337 IMPLEMENTATION + + * doc/BackgdErr.3: Converted internal routine + * doc/interp.n: TclBackgroundException() into public routine + * generic/tcl.decls: Tcl_BackgroundException(). + * generic/tclEvent.c: + * generic/tclInt.decls: + + * generic/tclDecls.h: make genstubs + * generic/tclIntDecls.h: + * generic/tclStubInit.c: + + * generic/tclIO.c: Update callers. + * generic/tclIOCmd.c: + * generic/tclInterp.c: + * generic/tclTimer.c: + *** POTENTIAL INCOMPATIBILITY only for extensions using the converted + internal routine *** + 2008-12-09 Donal K. Fellows <dkf@users.sf.net> * generic/tclIO.c (ChanClose,ChanRead,...): Factored out some of the diff --git a/doc/BackgdErr.3 b/doc/BackgdErr.3 index 3309d25..ba53dc6 100644 --- a/doc/BackgdErr.3 +++ b/doc/BackgdErr.3 @@ -5,59 +5,76 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: BackgdErr.3,v 1.8 2007/12/13 15:22:30 dgp Exp $ +'\" RCS: @(#) $Id: BackgdErr.3,v 1.9 2008/12/09 20:16:29 dgp Exp $ '\" .so man.macros .TH Tcl_BackgroundError 3 7.5 Tcl "Tcl Library Procedures" .BS .SH NAME -Tcl_BackgroundError \- report Tcl error that occurred in background processing +Tcl_BackgroundException, Tcl_BackgroundError \- report Tcl exception that occurred in background processing .SH SYNOPSIS .nf \fB#include <tcl.h>\fR .sp +\fBTcl_BackgroundException\fR(\fIinterp, code\fR) +.sp \fBTcl_BackgroundError\fR(\fIinterp\fR) .SH ARGUMENTS .AS Tcl_Interp *interp .AP Tcl_Interp *interp in -Interpreter in which the error occurred. +Interpreter in which the exception occurred. +.AP int code in +The exceptional return code to be reported. .BE .SH DESCRIPTION .PP -This procedure is typically invoked when a Tcl error occurs during +This procedure is typically invoked when a Tcl exception (any +return code other than TCL_OK) occurs during .QW "background processing" such as executing an event handler. -When such an error occurs, the error condition is reported to Tcl +When such an exception occurs, the condition is reported to Tcl or to a widget or some other C code, and there is not usually any -obvious way for that code to report the error to the user. -In these cases the code calls \fBTcl_BackgroundError\fR with an +obvious way for that code to report the exception to the user. +In these cases the code calls \fBTcl_BackgroundException\fR with an \fIinterp\fR argument identifying the interpreter in which the -error occurred. At the time \fBTcl_BackgroundError\fR is invoked, -the interpreter's result is expected to contain an error message. -\fBTcl_BackgroundError\fR will invoke the command registered +exception occurred, and a \fIcode\fR argument holding the return +code value of the exception. The state of the interpreter, including +any error message in the interpreter result, and the values of +any entries in the return options dictionary, is captured and +saved. \fBTcl_BackgroundException\fR then arranges for the event +loop to invoke at some later time the command registered in that interpreter to handle background errors by the -\fBinterp bgerror\fR command. -The registered handler command is meant to report the error +\fBinterp bgerror\fR command, passing the captured values as +arguments. +The registered handler command is meant to report the exception in an application-specific fashion. The handler command receives two arguments, the result of the interp, and the return options of the interp at the time the error occurred. If the application registers no handler command, the default handler command will attempt to call \fBbgerror\fR to report the error. If an error condition arises while invoking the -handler command, then \fBTcl_BackgroundError\fR reports the +handler command, then \fBTcl_BackgroundException\fR reports the error itself by printing a message on the standard error file. .PP -\fBTcl_BackgroundError\fR does not invoke the handler command immediately +\fBTcl_BackgroundException\fR does not invoke the handler command immediately because this could potentially interfere with scripts that are in process at the time the error occurred. Instead, it invokes the handler command later as an idle callback. .PP -It is possible for many background errors to accumulate before -the handler command is invoked. When this happens, each of the errors -is processed in order. However, if the handle command returns a +It is possible for many background exceptions to accumulate before +the handler command is invoked. When this happens, each of the exceptions +is processed in order. However, if the handler command returns a break exception, then all remaining error reports for the interpreter are skipped. +.PP +The \fBTcl_BackgroundError\fR routine is an older and simpler interface +useful when the exception code reported is \fBTCL_ERROR\fR. It is +equivalent to: +.PP +.CS +Tcl_BackgroundException(interp, TCL_ERROR); +.CE .SH KEYWORDS background, bgerror, error, interp diff --git a/doc/interp.n b/doc/interp.n index c986519..8e06fd3 100644 --- a/doc/interp.n +++ b/doc/interp.n @@ -6,7 +6,7 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: interp.n,v 1.41 2008/10/17 10:22:25 dkf Exp $ +'\" RCS: @(#) $Id: interp.n,v 1.42 2008/12/09 20:16:29 dgp Exp $ '\" .so man.macros .TH interp n 8.6 Tcl "Tcl Built-In Commands" @@ -138,12 +138,12 @@ as the current names of the commands). .TP \fBinterp bgerror \fIpath\fR ?\fIcmdPrefix\fR? . -This command either gets or sets the current background error handler +This command either gets or sets the current background exception handler for the interpreter identified by \fIpath\fR. If \fIcmdPrefix\fR is -absent, the current background error handler is returned, and if it is +absent, the current background exception handler is returned, and if it is present, it is a list of words (of minimum length one) that describes -what to set the interpreter's background error to. See the -\fBBACKGROUND ERROR HANDLING\fR section for more details. +what to set the interpreter's background exception handler to. See the +\fBBACKGROUND EXCEPTION HANDLING\fR section for more details. .TP \fBinterp\fR \fBcancel \fR?\fB\-unwind\fR? ?\fB\-\|\-\fR? ?\fIpath\fR? ?\fIresult\fR? .VS 8.6 @@ -395,12 +395,12 @@ does not have to be equal to \fIsrcCmd\fR. .TP \fIslave \fBbgerror\fR ?\fIcmdPrefix\fR? . -This command either gets or sets the current background error handler +This command either gets or sets the current background exception handler for the \fIslave\fR interpreter. If \fIcmdPrefix\fR is -absent, the current background error handler is returned, and if it is +absent, the current background exception handler is returned, and if it is present, it is a list of words (of minimum length one) that describes -what to set the interpreter's background error to. See the -\fBBACKGROUND ERROR HANDLING\fR section for more details. +what to set the interpreter's background exception handler to. See the +\fBBACKGROUND EXCEPTION HANDLING\fR section for more details. .TP \fIslave \fBeval \fIarg \fR?\fIarg ..\fR? . @@ -748,8 +748,8 @@ This option (common for all limit types) specifies (if non-empty) a Tcl script to be executed in the global namespace of the interpreter reading and writing the option when the particular limit in the limited interpreter is exceeded. The callback may modify the limit on the interpreter if it wishes the limited -interpreter to continue executing. If the callback generates an error, it is -reported through the background error mechanism (see \fBBACKGROUND ERROR +interpreter to continue executing. If the callback generates an exception, it is +reported through the background exception mechanism (see \fBBACKGROUND EXCEPTION HANDLING\fR). Note that the callbacks defined by one interpreter are completely isolated from the callbacks defined by another, and that the order in which those callbacks are called is undefined. @@ -792,21 +792,23 @@ these conditions, it should hide the \fBinterp\fR command in the child and then use aliases and the \fBinterp invokehidden\fR subcommand to provide such access as it chooses to the \fBinterp\fR command to the limited master as necessary. -.SH "BACKGROUND ERROR HANDLING" +.SH "BACKGROUND EXCEPTION HANDLING" .PP -When an error happens in a situation where it cannot be reported directly up +When an exception happens in a situation where it cannot be reported directly up the stack (e.g. when processing events in an \fBupdate\fR or \fBvwait\fR call) -the error is instead reported through the background error handling mechanism. -Every interpreter has a background error handler registered; the default error +the exception is instead reported through the background exception handling mechanism. +Every interpreter has a background exception handler registered; the default exception handler arranges for the \fBbgerror\fR command in the interpreter's global -namespace to be called, but other error handlers may be installed and process -background errors in substantially different ways. +namespace to be called, but other exception handlers may be installed and process +background exceptions in substantially different ways. .PP -A background error handler consists of a non-empty list of words to which will +A background exception handler consists of a non-empty list of words to which will be appended two further words at invocation time. The first word will be the -error message string, and the second will a dictionary of return options (this -is also the sort of information that can be obtained by trapping a normal -error using \fBcatch\fR of course.) The resulting list will then be executed +interpreter result at time of the exception, typically an error message, +and the second will be the dictionary of return options at the time of +the exception. These are the same values that \fBcatch\fR can capture +when it controls script evaluation in a non-background situation. +The resulting list will then be executed in the interpreter's global namespace without further substitutions being performed. .SH CREDITS @@ -849,7 +851,7 @@ set i [\fBinterp create\fR] } .CE .SH "SEE ALSO" -bgerror(n), load(n), safe(n), Tcl_CreateSlave(3), Tcl_Eval(3) +bgerror(n), load(n), safe(n), Tcl_CreateSlave(3), Tcl_Eval(3), Tcl_BackgroundException(3) .SH KEYWORDS alias, master interpreter, safe interpreter, slave interpreter '\"Local Variables: diff --git a/generic/tcl.decls b/generic/tcl.decls index bdfe02c..9bf31ff 100644 --- a/generic/tcl.decls +++ b/generic/tcl.decls @@ -12,7 +12,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: tcl.decls,v 1.157 2008/12/05 21:38:47 dkf Exp $ +# RCS: @(#) $Id: tcl.decls,v 1.158 2008/12/09 20:16:29 dgp Exp $ library tcl @@ -2217,6 +2217,11 @@ declare 608 generic { int Tcl_InterpActive(Tcl_Interp *interp) } +# TIP 337 +declare 609 generic { + void Tcl_BackgroundException(Tcl_Interp *interp, int code) +} + ############################################################################## # Define the platform specific public Tcl interface. These functions are only diff --git a/generic/tclDecls.h b/generic/tclDecls.h index 7e1c6fd..525b613 100644 --- a/generic/tclDecls.h +++ b/generic/tclDecls.h @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclDecls.h,v 1.159 2008/12/05 21:40:38 dkf Exp $ + * RCS: @(#) $Id: tclDecls.h,v 1.160 2008/12/09 20:16:29 dgp Exp $ */ #ifndef _TCLDECLS @@ -3681,6 +3681,12 @@ EXTERN void Tcl_TransferResult (Tcl_Interp * sourceInterp, /* 608 */ EXTERN int Tcl_InterpActive (Tcl_Interp * interp); #endif +#ifndef Tcl_BackgroundException_TCL_DECLARED +#define Tcl_BackgroundException_TCL_DECLARED +/* 609 */ +EXTERN void Tcl_BackgroundException (Tcl_Interp * interp, + int code); +#endif typedef struct TclStubHooks { const struct TclPlatStubs *tclPlatStubs; @@ -4349,6 +4355,7 @@ typedef struct TclStubs { void (*tcl_SetErrorLine) (Tcl_Interp * interp, int value); /* 606 */ void (*tcl_TransferResult) (Tcl_Interp * sourceInterp, int result, Tcl_Interp * targetInterp); /* 607 */ int (*tcl_InterpActive) (Tcl_Interp * interp); /* 608 */ + void (*tcl_BackgroundException) (Tcl_Interp * interp, int code); /* 609 */ } TclStubs; #if defined(USE_TCL_STUBS) && !defined(USE_TCL_STUB_PROCS) @@ -6857,6 +6864,10 @@ extern const TclStubs *tclStubsPtr; #define Tcl_InterpActive \ (tclStubsPtr->tcl_InterpActive) /* 608 */ #endif +#ifndef Tcl_BackgroundException +#define Tcl_BackgroundException \ + (tclStubsPtr->tcl_BackgroundException) /* 609 */ +#endif #endif /* defined(USE_TCL_STUBS) && !defined(USE_TCL_STUB_PROCS) */ diff --git a/generic/tclEvent.c b/generic/tclEvent.c index 203dc5a..cbb0aad 100644 --- a/generic/tclEvent.c +++ b/generic/tclEvent.c @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclEvent.c,v 1.85 2008/10/26 18:34:04 dkf Exp $ + * RCS: @(#) $Id: tclEvent.c,v 1.86 2008/12/09 20:16:29 dgp Exp $ */ #include "tclInt.h" @@ -140,10 +140,10 @@ Tcl_BackgroundError( Tcl_Interp *interp) /* Interpreter in which an error has * occurred. */ { - TclBackgroundException(interp, TCL_ERROR); + Tcl_BackgroundException(interp, TCL_ERROR); } void -TclBackgroundException( +Tcl_BackgroundException( Tcl_Interp *interp, /* Interpreter in which an exception has * occurred. */ int code) /* The exception code value */ @@ -353,7 +353,7 @@ TclDefaultBgErrorHandlerObjCmd( if (code == TCL_OK) { /* * Somehow we got to exception handling with no exception. - * (Pass TCL_OK to TclBackgroundException()?) + * (Pass TCL_OK to Tcl_BackgroundException()?) * Just return without doing anything. */ return TCL_OK; diff --git a/generic/tclIO.c b/generic/tclIO.c index 1a2bbfb..09ca6fa 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclIO.c,v 1.152 2008/12/09 14:09:14 dkf Exp $ + * RCS: @(#) $Id: tclIO.c,v 1.153 2008/12/09 20:16:29 dgp Exp $ */ #include "tclInt.h" @@ -8307,7 +8307,7 @@ TclChannelEventScriptInvoker( if (chanPtr->typePtr != NULL) { DeleteScriptRecord(interp, chanPtr, mask); } - TclBackgroundException(interp, result); + Tcl_BackgroundException(interp, result); } Tcl_Release(interp); } @@ -8812,7 +8812,7 @@ CopyData( } code = Tcl_EvalObjEx(interp, cmdPtr, TCL_EVAL_GLOBAL); if (code != TCL_OK) { - TclBackgroundException(interp, code); + Tcl_BackgroundException(interp, code); result = TCL_ERROR; } TclDecrRefCount(cmdPtr); diff --git a/generic/tclIOCmd.c b/generic/tclIOCmd.c index dbc9bb1..dbf6b2c 100644 --- a/generic/tclIOCmd.c +++ b/generic/tclIOCmd.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclIOCmd.c,v 1.59 2008/10/16 22:34:19 nijtmans Exp $ + * RCS: @(#) $Id: tclIOCmd.c,v 1.60 2008/12/09 20:16:29 dgp Exp $ */ #include "tclInt.h" @@ -1334,7 +1334,7 @@ AcceptCallbackProc( result = Tcl_VarEval(interp, script, " ", Tcl_GetChannelName(chan), " ", address, " ", portBuf, NULL); if (result != TCL_OK) { - TclBackgroundException(interp, result); + Tcl_BackgroundException(interp, result); Tcl_UnregisterChannel(interp, chan); } diff --git a/generic/tclInt.decls b/generic/tclInt.decls index 221fb34..1853c5c 100644 --- a/generic/tclInt.decls +++ b/generic/tclInt.decls @@ -13,7 +13,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: tclInt.decls,v 1.129 2008/10/22 20:23:59 nijtmans Exp $ +# RCS: @(#) $Id: tclInt.decls,v 1.130 2008/12/09 20:16:29 dgp Exp $ library tcl @@ -933,9 +933,10 @@ declare 235 generic { } -declare 236 generic { - void TclBackgroundException(Tcl_Interp *interp, int code) -} +# TIP 337 made this one public +#declare 236 generic { +# void TclBackgroundException(Tcl_Interp *interp, int code) +#} # TIP #285: Script cancellation support. declare 237 generic { diff --git a/generic/tclIntDecls.h b/generic/tclIntDecls.h index ab08e3b..a511988 100644 --- a/generic/tclIntDecls.h +++ b/generic/tclIntDecls.h @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclIntDecls.h,v 1.125 2008/10/22 20:23:59 nijtmans Exp $ + * RCS: @(#) $Id: tclIntDecls.h,v 1.126 2008/12/09 20:16:30 dgp Exp $ */ #ifndef _TCLINTDECLS @@ -1059,12 +1059,7 @@ EXTERN Var * TclVarHashCreateVar (TclVarHashTable * tablePtr, EXTERN void TclInitVarHashTable (TclVarHashTable * tablePtr, Namespace * nsPtr); #endif -#ifndef TclBackgroundException_TCL_DECLARED -#define TclBackgroundException_TCL_DECLARED -/* 236 */ -EXTERN void TclBackgroundException (Tcl_Interp * interp, - int code); -#endif +/* Slot 236 is reserved */ #ifndef TclResetCancellation_TCL_DECLARED #define TclResetCancellation_TCL_DECLARED /* 237 */ @@ -1369,7 +1364,7 @@ typedef struct TclIntStubs { void (*tclGetSrcInfoForPc) (CmdFrame * contextPtr); /* 233 */ Var * (*tclVarHashCreateVar) (TclVarHashTable * tablePtr, const char * key, int * newPtr); /* 234 */ void (*tclInitVarHashTable) (TclVarHashTable * tablePtr, Namespace * nsPtr); /* 235 */ - void (*tclBackgroundException) (Tcl_Interp * interp, int code); /* 236 */ + void *reserved236; int (*tclResetCancellation) (Tcl_Interp * interp, int force); /* 237 */ int (*tclNRInterpProc) (ClientData clientData, Tcl_Interp * interp, int objc, Tcl_Obj *const objv[]); /* 238 */ int (*tclNRInterpProcCore) (Tcl_Interp * interp, Tcl_Obj * procNameObj, int skip, ProcErrorProc errorProc); /* 239 */ @@ -2110,10 +2105,7 @@ extern const TclIntStubs *tclIntStubsPtr; #define TclInitVarHashTable \ (tclIntStubsPtr->tclInitVarHashTable) /* 235 */ #endif -#ifndef TclBackgroundException -#define TclBackgroundException \ - (tclIntStubsPtr->tclBackgroundException) /* 236 */ -#endif +/* Slot 236 is reserved */ #ifndef TclResetCancellation #define TclResetCancellation \ (tclIntStubsPtr->tclResetCancellation) /* 237 */ diff --git a/generic/tclInterp.c b/generic/tclInterp.c index 939d3a0..ac8cbb9 100644 --- a/generic/tclInterp.c +++ b/generic/tclInterp.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclInterp.c,v 1.98 2008/12/05 14:27:36 dkf Exp $ + * RCS: @(#) $Id: tclInterp.c,v 1.99 2008/12/09 20:16:30 dgp Exp $ */ #include "tclInt.h" @@ -3765,7 +3765,7 @@ TimeLimitCallback( code = Tcl_LimitCheck(interp); if (code != TCL_OK) { Tcl_AddErrorInfo(interp, "\n (while waiting for event)"); - TclBackgroundException(interp, code); + Tcl_BackgroundException(interp, code); } Tcl_Release(interp); } @@ -3933,7 +3933,7 @@ CallScriptLimitCallback( code = Tcl_EvalObjEx(limitCBPtr->interp, limitCBPtr->scriptObj, TCL_EVAL_GLOBAL); if (code != TCL_OK && !Tcl_InterpDeleted(limitCBPtr->interp)) { - TclBackgroundException(limitCBPtr->interp, code); + Tcl_BackgroundException(limitCBPtr->interp, code); } Tcl_Release(limitCBPtr->interp); } diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c index 6fdbc0d..f858b14 100644 --- a/generic/tclStubInit.c +++ b/generic/tclStubInit.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclStubInit.c,v 1.170 2008/12/05 21:40:38 dkf Exp $ + * RCS: @(#) $Id: tclStubInit.c,v 1.171 2008/12/09 20:16:30 dgp Exp $ */ #include "tclInt.h" @@ -305,7 +305,7 @@ static const TclIntStubs tclIntStubs = { TclGetSrcInfoForPc, /* 233 */ TclVarHashCreateVar, /* 234 */ TclInitVarHashTable, /* 235 */ - TclBackgroundException, /* 236 */ + NULL, /* 236 */ TclResetCancellation, /* 237 */ TclNRInterpProc, /* 238 */ TclNRInterpProcCore, /* 239 */ @@ -1134,6 +1134,7 @@ static const TclStubs tclStubs = { Tcl_SetErrorLine, /* 606 */ Tcl_TransferResult, /* 607 */ Tcl_InterpActive, /* 608 */ + Tcl_BackgroundException, /* 609 */ }; /* !END!: Do not edit above this line. */ diff --git a/generic/tclTimer.c b/generic/tclTimer.c index e254830..03e01fa 100644 --- a/generic/tclTimer.c +++ b/generic/tclTimer.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclTimer.c,v 1.36 2008/10/26 18:34:04 dkf Exp $ + * RCS: @(#) $Id: tclTimer.c,v 1.37 2008/12/09 20:16:30 dgp Exp $ */ #include "tclInt.h" @@ -1177,7 +1177,7 @@ AfterProc( result = Tcl_EvalObjEx(interp, afterPtr->commandPtr, TCL_EVAL_GLOBAL); if (result != TCL_OK) { Tcl_AddErrorInfo(interp, "\n (\"after\" script)"); - TclBackgroundException(interp, result); + Tcl_BackgroundException(interp, result); } Tcl_Release((ClientData) interp); |