diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2009-12-08 14:18:34 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2009-12-08 14:18:34 (GMT) |
commit | 812ad65c885e1e9c369e1704cb19e7f3dea8e162 (patch) | |
tree | 33c81e083600e8a09b89119a0db351dd30d76207 /generic/tclBasic.c | |
parent | 4fcf95fb18b11889ef2fbd9ed8a4ae6a04756425 (diff) | |
download | tcl-812ad65c885e1e9c369e1704cb19e7f3dea8e162.zip tcl-812ad65c885e1e9c369e1704cb19e7f3dea8e162.tar.gz tcl-812ad65c885e1e9c369e1704cb19e7f3dea8e162.tar.bz2 |
Small corrections (enforcing ANSI style declarations, etc.)
Diffstat (limited to 'generic/tclBasic.c')
-rw-r--r-- | generic/tclBasic.c | 278 |
1 files changed, 145 insertions, 133 deletions
diff --git a/generic/tclBasic.c b/generic/tclBasic.c index ae6469f..11da4cc 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.416 2009/12/07 19:03:15 msofer Exp $ + * RCS: @(#) $Id: tclBasic.c,v 1.417 2009/12/08 14:18:34 dkf Exp $ */ #include "tclInt.h" @@ -31,11 +31,9 @@ #include <assert.h> #endif - #define INTERP_STACK_INITIAL_SIZE 2000 #define CORO_STACK_INITIAL_SIZE 200 - /* * Determine whether we're using IEEE floating point */ @@ -2183,7 +2181,7 @@ Tcl_CreateObjCommand( * stuck in an infinite loop). */ - ckfree(Tcl_GetHashValue(hPtr)); + ckfree(Tcl_GetHashValue(hPtr)); } } else { /* @@ -3173,6 +3171,7 @@ CancelEvalProc( * Create the result object now so that Tcl_Canceled can avoid * locking the cancelLock mutex. */ + if (cancelInfo->result != NULL) { Tcl_SetStringObj(iPtr->asyncCancelMsg, cancelInfo->result, cancelInfo->length); @@ -3494,7 +3493,7 @@ OldMathFuncProc( static void OldMathFuncDeleteProc( - ClientData clientData) + ClientData clientData) { OldMathFuncData *dataPtr = clientData; @@ -4338,15 +4337,17 @@ NRCallTEBC( Tcl_SetResult(interp, "tailcall can only be called from a proc or lambda", TCL_STATIC); + Tcl_SetErrorCode(interp, "TCL", "TAILCALL", "ILLEGAL", NULL); return TCL_ERROR; case TCL_NR_YIELD_TYPE: if (iPtr->execEnvPtr->corPtr) { Tcl_SetResult(interp, "cannot yield: C stack busy", TCL_STATIC); - Tcl_SetErrorCode(interp, "COROUTINE_CANT_YIELD", NULL); + Tcl_SetErrorCode(interp, "TCL", "COROUTINE", "CANT_YIELD", NULL); } else { Tcl_SetResult(interp, "yield can only be called in a coroutine", TCL_STATIC); - Tcl_SetErrorCode(interp, "COROUTINE_ILLEGAL_YIELD", NULL); + Tcl_SetErrorCode(interp, "TCL", "COROUTINE", "ILLEGAL_YIELD", + NULL); } return TCL_ERROR; default: @@ -4866,23 +4867,23 @@ TclEvalEx( * evaluation of the script. Only * TCL_EVAL_GLOBAL is currently supported. */ int line, /* The line the script starts on. */ - int* clNextOuter, /* Information about an outer context for */ - CONST char* outerScript) /* continuation line data. This is set only in - * EvalTokensStandard(), to properly handle - * [...]-nested commands. The 'outerScript' - * refers to the most-outer script containing the - * embedded command, which is refered to by - * 'script'. The 'clNextOuter' refers to the - * current entry in the table of continuation - * lines in this "master script", and the - * character offsets are relative to the - * 'outerScript' as well. - * - * If outerScript == script, then this call is - * for the outer-most script/command. See - * Tcl_EvalEx() and TclEvalObjEx() for places - * generating arguments for which this is true. - */ + int *clNextOuter, /* Information about an outer context for */ + const char *outerScript) /* continuation line data. This is set only in + * EvalTokensStandard(), to properly handle + * [...]-nested commands. The 'outerScript' + * refers to the most-outer script containing + * the embedded command, which is refered to + * by 'script'. The 'clNextOuter' refers to + * the current entry in the table of + * continuation lines in this "master script", + * and the character offsets are relative to + * the 'outerScript' as well. + * + * If outerScript == script, then this call is + * for the outer-most script/command. See + * Tcl_EvalEx() and TclEvalObjEx() for places + * generating arguments for which this is + * true. */ { Interp *iPtr = (Interp *) interp; const char *p, *next; @@ -4916,7 +4917,7 @@ TclEvalEx( * parsing the script. */ - int* clNext = NULL; + int *clNext = NULL; if (iPtr->scriptCLLocPtr) { if (clNextOuter) { @@ -5041,7 +5042,7 @@ TclEvalEx( int wordLine = line; const char *wordStart = parsePtr->commandStart; - int* wordCLNext = clNext; + int *wordCLNext = clNext; /* * Generate an array of objects for the words of the command. @@ -5086,7 +5087,7 @@ TclEvalEx( code = TclSubstTokens(interp, tokenPtr+1, tokenPtr->numComponents, NULL, wordLine, - wordCLNext, outerScript); + wordCLNext, outerScript); iPtr->evalFlags = 0; @@ -5369,10 +5370,10 @@ TclAdvanceLines( */ void -TclAdvanceContinuations (line,clNextPtrPtr,loc) - int* line; - int** clNextPtrPtr; - int loc; +TclAdvanceContinuations( + int *line, + int **clNextPtrPtr, + int loc) { /* * Track the invisible continuation lines embedded in a script, if @@ -5384,14 +5385,16 @@ TclAdvanceContinuations (line,clNextPtrPtr,loc) * loc >= **clNextPtrPtr <=> We stepped beyond the current cont. line. */ - while (*clNextPtrPtr && (**clNextPtrPtr >= 0) && (loc >= **clNextPtrPtr)) { + while (*clNextPtrPtr && (**clNextPtrPtr >= 0) + && (loc >= **clNextPtrPtr)) { /* * We just stepped over an invisible continuation line. Adjust the * line counter and step to the table entry holding the location of * the next continuation line to track. */ - (*line) ++; - (*clNextPtrPtr) ++; + + (*line)++; + (*clNextPtrPtr)++; } } @@ -5543,73 +5546,77 @@ TclArgumentRelease( void TclArgumentBCEnter( - Tcl_Interp* interp, - Tcl_Obj* objv[], - int objc, - void* codePtr, - CmdFrame* cfPtr, - int pc) + Tcl_Interp *interp, + Tcl_Obj *objv[], + int objc, + void *codePtr, + CmdFrame *cfPtr, + int pc) { - Interp* iPtr = (Interp*) interp; - Tcl_HashEntry* hePtr = Tcl_FindHashEntry (iPtr->lineBCPtr, (char *) codePtr); + Interp *iPtr = (Interp *) interp; + Tcl_HashEntry *hePtr = + Tcl_FindHashEntry(iPtr->lineBCPtr, (char *) codePtr); + ExtCmdLoc *eclPtr; + if (!hePtr) { + return; + } + eclPtr = Tcl_GetHashValue(hePtr); + hePtr = Tcl_FindHashEntry(&eclPtr->litInfo, INT2PTR(pc)); if (hePtr) { - ExtCmdLoc* eclPtr = (ExtCmdLoc*) Tcl_GetHashValue (hePtr); - hePtr = Tcl_FindHashEntry(&eclPtr->litInfo, INT2PTR(pc)); + int word; + int cmd = PTR2INT(Tcl_GetHashValue(hePtr)); + ECL *ePtr = &eclPtr->loc[cmd]; + CFWordBC *lastPtr = NULL; - if (hePtr) { - int word; - int cmd = PTR2INT(Tcl_GetHashValue(hePtr)); - ECL* ePtr = &eclPtr->loc[cmd]; - CFWordBC* lastPtr = 0; + /* + * A few truths ... + * (1) ePtr->nline == objc + * (2) (ePtr->line[word] < 0) => !literal, for all words + * (3) (word == 0) => !literal + * + * Item (2) is why we can use objv to get the literals, and do not + * have to save them at compile time. + */ - /* - * A few truths ... - * (1) ePtr->nline == objc - * (2) (ePtr->line[word] < 0) => !literal, for all words - * (3) (word == 0) => !literal - * - * Item (2) is why we can use objv to get the literals, and do not - * have to save them at compile time. - */ + for (word = 1; word < objc; word++) { + if (ePtr->line[word] >= 0) { + int isnew; + Tcl_HashEntry *hPtr = + Tcl_CreateHashEntry(iPtr->lineLABCPtr, + (char *) objv[word], &isnew); + CFWordBC *cfwPtr = (CFWordBC *) ckalloc(sizeof(CFWordBC)); + + cfwPtr->framePtr = cfPtr; + cfwPtr->obj = objv[word]; + cfwPtr->pc = pc; + cfwPtr->word = word; + cfwPtr->nextPtr = lastPtr; + lastPtr = cfwPtr; + + if (isnew) { + /* + * The word is not on the stack yet, remember the current + * location and initialize references. + */ - for (word = 1; word < objc; word++) { - if (ePtr->line[word] >= 0) { - int isnew; - Tcl_HashEntry* hPtr = - Tcl_CreateHashEntry (iPtr->lineLABCPtr, - (char*) objv[word], &isnew); - CFWordBC* cfwPtr = (CFWordBC*) ckalloc (sizeof (CFWordBC)); - - cfwPtr->framePtr = cfPtr; - cfwPtr->obj = objv[word]; - cfwPtr->pc = pc; - cfwPtr->word = word; - cfwPtr->nextPtr = lastPtr; - lastPtr = cfwPtr; - - if (isnew) { - /* - * The word is not on the stack yet, remember the - * current location and initialize references. - */ - cfwPtr->prevPtr = NULL; - } else { - /* - * The object is already on the stack, however it may - * have a different location now (literal sharing may - * map multiple location to a single Tcl_Obj*. Save - * the old information in the new structure. - */ - cfwPtr->prevPtr = (CFWordBC*) Tcl_GetHashValue(hPtr); - } + cfwPtr->prevPtr = NULL; + } else { + /* + * The object is already on the stack, however it may have + * a different location now (literal sharing may map + * multiple location to a single Tcl_Obj*. Save the old + * information in the new structure. + */ - Tcl_SetHashValue (hPtr, cfwPtr); + cfwPtr->prevPtr = Tcl_GetHashValue(hPtr); } - } /* for */ - cfPtr->litarg = lastPtr; - } /* if */ + Tcl_SetHashValue(hPtr, cfwPtr); + } + } /* for */ + + cfPtr->litarg = lastPtr; } /* if */ } @@ -5635,17 +5642,17 @@ TclArgumentBCEnter( void TclArgumentBCRelease( - Tcl_Interp *interp, - CmdFrame* cfPtr) + Tcl_Interp *interp, + CmdFrame *cfPtr) { - Interp* iPtr = (Interp*) interp; - CFWordBC* cfwPtr = (CFWordBC*) cfPtr->litarg; + Interp *iPtr = (Interp *) interp; + CFWordBC *cfwPtr = (CFWordBC *) cfPtr->litarg; while (cfwPtr) { - CFWordBC* nextPtr = cfwPtr->nextPtr; - Tcl_HashEntry* hPtr = - Tcl_FindHashEntry(iPtr->lineLABCPtr, (char *) cfwPtr->obj); - CFWordBC* xPtr = (CFWordBC*) Tcl_GetHashValue (hPtr); + CFWordBC *nextPtr = cfwPtr->nextPtr; + Tcl_HashEntry *hPtr = + Tcl_FindHashEntry(iPtr->lineLABCPtr, (char *) cfwPtr->obj); + CFWordBC *xPtr = Tcl_GetHashValue(hPtr); if (xPtr != cfwPtr) { Tcl_Panic ("TclArgumentBC Enter/Release Mismatch"); @@ -5658,7 +5665,6 @@ TclArgumentBCRelease( } ckfree((char *) cfwPtr); - cfwPtr = nextPtr; } @@ -6031,8 +6037,8 @@ TclNREvalObjEx( * executing nested commands in the eval/direct path. */ - ContLineLoc* saveCLLocPtr = iPtr->scriptCLLocPtr; - ContLineLoc* clLocPtr = TclContinuationsGet (objPtr); + ContLineLoc *saveCLLocPtr = iPtr->scriptCLLocPtr; + ContLineLoc *clLocPtr = TclContinuationsGet (objPtr); if (clLocPtr) { iPtr->scriptCLLocPtr = clLocPtr; @@ -7370,6 +7376,7 @@ ExprAbsFunc( if (type == TCL_NUMBER_LONG) { long l = *((const long *) ptr); + if (l <= (long)0) { if (l == LONG_MIN) { TclBNInitBignumFromLong(&big, l); @@ -7384,6 +7391,7 @@ ExprAbsFunc( if (type == TCL_NUMBER_DOUBLE) { double d = *((const double *) ptr); + if (d <= 0.0) { Tcl_SetObjResult(interp, Tcl_NewDoubleObj(-d)); } else { @@ -7395,6 +7403,7 @@ ExprAbsFunc( #ifndef NO_WIDE_TYPE if (type == TCL_NUMBER_WIDE) { Tcl_WideInt w = *((const Tcl_WideInt *) ptr); + if (w < (Tcl_WideInt)0) { if (w == LLONG_MIN) { TclBNInitBignumFromWideInt(&big, w); @@ -7427,6 +7436,7 @@ ExprAbsFunc( return TCL_OK; #else double d; + Tcl_GetDoubleFromObj(interp, objv[1], &d); return TCL_ERROR; #endif @@ -7464,6 +7474,7 @@ ExprDoubleFunc( Tcl_Obj *const *objv) /* Actual parameter vector. */ { double dResult; + if (objc != 2) { MathFuncWrongNumArgs(interp, 2, objc, objv); return TCL_ERROR; @@ -7579,6 +7590,7 @@ ExprWideFunc( { Tcl_WideInt wResult; Tcl_Obj *objPtr; + if (ExprEntierFunc(NULL, interp, objc, objv) != TCL_OK) { return TCL_ERROR; } @@ -8188,14 +8200,12 @@ TclSpliceTailcall ( * being tailcalled. Note that we skip NRCommands marked in data[1] * (used by command redirectors) */ - + Interp *iPtr = (Interp *) interp; TEOV_callback *runPtr; ExecEnv *eePtr = NULL; - - - - restart: + + restart: for (runPtr = TOP_CB(interp); runPtr; runPtr = runPtr->nextPtr) { if (((runPtr->procPtr) == NRCommand) && !runPtr->data[1]) { break; @@ -8206,25 +8216,26 @@ TclSpliceTailcall ( * If we are tailcalling out of a coroutine, the splicing spot is * in the caller's execEnv: go find it! */ - + CoroutineData *corPtr = iPtr->execEnvPtr->corPtr; + if (corPtr) { - eePtr = iPtr->execEnvPtr; + eePtr = iPtr->execEnvPtr; iPtr->execEnvPtr = corPtr->callerEEPtr; goto restart; } Tcl_Panic("Tailcall cannot find the right splicing spot: should not happen!"); } - + tailcallPtr->nextPtr = runPtr->nextPtr; runPtr->nextPtr = tailcallPtr; - + if (eePtr) { /* * Restore the right execEnv if it was swapped for tailcalling out * of a coroutine. */ - + iPtr->execEnvPtr = eePtr; } } @@ -8287,7 +8298,8 @@ TclNRTailcallObjCmd( iPtr->varFramePtr->tailcallPtr = TOP_CB(interp); TOP_CB(interp) = TOP_CB(interp)->nextPtr; - TclNRAddCallback(interp, NRCallTEBC, INT2PTR(TCL_NR_TAILCALL_TYPE), NULL, NULL, NULL); + TclNRAddCallback(interp, NRCallTEBC, INT2PTR(TCL_NR_TAILCALL_TYPE), + NULL, NULL, NULL); return TCL_OK; } @@ -8304,7 +8316,7 @@ NRTailcallEval( int objc; Tcl_Obj **objv; - TclNRDeferCallback(interp, TailcallCleanup, listPtr, nsObjPtr, NULL, NULL); + TclNRDeferCallback(interp, TailcallCleanup, listPtr, nsObjPtr, NULL,NULL); if (result == TCL_OK) { result = TclGetNamespaceFromObj(interp, nsObjPtr, &nsPtr); if (result == TCL_OK) { @@ -8401,7 +8413,6 @@ static const CorContext NULL_CONTEXT = {NULL, NULL, NULL, NULL}; iPtr->varFramePtr = (context).varFramePtr; \ iPtr->cmdFramePtr = (context).cmdFramePtr; \ iPtr->lineLABCPtr = (context).lineLABCPtr - #define iPtr ((Interp *) interp) @@ -8421,7 +8432,7 @@ YieldCallback( /* yieldTo: invoke the command using tailcall tech */ TEOV_callback *cbPtr; ClientData nsPtr = data[2]; - + TclNRAddCallback(interp, NRTailcallEval, listPtr, nsPtr, NULL, NULL); cbPtr = TOP_CB(interp); @@ -8431,7 +8442,7 @@ YieldCallback( } return TCL_OK; } - + int TclNRYieldObjCmd( ClientData clientData, @@ -8507,7 +8518,7 @@ TclNRYieldToObjCmd( Tcl_Panic("yieldTo failed to find the proper namespace"); } Tcl_IncrRefCount(nsObjPtr); - + TclNRAddCallback(interp, YieldCallback, corPtr, listPtr, nsObjPtr, NULL); TclNRAddCallback(interp, NRCallTEBC, INT2PTR(TCL_NR_YIELD_TYPE), NULL, NULL, NULL); @@ -8716,14 +8727,14 @@ NRInterpCoroutine( Tcl_ResetResult(interp); Tcl_AppendResult(interp, "coroutine \"", Tcl_GetString(objv[0]), "\" is already running", NULL); - Tcl_SetErrorCode(interp, "COROUTINE_BUSY", NULL); + Tcl_SetErrorCode(interp, "TCL", "COROUTINE", "BUSY", NULL); return TCL_ERROR; } /* - * Swap the interp's environment to make it suitable to run this coroutine. - * TEBC needs no info to resume executing after a suspension: the codePtr - * will be read from the execEnv's saved bottomPtr. + * Swap the interp's environment to make it suitable to run this + * coroutine. TEBC needs no info to resume executing after a suspension: + * the codePtr will be read from the execEnv's saved bottomPtr. */ if (objc == 2) { @@ -8761,7 +8772,7 @@ TclNRCoroutineObjCmd( Namespace *nsPtr, *altNsPtr, *cxtNsPtr; Tcl_DString ds; int result; - + if (objc < 3) { Tcl_WrongNumArgs(interp, 1, objv, "name cmd ?arg ...?"); return TCL_ERROR; @@ -8868,19 +8879,20 @@ TclNRCoroutineObjCmd( { Tcl_HashSearch hSearch; - Tcl_HashEntry* hePtr; + Tcl_HashEntry *hePtr; - corPtr->base.lineLABCPtr = (Tcl_HashTable *) ckalloc(sizeof(Tcl_HashTable)); + corPtr->base.lineLABCPtr = (Tcl_HashTable *) + ckalloc(sizeof(Tcl_HashTable)); Tcl_InitHashTable(corPtr->base.lineLABCPtr, TCL_ONE_WORD_KEYS); for (hePtr = Tcl_FirstHashEntry(iPtr->lineLABCPtr,&hSearch); - hePtr; - hePtr = Tcl_NextHashEntry(&hSearch)) { + hePtr; hePtr = Tcl_NextHashEntry(&hSearch)) { int isNew; - Tcl_HashEntry* newPtr = - Tcl_CreateHashEntry(corPtr->base.lineLABCPtr, - (char *) Tcl_GetHashKey (iPtr->lineLABCPtr, hePtr), + Tcl_HashEntry *newPtr = + Tcl_CreateHashEntry(corPtr->base.lineLABCPtr, + (char *) Tcl_GetHashKey(iPtr->lineLABCPtr, hePtr), &isNew); + Tcl_SetHashValue(newPtr, Tcl_GetHashValue(hePtr)); } @@ -8908,11 +8920,11 @@ TclNRCoroutineObjCmd( iPtr->varFramePtr = iPtr->rootFramePtr; iPtr->lookupNsPtr = iPtr->framePtr->nsPtr; corPtr->auxNumLevels = iPtr->numLevels; - + TclNRAddCallback(interp, NRCoroutineExitCallback, corPtr, NULL,NULL,NULL); iPtr->evalFlags |= TCL_EVAL_REDIRECT; - result = TclNREvalObjEx(interp, cmdObjPtr, 0, NULL, 0); + result = TclNREvalObjEx(interp, cmdObjPtr, 0, NULL, 0); return TclNRRunCallbacks(interp, result, rootPtr, 0); } |