summaryrefslogtreecommitdiffstats
path: root/generic/tclEnsemble.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2018-11-28 11:37:03 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2018-11-28 11:37:03 (GMT)
commit72fca75fb1c17d261f85df32515f54b526fd56eb (patch)
tree29977c68bc37fd785f1f8a4ac0cae684cc92dcf7 /generic/tclEnsemble.c
parent5c59a6a5059cf906985e489dafe86a4b07b9f919 (diff)
downloadtcl-72fca75fb1c17d261f85df32515f54b526fd56eb.zip
tcl-72fca75fb1c17d261f85df32515f54b526fd56eb.tar.gz
tcl-72fca75fb1c17d261f85df32515f54b526fd56eb.tar.bz2
Make the type casting in TclSpellFix less horrific. It's still bad, but it is no longer ghastly.
Diffstat (limited to 'generic/tclEnsemble.c')
-rw-r--r--generic/tclEnsemble.c51
1 files changed, 35 insertions, 16 deletions
diff --git a/generic/tclEnsemble.c b/generic/tclEnsemble.c
index 51cf61d..dfffe12 100644
--- a/generic/tclEnsemble.c
+++ b/generic/tclEnsemble.c
@@ -2071,8 +2071,8 @@ TclResetRewriteEnsemble(
*
* TclSpellFix --
*
- * Record a spelling correction that needs making in the
- * generation of the WrongNumArgs usage message.
+ * Record a spelling correction that needs making in the generation of
+ * the WrongNumArgs usage message.
*
* Results:
* None.
@@ -2089,9 +2089,10 @@ FreeER(
Tcl_Interp *interp,
int result)
{
- Tcl_Obj **tmp = (Tcl_Obj **)data[0];
+ Tcl_Obj **tmp = (Tcl_Obj **) data[0];
+ Tcl_Obj **store = (Tcl_Obj **) data[1];
- ckfree(tmp[2]);
+ ckfree(store);
ckfree(tmp);
return result;
}
@@ -2117,22 +2118,28 @@ TclSpellFix(
iPtr->ensembleRewrite.numInsertedObjs = 0;
}
- /* Compute the valid length of the ensemble root */
+ /*
+ * Compute the valid length of the ensemble root.
+ */
size = iPtr->ensembleRewrite.numRemovedObjs + objc
- iPtr->ensembleRewrite.numInsertedObjs;
search = iPtr->ensembleRewrite.sourceObjs;
if (search[0] == NULL) {
- /* Awful casting abuse here */
+ /*
+ * Awful casting abuse here!
+ */
+
search = (Tcl_Obj *const *) search[1];
}
if (badIdx < iPtr->ensembleRewrite.numInsertedObjs) {
/*
- * Misspelled value was inserted. We cannot directly jump
- * to the bad value, but have to search.
+ * Misspelled value was inserted. We cannot directly jump to the bad
+ * value, but have to search.
*/
+
idx = 1;
while (idx < size) {
if (search[idx] == bad) {
@@ -2144,7 +2151,10 @@ TclSpellFix(
return;
}
} else {
- /* Jump to the misspelled value. */
+ /*
+ * Jump to the misspelled value.
+ */
+
idx = iPtr->ensembleRewrite.numRemovedObjs + badIdx
- iPtr->ensembleRewrite.numInsertedObjs;
@@ -2156,17 +2166,26 @@ TclSpellFix(
search = iPtr->ensembleRewrite.sourceObjs;
if (search[0] == NULL) {
- store = (Tcl_Obj **)search[2];
+ store = (Tcl_Obj **) search[2];
} else {
Tcl_Obj **tmp = ckalloc(3 * sizeof(Tcl_Obj *));
- tmp[0] = NULL;
- tmp[1] = (Tcl_Obj *)iPtr->ensembleRewrite.sourceObjs;
- tmp[2] = (Tcl_Obj *)ckalloc(size * sizeof(Tcl_Obj *));
- memcpy(tmp[2], tmp[1], size*sizeof(Tcl_Obj *));
+ store = ckalloc(size * sizeof(Tcl_Obj *));
+ memcpy(store, iPtr->ensembleRewrite.sourceObjs,
+ size * sizeof(Tcl_Obj *));
+
+ /*
+ * Awful casting abuse here! Note that the NULL in the first element
+ * indicates that the initial objects are a raw array in the second
+ * element and the rewritten ones are a raw array in the third.
+ */
+
+ tmp[0] = NULL;
+ tmp[1] = (Tcl_Obj *) iPtr->ensembleRewrite.sourceObjs;
+ tmp[2] = (Tcl_Obj *) store;
iPtr->ensembleRewrite.sourceObjs = (Tcl_Obj *const *) tmp;
- TclNRAddCallback(interp, FreeER, tmp, NULL, NULL, NULL);
- store = (Tcl_Obj **)tmp[2];
+
+ TclNRAddCallback(interp, FreeER, tmp, store, NULL, NULL);
}
store[idx] = fix;