summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2018-04-18 23:41:48 (GMT)
committerdgp <dgp@users.sourceforge.net>2018-04-18 23:41:48 (GMT)
commit8d0340e39e077c5577acacc1a175b5c412c8905b (patch)
tree58f066007ef2577ee4ef31055782da54c3de2f34
parent61f580bd36bb6b0f50e0d0735c1b72459434c8f5 (diff)
downloadtcl-8d0340e39e077c5577acacc1a175b5c412c8905b.zip
tcl-8d0340e39e077c5577acacc1a175b5c412c8905b.tar.gz
tcl-8d0340e39e077c5577acacc1a175b5c412c8905b.tar.bz2
Refactor error reporting when value is not an expected array variable name.
-rw-r--r--generic/tclVar.c56
1 files changed, 20 insertions, 36 deletions
diff --git a/generic/tclVar.c b/generic/tclVar.c
index f1c8669..92ae183 100644
--- a/generic/tclVar.c
+++ b/generic/tclVar.c
@@ -178,6 +178,7 @@ static void DeleteArray(Interp *iPtr, Tcl_Obj *arrayNamePtr,
Var *varPtr, int flags, int index);
static int LocateArray(Tcl_Interp *interp, Tcl_Obj *name,
Var **varPtrPtr, int *isArrayPtr);
+static int NotArrayError(Tcl_Interp *interp, Tcl_Obj *name);
static Tcl_Var ObjFindNamespaceVar(Tcl_Interp *interp,
Tcl_Obj *namePtr, Tcl_Namespace *contextNsPtr,
int flags);
@@ -294,6 +295,19 @@ LocateArray(
}
return TCL_OK;
}
+
+static int
+NotArrayError(
+ Tcl_Interp *interp,
+ Tcl_Obj *name)
+{
+ const char *nameStr = Tcl_GetString(name);
+
+ Tcl_SetObjResult(interp,
+ Tcl_ObjPrintf("\"%s\" isn't an array", nameStr));
+ Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "ARRAY", nameStr, NULL);
+ return TCL_ERROR;
+}
/*
*----------------------------------------------------------------------
@@ -3162,18 +3176,15 @@ ArrayStartSearchCmd(
return TCL_ERROR;
}
- varName = TclGetString(objv[1]);
if (!isArray) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "\"%s\" isn't an array", varName));
- Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "ARRAY", varName, NULL);
- return TCL_ERROR;
+ return NotArrayError(interp, objv[1]);
}
/*
* Make a new array search with a free name.
*/
+ varName = TclGetString(objv[1]);
searchPtr = ckalloc(sizeof(ArraySearch));
hPtr = Tcl_CreateHashEntry(&iPtr->varSearches, varPtr, &isNew);
if (isNew) {
@@ -3236,11 +3247,7 @@ ArrayAnyMoreCmd(
}
if (!isArray) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "\"%s\" isn't an array", TclGetString(varNameObj)));
- Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "ARRAY",
- TclGetString(varNameObj), NULL);
- return TCL_ERROR;
+ return NotArrayError(interp, varNameObj);
}
/*
@@ -3317,17 +3324,8 @@ ArrayNextElementCmd(
return TCL_ERROR;
}
- /*
- * Verify that it is indeed an array variable. This test comes after the
- * traces - the variable may actually become an array as an effect of said
- * traces.
- */
if (!isArray) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "\"%s\" isn't an array", TclGetString(varNameObj)));
- Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "ARRAY",
- TclGetString(varNameObj), NULL);
- return TCL_ERROR;
+ return NotArrayError(interp, varNameObj);
}
/*
@@ -3409,18 +3407,8 @@ ArrayDoneSearchCmd(
return TCL_ERROR;
}
- /*
- * Verify that it is indeed an array variable. This test comes after the
- * traces - the variable may actually become an array as an effect of said
- * traces.
- */
-
if (!isArray) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "\"%s\" isn't an array", TclGetString(varNameObj)));
- Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "ARRAY",
- TclGetString(varNameObj), NULL);
- return TCL_ERROR;
+ return NotArrayError(interp, varNameObj);
}
/*
@@ -3964,11 +3952,7 @@ ArrayStatsCmd(
}
if (!isArray) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "\"%s\" isn't an array", TclGetString(varNameObj)));
- Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "ARRAY",
- TclGetString(varNameObj), NULL);
- return TCL_ERROR;
+ return NotArrayError(interp, varNameObj);
}
stats = Tcl_HashStats((Tcl_HashTable *) varPtr->value.tablePtr);