Index: TODO =================================================================== diff -u -r236b6dfeb5bc9a7fa81e596f9f5d0bb7dfa6ea9e -rb7fc53255ed596e8e8ff630461349b7a35e1c3f3 --- TODO (.../TODO) (revision 236b6dfeb5bc9a7fa81e596f9f5d0bb7dfa6ea9e) +++ TODO (.../TODO) (revision b7fc53255ed596e8e8ff630461349b7a35e1c3f3) @@ -5392,6 +5392,7 @@ - move NsfMethodNamePath() out of NsfObjWrongArgs() - move NsfMethodNamePath() out of NsfUnexpectedArgumentError() and NsfUnexpectedNonposArgumentError() - fix name paths in error messages triggered from ArgumentParse() +- use 3-argument version of NsfMethodNamePath() ======================================================================== TODO: Index: generic/nsf.c =================================================================== diff -u -r1d47bd9661fd8d641c0c8441f6def1081902c9db -rb7fc53255ed596e8e8ff630461349b7a35e1c3f3 --- generic/nsf.c (.../nsf.c) (revision 1d47bd9661fd8d641c0c8441f6def1081902c9db) +++ generic/nsf.c (.../nsf.c) (revision b7fc53255ed596e8e8ff630461349b7a35e1c3f3) @@ -4408,56 +4408,24 @@ Tcl_Obj * NsfMethodNamePath(Tcl_Interp *interp, Tcl_CallFrame *framePtr, - int skip, CONST char *methodName) { Tcl_Obj *resultObj = Tcl_NewListObj(0, NULL); assert(interp); assert(methodName); - if (framePtr == NULL) { - /* We default to the top frame, if not requested otherwise */ - (void) CallStackGetTopFrame(interp, &framePtr); - } - if (framePtr) { Tcl_ListObjAppendList(interp, resultObj, - CallStackMethodPath(interp, skip, framePtr)); + CallStackMethodPath(interp, framePtr)); } Tcl_ListObjAppendElement(interp, resultObj, Tcl_NewStringObj(methodName,-1)); return resultObj; } -EXTERN Tcl_Obj *NsfMethodNamePath3(Tcl_Interp *interp, - Tcl_CallFrame *framePtr, - CONST char *methodName) - nonnull(1) returns_nonnull; - -Tcl_Obj * -NsfMethodNamePath3(Tcl_Interp *interp, - Tcl_CallFrame *framePtr, - CONST char *methodName) { - - Tcl_Obj *resultObj = Tcl_NewListObj(0, NULL); - - assert(interp); - assert(methodName); - - if (framePtr) { - Tcl_ListObjAppendList(interp, resultObj, - CallStackMethodPath(interp, 0 /* fixme */, framePtr)); - } - - Tcl_ListObjAppendElement(interp, resultObj, - Tcl_NewStringObj(methodName,-1)); - return resultObj; -} - - /* *---------------------------------------------------------------------- * NsColonVarResolver -- @@ -12473,9 +12441,9 @@ * method path, and the unknown final method. */ Tcl_Obj *callInfoObj = Tcl_NewListObj(1, &callerSelf->cmdName); - Tcl_Obj *methodPathObj = NsfMethodNamePath3(interp, - CallStackGetFrame(interp,(Tcl_CallFrame *)framePtr, 1), - MethodName(objv[0])); + Tcl_Obj *methodPathObj = NsfMethodNamePath(interp, + CallStackGetTclFrame(interp,(Tcl_CallFrame *)framePtr, 1), + MethodName(objv[0])); INCR_REF_COUNT(callInfoObj); Tcl_ListObjAppendList(interp, callInfoObj, methodPathObj); Tcl_ListObjAppendElement(interp, callInfoObj, objv[1]); @@ -19547,7 +19515,7 @@ if (objc > 2) { return NsfObjWrongArgs(interp, "wrong # args", object->cmdName, - NsfMethodNamePath3(interp, CallStackGetFrame(interp, NULL, 1), NsfMethodName(objv[0])), "?value?"); + NsfMethodNamePath(interp, CallStackGetTclFrame(interp, NULL, 1), NsfMethodName(objv[0])), "?value?"); } if (object == NULL) return NsfDispatchClientDataError(interp, clientData, "object", ObjStr(objv[0])); @@ -19626,8 +19594,8 @@ if (tcd->object) { cmd = Tcl_DuplicateObj(tcd->object->cmdName); if (objc > 0) { - Tcl_ListObjAppendList(interp, cmd, - NsfMethodNamePath3(interp, CallStackGetFrame(interp, NULL, 1), MethodName(objv[0]))); + Tcl_ListObjAppendList(interp, cmd, + NsfMethodNamePath(interp, CallStackGetTclFrame(interp, NULL, 1), MethodName(objv[0]))); if (objc > 1) { Tcl_ListObjAppendElement(interp, cmd, Tcl_NewListObj(objc-1,objv+1)); } @@ -20880,9 +20848,9 @@ } else if (unlikely(pPtr->flags & NSF_ARG_REQUIRED) && (processFlags & NSF_ARGPARSE_FORCE_REQUIRED)) { Tcl_Obj *paramDefsObj = NsfParamDefsSyntax(interp, ifd, pcPtr->object, NULL); - Tcl_Obj *methodPathObj = NsfMethodNamePath3(interp, - CallStackGetFrame(interp, NULL, 1), - MethodName(pcPtr->full_objv[0])); + Tcl_Obj *methodPathObj = NsfMethodNamePath(interp, + CallStackGetTclFrame(interp, NULL, 1), + MethodName(pcPtr->full_objv[0])); INCR_REF_COUNT2("methodPathObj", methodPathObj); @@ -21035,7 +21003,7 @@ #endif if (unlikely(currentParamPtr > lastParamPtr)) { - Tcl_Obj *methodPathObj = NsfMethodNamePath3(interp, CallStackGetFrame(interp, NULL, 0), NsfMethodName(procNameObj)); + Tcl_Obj *methodPathObj = NsfMethodNamePath(interp, CallStackGetTclFrame(interp, NULL, 0), NsfMethodName(procNameObj)); return NsfUnexpectedArgumentError(interp, ObjStr(argumentObj), (Nsf_Object*)object, paramPtr, methodPathObj); } @@ -21144,8 +21112,8 @@ Nsf_Param CONST *nextParamPtr = NextParam(currentParamPtr, lastParamPtr); if (nextParamPtr > lastParamPtr || (nextParamPtr->flags & NSF_ARG_NOLEADINGDASH)) { - Tcl_Obj *methodPathObj = NsfMethodNamePath3(interp, CallStackGetFrame(interp, NULL, 0), - NsfMethodName(procNameObj)); + Tcl_Obj *methodPathObj = NsfMethodNamePath(interp, CallStackGetTclFrame(interp, NULL, 0), + NsfMethodName(procNameObj)); return NsfUnexpectedNonposArgumentError(interp, argumentString, (Nsf_Object *)object, currentParamPtr, paramPtr, @@ -21201,8 +21169,8 @@ ObjStr(argumentObj)); } #endif - Tcl_Obj *methodPathObj = NsfMethodNamePath3(interp, CallStackGetFrame(interp, NULL, 0), - NsfMethodName(procNameObj)); + Tcl_Obj *methodPathObj = NsfMethodNamePath(interp, CallStackGetTclFrame(interp, NULL, 0), + NsfMethodName(procNameObj)); return NsfUnexpectedNonposArgumentError(interp, argumentString, (Nsf_Object *)object, currentParamPtr, paramPtr, @@ -21224,15 +21192,14 @@ * parameter, valueObj might be already provided for valueInArgument. */ if (unlikely(pPtr > lastParamPtr)) { - Tcl_Obj *methodPathObj = NsfMethodNamePath3(interp, CallStackGetFrame(interp, NULL, 0), - NsfMethodName(procNameObj)); + Tcl_Obj *methodPathObj = NsfMethodNamePath(interp, CallStackGetTclFrame(interp, NULL, 0), + NsfMethodName(procNameObj)); return NsfUnexpectedArgumentError(interp, ObjStr(argumentObj), (Nsf_Object *)object, paramPtr, methodPathObj); } - /* * Set the position in the downstream argv (normalized order) */ @@ -26198,9 +26165,9 @@ case CurrentoptionMethodpathIdx: cscPtr = CallStackGetTopFrame0(interp); - Tcl_SetObjResult(interp, NsfMethodNamePath3(interp, - CallStackGetFrame(interp, NULL, 1), - Tcl_GetCommandName(interp, cscPtr->cmdPtr))); + Tcl_SetObjResult(interp, NsfMethodNamePath(interp, + CallStackGetTclFrame(interp, NULL, 1), + Tcl_GetCommandName(interp, cscPtr->cmdPtr))); break; case CurrentoptionClassIdx: /* class subcommand */ @@ -26265,9 +26232,9 @@ cscPtr = NsfCallStackFindLastInvocation(interp, 1, &framePtr); if (cscPtr && cscPtr->cmdPtr) { - resultObj = NsfMethodNamePath3(interp, - CallStackGetFrame(interp, framePtr, 1), - Tcl_GetCommandName(interp, cscPtr->cmdPtr)); + resultObj = NsfMethodNamePath(interp, + CallStackGetTclFrame(interp, framePtr, 1), + Tcl_GetCommandName(interp, cscPtr->cmdPtr)); } else { resultObj = NsfGlobalObjs[NSF_EMPTY]; } Index: generic/nsfInt.h =================================================================== diff -u -r236b6dfeb5bc9a7fa81e596f9f5d0bb7dfa6ea9e -rb7fc53255ed596e8e8ff630461349b7a35e1c3f3 --- generic/nsfInt.h (.../nsfInt.h) (revision 236b6dfeb5bc9a7fa81e596f9f5d0bb7dfa6ea9e) +++ generic/nsfInt.h (.../nsfInt.h) (revision b7fc53255ed596e8e8ff630461349b7a35e1c3f3) @@ -1019,10 +1019,10 @@ EXTERN Tcl_Obj *NsfMethodNamePath(Tcl_Interp *interp, Tcl_CallFrame *framePtr, - int skip, CONST char *methodName) - nonnull(1) nonnull(4) returns_nonnull; + nonnull(1) nonnull(3) returns_nonnull; + /* * Definition of methodEpoch macros */ Index: generic/nsfStack.c =================================================================== diff -u -r1d47bd9661fd8d641c0c8441f6def1081902c9db -rb7fc53255ed596e8e8ff630461349b7a35e1c3f3 --- generic/nsfStack.c (.../nsfStack.c) (revision 1d47bd9661fd8d641c0c8441f6def1081902c9db) +++ generic/nsfStack.c (.../nsfStack.c) (revision b7fc53255ed596e8e8ff630461349b7a35e1c3f3) @@ -41,7 +41,7 @@ * *---------------------------------------------------------------------- */ -static int CscListRemove(Tcl_Interp *interp, NsfCallStackContent *cscPtr, NsfClasses **cscListPtr) +static int CscListRemove(Tcl_Interp *interp, NsfCallStackContent *cscPtr, NsfClasses **cscListPtr) nonnull(1) nonnull(2) nonnull(3); static void CscListAdd(Tcl_Interp *interp, NsfCallStackContent *cscPtr) nonnull(1) nonnull(2); @@ -226,9 +226,9 @@ * *---------------------------------------------------------------------- */ -NSF_INLINE static void Nsf_PushFrameCsc(Tcl_Interp *interp, NsfCallStackContent *cscPtr, CallFrame *framePtr) - nonnull(1) nonnull(2) nonnull(3); -static void Nsf_PopFrameCsc(Tcl_Interp *interp, CallFrame *UNUSED(framePtr)) nonnull(1); +NSF_INLINE static void Nsf_PushFrameCsc(Tcl_Interp *interp, NsfCallStackContent *cscPtr, CallFrame *framePtr) + nonnull(1) nonnull(2) nonnull(3); +static void Nsf_PopFrameCsc(Tcl_Interp *interp, CallFrame *UNUSED(framePtr)) nonnull(1); NSF_INLINE static void Nsf_PushFrameCsc(Tcl_Interp *interp, NsfCallStackContent *cscPtr, CallFrame *framePtr) { @@ -361,7 +361,7 @@ Tcl_Interp_framePtr(interp), Tcl_Interp_varFramePtr(interp));*/ for (; varFramePtr; varFramePtr = - + #if defined(SKIP_LEVELS) Tcl_CallFrame_callerPtr(varFramePtr) #else @@ -388,23 +388,36 @@ return NULL; } -static Tcl_CallFrame* CallStackGetFrame(Tcl_Interp *interp, - Tcl_CallFrame *startFrame, - int skip) nonnull(1); +/* + *---------------------------------------------------------------------- + * CallStackGetTclFrame -- + * + * Return the Tcl_Callframe a (scripted or nonleaf) method starting with + * the specified or topmost frame; if skip is a positive numer the + * specified number of frames tcl frames are skipped. + * + * Results: + * Tcl_CallFrame or NULL. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ +static Tcl_CallFrame* CallStackGetTclFrame(Tcl_Interp *interp, + Tcl_CallFrame *startFramePtr, + int skip) nonnull(1); -static Tcl_CallFrame* CallStackGetFrame(Tcl_Interp *interp, - Tcl_CallFrame *startFrame, - int skip) { - register Tcl_CallFrame *varFramePtr; - +static Tcl_CallFrame* CallStackGetTclFrame(Tcl_Interp *interp, + Tcl_CallFrame *varFramePtr, + int skip) { assert(interp); + assert(skip >= 0); /* NsfShowStack(interp); */ - if (startFrame == NULL) { + if (varFramePtr == NULL) { varFramePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); - } else { - varFramePtr = startFrame; } while(skip-- && varFramePtr != NULL) { @@ -424,7 +437,9 @@ *---------------------------------------------------------------------- * CallStackGetTopFrame, CallStackGetTopFrame0, NsfCallStackGetTopFrame -- * - * Return the topmost invocation of a (scripted or nonleaf) method + * Return the NsfCallStackContent* of the topmost invocation of a (scripted + * or nonleaf) method. If framePtrPtr is provided, it is used to return the + * tcl frame as well. * * Results: * Call stack content or NULL. @@ -434,17 +449,17 @@ * *---------------------------------------------------------------------- */ -static NsfCallStackContent*CallStackGetTopFrame(Tcl_Interp *interp, Tcl_CallFrame **framePtrPtr) nonnull(1); -NSF_INLINE static NsfCallStackContent* CallStackGetTopFrame0(Tcl_Interp *interp) nonnull(1); +static NsfCallStackContent *CallStackGetTopFrame(Tcl_Interp *interp, Tcl_CallFrame **framePtrPtr) nonnull(1); +NSF_INLINE static NsfCallStackContent *CallStackGetTopFrame0(Tcl_Interp *interp) nonnull(1); static NsfCallStackContent* CallStackGetTopFrame(Tcl_Interp *interp, Tcl_CallFrame **framePtrPtr) { register Tcl_CallFrame *varFramePtr; assert(interp); - for (varFramePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); - varFramePtr; + for (varFramePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); + varFramePtr; varFramePtr = Tcl_CallFrame_callerPtr(varFramePtr)) { if (Tcl_CallFrame_isProcCallFrame(varFramePtr) & (FRAME_IS_NSF_METHOD|FRAME_IS_NSF_CMETHOD)) { @@ -464,8 +479,8 @@ assert(interp); - for (varFramePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); - varFramePtr; + for (varFramePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); + varFramePtr; varFramePtr = Tcl_CallFrame_callerPtr(varFramePtr)) { if (likely(Tcl_CallFrame_isProcCallFrame(varFramePtr) & (FRAME_IS_NSF_METHOD|FRAME_IS_NSF_CMETHOD))) { return (NsfCallStackContent *)Tcl_CallFrame_clientData(varFramePtr); @@ -498,7 +513,7 @@ * *---------------------------------------------------------------------- */ -static NsfCallStackContent *NsfCallStackFindLastInvocation(Tcl_Interp *interp, int offset, Tcl_CallFrame **framePtrPtr) +static NsfCallStackContent *NsfCallStackFindLastInvocation(Tcl_Interp *interp, int offset, Tcl_CallFrame **framePtrPtr) nonnull(1); static NsfCallStackContent * @@ -507,7 +522,7 @@ int lvl = Tcl_CallFrame_level(varFramePtr); assert(interp); - + for (; likely(varFramePtr != NULL); varFramePtr = Tcl_CallFrame_callerVarPtr(varFramePtr)) { if (Tcl_CallFrame_isProcCallFrame(varFramePtr) & (FRAME_IS_NSF_METHOD|FRAME_IS_NSF_CMETHOD)) { @@ -569,7 +584,7 @@ /* skip #offset frames */ for (varFramePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); - offset>0 && varFramePtr; + offset>0 && varFramePtr; varFramePtr = Tcl_CallFrame_callerPtr(varFramePtr), offset--); /* search for first active frame and set tcl frame pointers */ @@ -766,10 +781,11 @@ * *---------------------------------------------------------------------- */ -static Tcl_Obj* CallStackMethodPath(Tcl_Interp *interp, int skip, Tcl_CallFrame *framePtr) nonnull(1) nonnull(3); +static Tcl_Obj* CallStackMethodPath(Tcl_Interp *interp, Tcl_CallFrame *framePtr) + nonnull(1) nonnull(2); static Tcl_Obj* -CallStackMethodPath(Tcl_Interp *interp, int skip, Tcl_CallFrame *framePtr) { +CallStackMethodPath(Tcl_Interp *interp, Tcl_CallFrame *framePtr) { int elements; Tcl_Obj *resultObj; Tcl_Obj *methodPathObj = Tcl_NewListObj(0, NULL); @@ -780,11 +796,7 @@ /* * Append all ensemble names to the specified list obj */ - - while(skip--) {framePtr = Tcl_CallFrame_callerPtr(framePtr);} - - for (/* Skipping the starting frame, assuming a "leaf" frame in an ensemble dispatch */ - elements = 0; + for (elements = 0; Tcl_CallFrame_isProcCallFrame(framePtr) & (FRAME_IS_NSF_CMETHOD|FRAME_IS_NSF_METHOD); framePtr = Tcl_CallFrame_callerPtr(framePtr)) { @@ -943,7 +955,7 @@ static void CallStackPopAll(Tcl_Interp *interp) { assert(interp); - + if (RUNTIME_STATE(interp)->debugLevel > 2) { NsfShowStack(interp); } @@ -1013,10 +1025,10 @@ *---------------------------------------------------------------------- */ #if defined(NRE) -static NsfCallStackContent * CscAlloc(Tcl_Interp *interp, NsfCallStackContent *cscPtr, Tcl_Command cmd) +static NsfCallStackContent * CscAlloc(Tcl_Interp *interp, NsfCallStackContent *cscPtr, Tcl_Command cmd) nonnull(1); #else -static NsfCallStackContent * CscAlloc(Tcl_Interp *interp, NsfCallStackContent *cscPtr, Tcl_Command cmd) +static NsfCallStackContent * CscAlloc(Tcl_Interp *interp, NsfCallStackContent *cscPtr, Tcl_Command cmd) nonnull(2); #endif