Index: generic/nsf.c =================================================================== diff -u -r405ace784414b362cf5594619e12776fa8454c2d -r47f388cda74f1b4656389d4129b96435034ac4a4 --- generic/nsf.c (.../nsf.c) (revision 405ace784414b362cf5594619e12776fa8454c2d) +++ generic/nsf.c (.../nsf.c) (revision 47f388cda74f1b4656389d4129b96435034ac4a4) @@ -18642,13 +18642,6 @@ DECR_REF_COUNT2("procNameObj", tcd->procName); if (tcd->cmd != NULL) { - /* - * Re-wire the original namespace into the shadowed cmd, to prevent - * namespace references from becoming dangling and to keep the involved - * namespaces' refcount books balanced. - */ - ((Command *)tcd->cmd)->nsPtr = (Namespace *)tcd->origNsPtr; - NSNamespaceRelease(tcd->origNsPtr); NsfCommandRelease(tcd->cmd); } /* tcd->paramDefs is freed by NsfProcDeleteProc() */ @@ -18671,12 +18664,14 @@ *---------------------------------------------------------------------- */ static int InvokeShadowedProc(Tcl_Interp *interp, Tcl_Obj *procNameObj, Tcl_Command cmd, ParseContext *pcPtr, - struct Tcl_Time *trtPtr, unsigned int cmdFlags) - nonnull(1) nonnull(2) nonnull(4) nonnull(3) nonnull(4); + struct Tcl_Time *trtPtr, unsigned int cmdFlags, + Tcl_Namespace *execNsPtr) + nonnull(1) nonnull(2) nonnull(4) nonnull(3) nonnull(4) nonnull(5); static int InvokeShadowedProc(Tcl_Interp *interp, Tcl_Obj *procNameObj, Tcl_Command cmd, ParseContext *pcPtr, - struct Tcl_Time *trtPtr, unsigned int cmdFlags) { + struct Tcl_Time *trtPtr, unsigned int cmdFlags, + Tcl_Namespace *execNsPtr) { Tcl_Obj *const *objv; int objc, result, includeTiming; const char *fullMethodName; @@ -18731,12 +18726,13 @@ procPtr = (Proc *)Tcl_Command_objClientData(cmd); result = TclPushStackFrame(interp, &framePtr, - (Tcl_Namespace *) procPtr->cmdPtr->nsPtr, + execNsPtr /* procPtr->cmdPtr->nsPtr */, (FRAME_IS_PROC)); if (likely(result == TCL_OK)) { unsigned int dummy = 0; - result = ByteCompiled(interp, &dummy, procPtr, procPtr->cmdPtr->nsPtr, fullMethodName); + result = ByteCompiled(interp, &dummy, procPtr, (Namespace *)execNsPtr, + fullMethodName); } if (unlikely(result != TCL_OK)) { /* todo: really? error msg? */ @@ -18879,7 +18875,8 @@ NsfDeprecatedCmd(interp, "proc", ObjStr(objv[0]), ""); } - result = InvokeShadowedProc(interp, tcd->procName, tcd->cmd, pcPtr, &trt, cmdFlags); + result = InvokeShadowedProc(interp, tcd->procName, tcd->cmd, pcPtr, &trt, + cmdFlags, Tcl_Command_nsPtr(cmd)); } else { /* @@ -19078,13 +19075,7 @@ Tcl_Command procCmd = Tcl_GetCommandFromObj(interp, procNameObj); assert(procCmd != NULL); - /* - * Preserve the shadowed cmd's original namespace (::nsf::procs::*) for - * later re-wiring in NsfProcStubDeleteProc() - */ - tcd->origNsPtr = Tcl_Command_nsPtr(procCmd); - NSNamespacePreserve(tcd->origNsPtr); - ((Command *)procCmd)->nsPtr = (Namespace *)cmdNsPtr; + tcd->cmd = procCmd; NsfCommandPreserve(tcd->cmd); Index: generic/nsfInt.h =================================================================== diff -u -rd7bc5d6344a2648519087a1450071b28660b9977 -r47f388cda74f1b4656389d4129b96435034ac4a4 --- generic/nsfInt.h (.../nsfInt.h) (revision d7bc5d6344a2648519087a1450071b28660b9977) +++ generic/nsfInt.h (.../nsfInt.h) (revision 47f388cda74f1b4656389d4129b96435034ac4a4) @@ -688,7 +688,6 @@ Tcl_Command cmd; Tcl_Command wrapperCmd; NsfParamDefs *paramDefs; - Tcl_Namespace *origNsPtr; unsigned int flags; } NsfProcClientData; Index: tests/nsf-cmd.test =================================================================== diff -u -r1919d17fefad9446170fa6d532b439f494189b32 -r47f388cda74f1b4656389d4129b96435034ac4a4 --- tests/nsf-cmd.test (.../nsf-cmd.test) (revision 1919d17fefad9446170fa6d532b439f494189b32) +++ tests/nsf-cmd.test (.../nsf-cmd.test) (revision 47f388cda74f1b4656389d4129b96435034ac4a4) @@ -511,7 +511,27 @@ } +nx::test case nsf-proc-rename { + namespace eval ::ns1 {} + + nsf::proc ns1::foo { + {-x:required} + } { return 1-$x } + ? {ns1::foo -x ok} 1-ok + + rename ns1::foo ns1::foo.orig + + nsf::proc ns1::foo { + {-x:required} + } { return 2-$x } + + ? {ns1::foo -x ok} 2-ok + + namespace delete ::ns1 +} + + # # Local variables: # mode: tcl