Index: generic/xotcl.c =================================================================== diff -u -r2ed7f30b42c12e7ec8ad8ee7b2dd98f5f22d7c3f -rdc6c71950983c8fc6c220a751e3e0e3f79b5e10b --- generic/xotcl.c (.../xotcl.c) (revision 2ed7f30b42c12e7ec8ad8ee7b2dd98f5f22d7c3f) +++ generic/xotcl.c (.../xotcl.c) (revision dc6c71950983c8fc6c220a751e3e0e3f79b5e10b) @@ -7297,37 +7297,6 @@ } /* - * mark an obj on the existing callstack, as not destroyed - */ -static void -UndestroyObj(Tcl_Interp *interp, XOTclObject *obj) { - XOTclCallStack *cs = &RUNTIME_STATE(interp)->cs; - XOTclCallStackContent *csc; - - /* - * mark the object on the whole callstack as not destroyed - */ - for (csc = &cs->content[1]; csc <= cs->top; csc++) { - if (obj == csc->self && csc->destroyedCmd) { - /* - * The ref count was incremented, when csc->destroyedCmd - * was set. We revert this first before forgetting the - * destroyedCmd. - */ - if (Tcl_Command_refCount(csc->destroyedCmd) > 1) { - Tcl_Command_refCount(csc->destroyedCmd)--; - MEM_COUNT_FREE("command refCount", csc->destroyedCmd); - } - csc->destroyedCmd = 0; - } - } - /* - * mark obj->flags XOTCL_DESTROY_CALLED as NOT CALLED (0) - */ - obj->flags &= ~XOTCL_DESTROY_CALLED; -} - -/* * bring an object into a state, as after initialization */ static void @@ -7516,7 +7485,7 @@ /* if the command of the obj was used before, we have to clean * up the callstack from set "destroyedCmd" flags */ - UndestroyObj(interp, obj); + CallStackMarkUndestroyed(interp, obj); if (Tcl_FindNamespace(interp, name, NULL, 0)) { nsPtr = NSGetFreshNamespace(interp, (ClientData)obj, name); @@ -8038,7 +8007,7 @@ } if (destroyed) { - UndestroyObj(interp, newobj); + CallStackMarkUndestroyed(interp, newobj); } /* Index: generic/xotcl.h =================================================================== diff -u -r2ed7f30b42c12e7ec8ad8ee7b2dd98f5f22d7c3f -rdc6c71950983c8fc6c220a751e3e0e3f79b5e10b --- generic/xotcl.h (.../xotcl.h) (revision 2ed7f30b42c12e7ec8ad8ee7b2dd98f5f22d7c3f) +++ generic/xotcl.h (.../xotcl.h) (revision dc6c71950983c8fc6c220a751e3e0e3f79b5e10b) @@ -88,8 +88,8 @@ #define CANONICAL_ARGS 1 */ #define CANONICAL_ARGS 1 +#define TCL85STACK 1 - #if defined PARSE_TRACE_FULL # define PARSE_TRACE 1 #endif Index: generic/xotclStack.c =================================================================== diff -u -r457ad3038f20a9cb9869fbabd3773c00a973d0ee -rdc6c71950983c8fc6c220a751e3e0e3f79b5e10b --- generic/xotclStack.c (.../xotclStack.c) (revision 457ad3038f20a9cb9869fbabd3773c00a973d0ee) +++ generic/xotclStack.c (.../xotclStack.c) (revision dc6c71950983c8fc6c220a751e3e0e3f79b5e10b) @@ -214,6 +214,35 @@ } return countSelfs; } + +/* + * Mark the given obj existing in the callstack as "not destroyed" + */ +static void +CallStackMarkUndestroyed(Tcl_Interp *interp, XOTclObject *obj) { + XOTclCallStack *cs = &RUNTIME_STATE(interp)->cs; + XOTclCallStackContent *csc; + + for (csc = &cs->content[1]; csc <= cs->top; csc++) { + if (obj == csc->self && csc->destroyedCmd) { + /* + * The ref count was incremented, when csc->destroyedCmd + * was set. We revert this first before clearing the + * destroyedCmd. + */ + if (Tcl_Command_refCount(csc->destroyedCmd) > 1) { + Tcl_Command_refCount(csc->destroyedCmd)--; + MEM_COUNT_FREE("command refCount", csc->destroyedCmd); + } + csc->destroyedCmd = 0; + } + } + /* + * mark obj->flags XOTCL_DESTROY_CALLED as NOT CALLED + */ + obj->flags &= ~XOTCL_DESTROY_CALLED; +} + #endif /* NOT TCL85STACK */ Index: generic/xotclStack85.c =================================================================== diff -u -r457ad3038f20a9cb9869fbabd3773c00a973d0ee -rdc6c71950983c8fc6c220a751e3e0e3f79b5e10b --- generic/xotclStack85.c (.../xotclStack85.c) (revision 457ad3038f20a9cb9869fbabd3773c00a973d0ee) +++ generic/xotclStack85.c (.../xotclStack85.c) (revision dc6c71950983c8fc6c220a751e3e0e3f79b5e10b) @@ -331,6 +331,35 @@ return marked; } +/* + * Mark the given obj existing in the callstack as "not destroyed" + */ +static void +CallStackMarkUndestroyed(Tcl_Interp *interp, XOTclObject *obj) { + register Tcl_CallFrame *varFramePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); + + for (; varFramePtr; varFramePtr = Tcl_CallFrame_callerPtr(varFramePtr)) { + if (Tcl_CallFrame_isProcCallFrame(varFramePtr) & (FRAME_IS_XOTCL_METHOD|FRAME_IS_XOTCL_CMETHOD)) { + XOTclCallStackContent *csc = (XOTclCallStackContent *)Tcl_CallFrame_clientData(varFramePtr); + if (obj == csc->self && csc->destroyedCmd) { + /* + * The ref count was incremented, when csc->destroyedCmd + * was set. We revert this first before clearing the + * destroyedCmd. + */ + if (Tcl_Command_refCount(csc->destroyedCmd) > 1) { + Tcl_Command_refCount(csc->destroyedCmd)--; + MEM_COUNT_FREE("command refCount", csc->destroyedCmd); + } + csc->destroyedCmd = 0; + } + } + } + /* + * mark obj->flags XOTCL_DESTROY_CALLED as NOT CALLED + */ + obj->flags &= ~XOTCL_DESTROY_CALLED; +} #endif /* TCL85STACK */