diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2010-03-05 14:34:03 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2010-03-05 14:34:03 (GMT) |
commit | b501910778714de837dc4367698256e996737e9b (patch) | |
tree | f2dc6d4861ea238a538f41c4306249dad1ac3ea5 /generic/tclBasic.c | |
parent | f7a64b3a111891d5f7f79ce94bbb37abedd30176 (diff) | |
download | tcl-b501910778714de837dc4367698256e996737e9b.zip tcl-b501910778714de837dc4367698256e996737e9b.tar.gz tcl-b501910778714de837dc4367698256e996737e9b.tar.bz2 |
Code Audit results:
* use do { ... } while (0) in macros
* avoid shadowing one local variable with another
* use clearer 'foo.bar++;' instead of '++foo.bar;' where result not
required (i.e., semantically equivalent)
* follow Engineering Manual rules on spacing and declarations
Diffstat (limited to 'generic/tclBasic.c')
-rw-r--r-- | generic/tclBasic.c | 144 |
1 files changed, 74 insertions, 70 deletions
diff --git a/generic/tclBasic.c b/generic/tclBasic.c index fde9b1b..b9282ae 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -16,7 +16,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclBasic.c,v 1.447 2010/02/24 10:45:04 dkf Exp $ + * RCS: @(#) $Id: tclBasic.c,v 1.448 2010/03/05 14:34:03 dkf Exp $ */ #include "tclInt.h" @@ -1310,6 +1310,7 @@ DeleteInterpProc( Tcl_HashSearch search; Tcl_HashTable *hTablePtr; ResolverScheme *resPtr, *nextResPtr; + int i; /* * Punt if there is an error in the Tcl_Release/Tcl_Preserve matchup. @@ -1503,89 +1504,87 @@ DeleteInterpProc( * contents. */ - { - Tcl_HashEntry *hPtr; - Tcl_HashSearch hSearch; - int i; - - for (hPtr = Tcl_FirstHashEntry(iPtr->linePBodyPtr, &hSearch); - hPtr != NULL; - hPtr = Tcl_NextHashEntry(&hSearch)) { - CmdFrame *cfPtr = Tcl_GetHashValue(hPtr); + for (hPtr = Tcl_FirstHashEntry(iPtr->linePBodyPtr, &search); + hPtr != NULL; + hPtr = Tcl_NextHashEntry(&search)) { + CmdFrame *cfPtr = Tcl_GetHashValue(hPtr); - if (cfPtr->type == TCL_LOCATION_SOURCE) { - Tcl_DecrRefCount(cfPtr->data.eval.path); - } - ckfree((char *) cfPtr->line); - ckfree((char *) cfPtr); - Tcl_DeleteHashEntry(hPtr); + if (cfPtr->type == TCL_LOCATION_SOURCE) { + Tcl_DecrRefCount(cfPtr->data.eval.path); } - Tcl_DeleteHashTable(iPtr->linePBodyPtr); - ckfree((char *) iPtr->linePBodyPtr); - iPtr->linePBodyPtr = NULL; + ckfree((char *) cfPtr->line); + ckfree((char *) cfPtr); + Tcl_DeleteHashEntry(hPtr); + } + Tcl_DeleteHashTable(iPtr->linePBodyPtr); + ckfree((char *) iPtr->linePBodyPtr); + iPtr->linePBodyPtr = NULL; - /* - * See also tclCompile.c, TclCleanupByteCode - */ + /* + * See also tclCompile.c, TclCleanupByteCode + */ - for (hPtr = Tcl_FirstHashEntry(iPtr->lineBCPtr, &hSearch); - hPtr != NULL; - hPtr = Tcl_NextHashEntry(&hSearch)) { - ExtCmdLoc *eclPtr = Tcl_GetHashValue(hPtr); + for (hPtr = Tcl_FirstHashEntry(iPtr->lineBCPtr, &search); + hPtr != NULL; + hPtr = Tcl_NextHashEntry(&search)) { + ExtCmdLoc *eclPtr = Tcl_GetHashValue(hPtr); - if (eclPtr->type == TCL_LOCATION_SOURCE) { - Tcl_DecrRefCount(eclPtr->path); - } - for (i=0; i< eclPtr->nuloc; i++) { - ckfree((char *) eclPtr->loc[i].line); - } + if (eclPtr->type == TCL_LOCATION_SOURCE) { + Tcl_DecrRefCount(eclPtr->path); + } + for (i=0; i< eclPtr->nuloc; i++) { + ckfree((char *) eclPtr->loc[i].line); + } - if (eclPtr->loc != NULL) { - ckfree((char *) eclPtr->loc); - } + if (eclPtr->loc != NULL) { + ckfree((char *) eclPtr->loc); + } - Tcl_DeleteHashTable(&eclPtr->litInfo); + Tcl_DeleteHashTable(&eclPtr->litInfo); - ckfree((char *) eclPtr); - Tcl_DeleteHashEntry(hPtr); - } - Tcl_DeleteHashTable(iPtr->lineBCPtr); - ckfree((char *) iPtr->lineBCPtr); - iPtr->lineBCPtr = NULL; + ckfree((char *) eclPtr); + Tcl_DeleteHashEntry(hPtr); + } + Tcl_DeleteHashTable(iPtr->lineBCPtr); + ckfree((char *) iPtr->lineBCPtr); + iPtr->lineBCPtr = NULL; + + /* + * Location stack for uplevel/eval/... scripts which were passed through + * proc arguments. Actually we track all arguments as we do not and cannot + * know which arguments will be used as scripts and which will not. + */ + if (iPtr->lineLAPtr->numEntries) { /* - * Location stack for uplevel/eval/... scripts which were passed - * through proc arguments. Actually we track all arguments as we do - * not and cannot know which arguments will be used as scripts and - * which will not. + * When the interp goes away we have nothing on the stack, so there + * are no arguments, so this table has to be empty. */ - if (iPtr->lineLAPtr->numEntries) { - /* - * When the interp goes away we have nothing on the stack, so - * there are no arguments, so this table has to be empty. - */ + Tcl_Panic("Argument location tracking table not empty"); + } - Tcl_Panic("Argument location tracking table not empty"); - } + Tcl_DeleteHashTable(iPtr->lineLAPtr); + ckfree((char *) iPtr->lineLAPtr); + iPtr->lineLAPtr = NULL; - Tcl_DeleteHashTable(iPtr->lineLAPtr); - ckfree((char *) iPtr->lineLAPtr); - iPtr->lineLAPtr = NULL; + if (iPtr->lineLABCPtr->numEntries) { + /* + * When the interp goes away we have nothing on the stack, so there + * are no arguments, so this table has to be empty. + */ - if (iPtr->lineLABCPtr->numEntries) { - /* - * When the interp goes away we have nothing on the stack, so - * there are no arguments, so this table has to be empty. - */ + Tcl_Panic("Argument location tracking table not empty"); + } - Tcl_Panic("Argument location tracking table not empty"); - } + Tcl_DeleteHashTable(iPtr->lineLABCPtr); + ckfree((char *) iPtr->lineLABCPtr); + iPtr->lineLABCPtr = NULL; - Tcl_DeleteHashTable(iPtr->lineLABCPtr); - ckfree((char *) iPtr->lineLABCPtr); - iPtr->lineLABCPtr = NULL; - } + /* + * Squelch the tables of traces on variables and searches over arrays in + * the in the interpreter. + */ Tcl_DeleteHashTable(&iPtr->varTraces); Tcl_DeleteHashTable(&iPtr->varSearches); @@ -7423,12 +7422,17 @@ ExprAbsFunc( goto unChanged; } else if (l == (long)0) { const char *string = objv[1]->bytes; + if (!string) { - /* There is no string representation, so internal one is correct */ + /* + * There is no string representation, so internal one is + * correct. + */ + goto unChanged; } while (isspace(UCHAR(*string))) { - ++string; + string++; } if (*string != '-') { goto unChanged; @@ -7927,7 +7931,7 @@ MathFuncWrongNumArgs( const char *tail = name + strlen(name); while (tail > name+1) { - --tail; + tail--; if (*tail == ':' && tail[-1] == ':') { name = tail+1; break; |