(tailcall|yieldto) failed to find the proper namespace Abort
Under some circumstances a coroutine can be invoked via ::yieldto while the namespace in which it resides is dying (nsPtr->flags&NS_DYING) This may occur, and is occuring, for example, when a TclOO object is being destroyed, and a coroutine within it is invoked by an event. The call to TclGetNamespaceFromObj() at tclBasic.c:8532 will indicate an error, because the current frame's namespace is not considered to match itself in the case that it is dying. I am unsure what the purpose of the test is, or under what circumstances the two namespaces might differ, but this abort occurs as a result of script evaluation, and hence should be considered a bug.
1. no script to repro? 2. any suggestion as to what should happen in that case? Would an error be in order?
Note: the problem is likely to appear also with [tailcall].
The problem is indeed with [tailcall] whose guts are reused by [yieldto]. The current namespace was being cached in an nsNameType Tcl_Obj in order to insure its survival, and as a failure to resolve "could not happen" it was signaled by a panic. As colin is wont to do, he triggered the impossible! Fixed by using a better lifetime management of the namespace.
Is this bug still present?
This is why it's great to have a test, so we can confirm when the bug is dead…
The following script reproduces the issue:
namespace eval ns {
proc p args {
::tailcall [namespace current] {*}$args
}
namespace eval [namespace current] {
namespace delete [namespace current]
p
}
}
TIP 498 is one solution to this issue.
A slightly smaller example:
namespace eval ns {
proc p args {
::tailcall [namespace current] {*}$args
}
namespace delete [namespace current]
p
}
If {*} from the example the compiled path for tailcall is taken, and in the compiled variant an error is raised:
namespace "::ns" not found
In [9198c16407f3] namespace handling is removed from
TclNRTailcallObjCmd, allowing TclNRTailcallObjCmd to
handle namespace issues later. This aligns the behaviour of the non-compiled
variant with the compiled one: An error is produced if the namespace is not
found.
This is now fixed and the ticket can be closed?