summaryrefslogtreecommitdiffstats
path: root/generic/tclResult.c
diff options
context:
space:
mode:
authornijtmans <nijtmans>2010-03-27 22:40:13 (GMT)
committernijtmans <nijtmans>2010-03-27 22:40:13 (GMT)
commit419d5645c272033992ce63a5c714a64436e9f189 (patch)
treeea1e97233f6104789908e88752e680e1fa3959dc /generic/tclResult.c
parent05f862b0622794e90c90544b62b929ac0f47753c (diff)
downloadtcl-419d5645c272033992ce63a5c714a64436e9f189.zip
tcl-419d5645c272033992ce63a5c714a64436e9f189.tar.gz
tcl-419d5645c272033992ce63a5c714a64436e9f189.tar.bz2
[Freq 2974744] share exception codes (ObjType?)
Diffstat (limited to 'generic/tclResult.c')
-rw-r--r--generic/tclResult.c75
1 files changed, 53 insertions, 22 deletions
diff --git a/generic/tclResult.c b/generic/tclResult.c
index 3c329f1..4fcd285 100644
--- a/generic/tclResult.c
+++ b/generic/tclResult.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: tclResult.c,v 1.58 2010/03/24 15:33:14 dgp Exp $
+ * RCS: @(#) $Id: tclResult.c,v 1.59 2010/03/27 22:40:14 nijtmans Exp $
*/
#include "tclInt.h"
@@ -1292,12 +1292,61 @@ TclProcessReturn(
/*
*----------------------------------------------------------------------
*
+ * TclGetCompletionCodeFromObj --
+ *
+ * Parses Completion code Code
+ *
+ * Results:
+ * Returns TCL_ERROR if the value is an invalid completion code.
+ * Otherwise, returns TCL_OK, and writes the completion code to
+ * the pointer provided.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+TclGetCompletionCodeFromObj(
+ Tcl_Interp *interp, /* Current interpreter. */
+ Tcl_Obj *value,
+ int *code) /* Argument objects. */
+{
+ if (TCL_ERROR == TclGetIntFromObj(NULL, value, code)) {
+ static const char *const returnCodes[] = {
+ "ok", "error", "return", "break", "continue", NULL
+ };
+
+ if (TCL_ERROR == Tcl_GetIndexFromObj(NULL, value, returnCodes,
+ NULL, TCL_EXACT, code)) {
+ /*
+ * Value is not a legal return code.
+ */
+
+ if (interp != NULL) {
+ Tcl_ResetResult(interp);
+ Tcl_AppendResult(interp, "bad completion code \"",
+ TclGetString(value),
+ "\": must be ok, error, return, break, "
+ "continue, or an integer", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "RESULT", "ILLEGAL_CODE", NULL);
+ }
+ return TCL_ERROR;
+ }
+ }
+ return TCL_OK;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* TclMergeReturnOptions --
*
* Parses, checks, and stores the options to the [return] command.
*
* Results:
- * Returns TCL_ERROR is any of the option values are invalid. Otherwise,
+ * Returns TCL_ERROR if any of the option values are invalid. Otherwise,
* returns TCL_OK, and writes the returnOpts, code, and level values to
* the pointers provided.
*
@@ -1377,28 +1426,10 @@ TclMergeReturnOptions(
*/
Tcl_DictObjGet(NULL, returnOpts, keys[KEY_CODE], &valuePtr);
- if ((valuePtr != NULL)
- && (TCL_ERROR == TclGetIntFromObj(NULL, valuePtr, &code))) {
- static const char *const returnCodes[] = {
- "ok", "error", "return", "break", "continue", NULL
- };
-
- if (TCL_ERROR == Tcl_GetIndexFromObj(NULL, valuePtr, returnCodes,
- NULL, TCL_EXACT, &code)) {
- /*
- * Value is not a legal return code.
- */
-
- Tcl_ResetResult(interp);
- Tcl_AppendResult(interp, "bad completion code \"",
- TclGetString(valuePtr),
- "\": must be ok, error, return, break, "
- "continue, or an integer", NULL);
- Tcl_SetErrorCode(interp, "TCL", "RESULT", "ILLEGAL_CODE", NULL);
+ if (valuePtr != NULL) {
+ if (TCL_ERROR == TclGetCompletionCodeFromObj(interp, valuePtr, &code)) {
goto error;
}
- }
- if (valuePtr != NULL) {
Tcl_DictObjRemove(NULL, returnOpts, keys[KEY_CODE]);
}