Index: generic/nsf.c =================================================================== diff -u -rc9a0d623d5d561d4c0f1dcd97cada90ba8fbb108 -rc4dd42ea5b714013b9d1d7a71ae2c895dc322ef8 --- generic/nsf.c (.../nsf.c) (revision c9a0d623d5d561d4c0f1dcd97cada90ba8fbb108) +++ generic/nsf.c (.../nsf.c) (revision c4dd42ea5b714013b9d1d7a71ae2c895dc322ef8) @@ -18639,13 +18639,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() */ @@ -18668,12 +18661,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; @@ -18728,12 +18723,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? */ @@ -18876,7 +18872,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 { /* @@ -19075,13 +19072,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 -rb9bcc40ab502329b1e7bc4ed6602adf7bd5e614d -rc4dd42ea5b714013b9d1d7a71ae2c895dc322ef8 --- generic/nsfInt.h (.../nsfInt.h) (revision b9bcc40ab502329b1e7bc4ed6602adf7bd5e614d) +++ generic/nsfInt.h (.../nsfInt.h) (revision c4dd42ea5b714013b9d1d7a71ae2c895dc322ef8) @@ -668,7 +668,6 @@ Tcl_Command cmd; Tcl_Command wrapperCmd; NsfParamDefs *paramDefs; - Tcl_Namespace *origNsPtr; unsigned int flags; } NsfProcClientData; Index: tests/nsf-cmd.test =================================================================== diff -u -r1919d17fefad9446170fa6d532b439f494189b32 -rc4dd42ea5b714013b9d1d7a71ae2c895dc322ef8 --- tests/nsf-cmd.test (.../nsf-cmd.test) (revision 1919d17fefad9446170fa6d532b439f494189b32) +++ tests/nsf-cmd.test (.../nsf-cmd.test) (revision c4dd42ea5b714013b9d1d7a71ae2c895dc322ef8) @@ -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