diff options
author | dkf <dkf@noemail.net> | 2011-05-09 15:24:06 (GMT) |
---|---|---|
committer | dkf <dkf@noemail.net> | 2011-05-09 15:24:06 (GMT) |
commit | 48a3f2ba866eed93945f76da2ef8b1ac2f2cd5a8 (patch) | |
tree | 022fd34c553b4bac0b99b267538eecaeb5b0f116 /generic/tclNamesp.c | |
parent | a91d3ab4e2353e0e5b233bfb563e97b17d59e09d (diff) | |
download | tcl-48a3f2ba866eed93945f76da2ef8b1ac2f2cd5a8.zip tcl-48a3f2ba866eed93945f76da2ef8b1ac2f2cd5a8.tar.gz tcl-48a3f2ba866eed93945f76da2ef8b1ac2f2cd5a8.tar.bz2 |
Reduce use of Tcl_AppendElement, which is not (and can't be) a Tcl_Obj-aware API.
FossilOrigin-Name: dbab97cbba58a39c357af59d4ab96a4d419cc9d7
Diffstat (limited to 'generic/tclNamesp.c')
-rw-r--r-- | generic/tclNamesp.c | 58 |
1 files changed, 41 insertions, 17 deletions
diff --git a/generic/tclNamesp.c b/generic/tclNamesp.c index f3c93e7..9a2152a 100644 --- a/generic/tclNamesp.c +++ b/generic/tclNamesp.c @@ -3959,16 +3959,15 @@ NamespacePathCmd( */ if (objc == 1) { - /* - * Not a very fast way to compute this, but easy to get right. - */ + Tcl_Obj *resultObj = Tcl_NewObj(); for (i=0 ; i<nsPtr->commandPathLength ; i++) { if (nsPtr->commandPathArray[i].nsPtr != NULL) { - Tcl_AppendElement(interp, - nsPtr->commandPathArray[i].nsPtr->fullName); + Tcl_ListObjAppendElement(NULL, resultObj, Tcl_NewStringObj( + nsPtr->commandPathArray[i].nsPtr->fullName, -1)); } } + Tcl_SetObjResult(interp, resultObj); return TCL_OK; } @@ -4844,8 +4843,9 @@ TclLogCommandInfo( * the error. */ int length, /* Number of bytes in command (-1 means use * all bytes up to first null byte). */ - const unsigned char *pc, /* current pc of bytecode execution context */ - Tcl_Obj **tosPtr) /* current stack of bytecode execution context */ + const unsigned char *pc, /* Current pc of bytecode execution context */ + Tcl_Obj **tosPtr) /* Current stack of bytecode execution + * context */ { register const char *p; Interp *iPtr = (Interp *) interp; @@ -4930,32 +4930,46 @@ TclLogCommandInfo( iPtr->resetErrorStack = 0; Tcl_ListObjLength(interp, iPtr->errorStack, &len); - /* reset while keeping the list intrep as much as possible */ + + /* + * Reset while keeping the list intrep as much as possible. + */ + Tcl_ListObjReplace(interp, iPtr->errorStack, 0, len, 0, NULL); if (pc != NULL) { Tcl_Obj *innerContext; innerContext = TclGetInnerContext(interp, pc, tosPtr); if (innerContext != NULL) { - Tcl_ListObjAppendElement(NULL, iPtr->errorStack, iPtr->innerLiteral); + Tcl_ListObjAppendElement(NULL, iPtr->errorStack, + iPtr->innerLiteral); Tcl_ListObjAppendElement(NULL, iPtr->errorStack, innerContext); } } else if (command != NULL) { - Tcl_ListObjAppendElement(NULL, iPtr->errorStack, iPtr->innerLiteral); - Tcl_ListObjAppendElement(NULL, iPtr->errorStack, Tcl_NewStringObj(command, length)); + Tcl_ListObjAppendElement(NULL, iPtr->errorStack, + iPtr->innerLiteral); + Tcl_ListObjAppendElement(NULL, iPtr->errorStack, + Tcl_NewStringObj(command, length)); } } if (!iPtr->framePtr->objc) { - /* special frame, nothing to report */ + /* + * Special frame, nothing to report. + */ } else if (iPtr->varFramePtr != iPtr->framePtr) { - /* uplevel case, [lappend errorstack UP $relativelevel] */ + /* + * uplevel case, [lappend errorstack UP $relativelevel] + */ Tcl_ListObjAppendElement(NULL, iPtr->errorStack, iPtr->upLiteral); Tcl_ListObjAppendElement(NULL, iPtr->errorStack, Tcl_NewIntObj( iPtr->framePtr->level - iPtr->varFramePtr->level)); } else if (iPtr->framePtr != iPtr->rootFramePtr) { - /* normal case, [lappend errorstack CALL [info level 0]] */ + /* + * normal case, [lappend errorstack CALL [info level 0]] + */ + Tcl_ListObjAppendElement(NULL, iPtr->errorStack, iPtr->callLiteral); Tcl_ListObjAppendElement(NULL, iPtr->errorStack, Tcl_NewListObj( iPtr->framePtr->objc, iPtr->framePtr->objv)); @@ -4979,7 +4993,12 @@ TclLogCommandInfo( * *---------------------------------------------------------------------- */ -void TclErrorStackResetIf(Tcl_Interp *interp, const char *msg, int length) + +void +TclErrorStackResetIf( + Tcl_Interp *interp, + const char *msg, + int length) { Interp *iPtr = (Interp *) interp; @@ -4996,10 +5015,15 @@ void TclErrorStackResetIf(Tcl_Interp *interp, const char *msg, int length) iPtr->resetErrorStack = 0; Tcl_ListObjLength(interp, iPtr->errorStack, &len); - /* reset while keeping the list intrep as much as possible */ + + /* + * Reset while keeping the list intrep as much as possible. + */ + Tcl_ListObjReplace(interp, iPtr->errorStack, 0, len, 0, NULL); Tcl_ListObjAppendElement(NULL, iPtr->errorStack, iPtr->innerLiteral); - Tcl_ListObjAppendElement(NULL, iPtr->errorStack, Tcl_NewStringObj(msg, length)); + Tcl_ListObjAppendElement(NULL, iPtr->errorStack, + Tcl_NewStringObj(msg, length)); } } |