From 72fca75fb1c17d261f85df32515f54b526fd56eb Mon Sep 17 00:00:00 2001 From: dkf Date: Wed, 28 Nov 2018 11:37:03 +0000 Subject: Make the type casting in TclSpellFix less horrific. It's still bad, but it is no longer ghastly. --- generic/tclEnsemble.c | 51 +++++++++++++++++++++++++++++++++++---------------- 1 file 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; -- cgit v0.12 From b3f8bdaff2101f6b235b59ab3157f45d7cc314c3 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 29 Nov 2018 21:06:45 +0000 Subject: relax the timings of 2 tests, which incidentally fail on Travis CI --- tests/event.test | 2 +- tests/timer.test | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/event.test b/tests/event.test index 207c799..67a980b 100644 --- a/tests/event.test +++ b/tests/event.test @@ -527,7 +527,7 @@ test event-11.4 {Tcl_VwaitCmd procedure} -setup { } -body { after 100 {set x x-done} after 200 {set y y-done} - after 300 {set z z-done} + after 400 {set z z-done} after idle {set q q-done} set x before set y before diff --git a/tests/timer.test b/tests/timer.test index ab6efc9..740d05e 100644 --- a/tests/timer.test +++ b/tests/timer.test @@ -205,11 +205,11 @@ test timer-6.4 {Tcl_AfterCmd procedure, ms argument} { } {before after} test timer-6.5 {Tcl_AfterCmd procedure, ms argument} { set x before - after 300 set x after + after 400 set x after after 200 update set y $x - after 200 + after 400 update list $y $x } {before after} -- cgit v0.12