Index: generic/xotcl.c =================================================================== diff -u -r399b8ad3f5b8723b9738f1ed1d83ed6f01f3c8d1 -r63626dfe7b97728f4103a7873214038e7b15d74e --- generic/xotcl.c (.../xotcl.c) (revision 399b8ad3f5b8723b9738f1ed1d83ed6f01f3c8d1) +++ generic/xotcl.c (.../xotcl.c) (revision 63626dfe7b97728f4103a7873214038e7b15d74e) @@ -517,10 +517,6 @@ #if !defined(NDEBUG) memset(object, 0, sizeof(XOTclObject)); #endif - /* - if (object->cmdName->refCount > 1) { - fprintf(stderr, "--- obj %p %s cmdName->refCount %d\n",object,ObjStr(object->cmdName), object->cmdName->refCount); - }*/ ckfree((char *) object); } } @@ -2045,7 +2041,6 @@ static int XOTcl_DeleteCommandFromToken(Tcl_Interp *interp, Tcl_Command cmd) { - /*fprintf(stderr, "XOTcl_DeleteCommandFromToken %p\n",cmd);*/ CallStackClearCmdReferences(interp, cmd); return Tcl_DeleteCommandFromToken(interp, cmd); } @@ -2084,7 +2079,7 @@ /* * cmd is an aliased object, reduce the refcount */ - /* fprintf(stderr, "NSCleanupNamespace cleanup aliased object %p\n", invokeObj); */ + /*fprintf(stderr, "NSCleanupNamespace cleanup aliased object %p\n", invokeObj); */ XOTclCleanupObject(invokeObj); XOTcl_DeleteCommandFromToken(interp, cmd); } @@ -2095,12 +2090,12 @@ continue; } - /*fprintf(stderr, "NSCleanupNamespace calls DeleteCommandFromToken for %p flags %.6x invokeObj %p\n", - cmd, ((Command *)cmd)->flags, invokeObj); - fprintf(stderr, " cmd = %s\n", Tcl_GetCommandName(interp,cmd)); - fprintf(stderr, " nsPtr = %p\n", ((Command *)cmd)->nsPtr); - fprintf(stderr, " flags %.6x\n", ((Namespace *)((Command *)cmd)->nsPtr)->flags);*/ - + /* fprintf(stderr, "NSCleanupNamespace calls DeleteCommandFromToken for %p flags %.6x invokeObj %p obj %p\n", + cmd, ((Command *)cmd)->flags, invokeObj,object); + fprintf(stderr, " cmd = %s\n", Tcl_GetCommandName(interp,cmd)); + fprintf(stderr, " nsPtr = %p\n", ((Command *)cmd)->nsPtr); + fprintf(stderr, " flags %.6x\n", ((Namespace *)((Command *)cmd)->nsPtr)->flags);*/ + XOTcl_DeleteCommandFromToken(interp, cmd); } } @@ -2545,8 +2540,8 @@ if (object->flags & XOTCL_DURING_DELETE) { return; } - /*fprintf(stderr, "CallStackDoDestroy %p flags %.6x activation %d cmd %p\n", - obj, obj->flags, obj->activationCount, obj->id);*/ + /*fprintf(stderr, "CallStackDoDestroy %p flags %.6x activation %d cmd %p \n", + object, object->flags, object->activationCount, object->id);*/ object->flags |= XOTCL_DURING_DELETE; oid = object->id; /* oid might be freed already, we can't even use (((Command*)oid)->flags & CMD_IS_DELETED) */ @@ -2565,12 +2560,10 @@ object, object->refCount, object->teardown);*/ PrimitiveDestroy((ClientData) object); - - if (!(object->flags & XOTCL_CMD_NOT_FOUND)) { + if (!(object->flags & XOTCL_TCL_DELETE) && !(object->flags & XOTCL_CMD_NOT_FOUND)) { Tcl_Obj *savedObjResult = Tcl_GetObjResult(interp); INCR_REF_COUNT(savedObjResult); - - /*fprintf(stderr, " before DeleteCommandFromToken %p %.6x\n", oid, ((Command*)oid)->flags);*/ + /*fprintf(stderr, " before DeleteCommandFromToken %p object flags %.6x\n", oid, object->flags);*/ Tcl_DeleteCommandFromToken(interp, oid); /* this can change the result */ /*fprintf(stderr, " after DeleteCommandFromToken %p %.6x\n", oid, ((Command*)oid)->flags);*/ Tcl_SetObjResult(interp, savedObjResult); @@ -2617,7 +2610,7 @@ NSDeleteChildren(interp, object->nsPtr); } } - /* fprintf(stderr, " CallStackDestroyObject %p final done\n", object);*/ + /*fprintf(stderr, " CallStackDestroyObject %p DONE\n", object);*/ } /* @@ -6003,7 +5996,7 @@ unknown = 1; } - /*fprintf(stderr, "cmd %p unknown %d result %d\n", cmd, unknown, result);*/ + /* fprintf(stderr, "cmd %p unknown %d result %d\n", cmd, unknown, result);*/ if (result == TCL_OK) { /*fprintf(stderr, "after doCallProcCheck unknown == %d\n", unknown);*/ @@ -6063,6 +6056,7 @@ FilterStackPop(object); XOTclCleanupObject(object); + /*fprintf(stderr, "ObjectDispatch call XOTclCleanupObject %p DONE\n", object);*/ DECR_REF_COUNT(cmdName); /* must be after last dereferencing of obj */ return result; } @@ -7659,6 +7653,8 @@ XOTclObject *object = (XOTclObject*)clientData; Tcl_Interp *interp; + object->flags |= XOTCL_TCL_DELETE; + #ifdef OBJDELETION_TRACE fprintf(stderr, "tclDeletesObject %p obj->id %p flags %.6x\n", object, object->id, object->flags); #endif @@ -7668,6 +7664,7 @@ fprintf(stderr, "... %p %s\n", object, objectName(object)); # endif CallStackDestroyObject(interp, object); + /*fprintf(stderr, "tclDeletesObject %p DONE\n", object);*/ } /* @@ -13225,7 +13222,6 @@ CallStackDestroyObject(interp, object); } - /* fprintf(stderr, "DoDealloc obj=%p done\n", object);*/ return TCL_OK; } Index: generic/xotclInt.h =================================================================== diff -u -r335be502582c8dbf25ed808978d56a8fde39c991 -r63626dfe7b97728f4103a7873214038e7b15d74e --- generic/xotclInt.h (.../xotclInt.h) (revision 335be502582c8dbf25ed808978d56a8fde39c991) +++ generic/xotclInt.h (.../xotclInt.h) (revision 63626dfe7b97728f4103a7873214038e7b15d74e) @@ -352,6 +352,7 @@ #define XOTCL_IS_CLASS 0x0040 #define XOTCL_IS_ROOT_META_CLASS 0x0080 #define XOTCL_IS_ROOT_CLASS 0x0100 +#define XOTCL_TCL_DELETE 0x0200 /* DESTROYED set, when object is physically destroyed with PrimitiveODestroy */ #define XOTCL_CMD_NOT_FOUND 0x1000 #define XOTCL_DURING_DELETE 0x2000 Index: generic/xotclStack85.c =================================================================== diff -u -r9f8816ff85210d4b5a1dbc235f8518a0d3312909 -r63626dfe7b97728f4103a7873214038e7b15d74e --- generic/xotclStack85.c (.../xotclStack85.c) (revision 9f8816ff85210d4b5a1dbc235f8518a0d3312909) +++ generic/xotclStack85.c (.../xotclStack85.c) (revision 63626dfe7b97728f4103a7873214038e7b15d74e) @@ -406,10 +406,10 @@ if (cl) { Namespace *nsPtr = ((Command *)cmd)->nsPtr; cl->object.activationCount ++; - /*fprintf(stderr, "... %s cmd %s cmd ns %p (%s) obj ns %p parent %p\n", + /*fprintf(stderr, "... %s cmd %s cmd ns %p (%s, refCount %d ++) obj ns %p parent %p\n", className(cl), Tcl_GetCommandName(object->teardown, cmd), - ((Command *)cmd)->nsPtr, ((Command *)cmd)->nsPtr->fullName, + nsPtr, nsPtr->fullName, nsPtr->refCount, cl->object.nsPtr,cl->object.nsPtr ? ((Namespace*)cl->object.nsPtr)->parentPtr : NULL);*/ /* incremement the namespace ptr in case tcl tries to delete this namespace @@ -440,7 +440,7 @@ *---------------------------------------------------------------------- * CscFinish -- * - * Counterpart of CscInit(). Decreament activation counts + * Counterpart of CscInit(). Decrement activation counts * and delete objects/classes if necessary. * * Results: @@ -510,6 +510,7 @@ if ((nsPtr->refCount == 0) && (nsPtr->flags & NS_DEAD)) { /* the namspace refcound has reached 0, we have to free it. unfortunately, NamespaceFree() is not exported */ + /* TODO: remove me finally */ fprintf(stderr, "HAVE TO FREE %p\n",nsPtr); /*NamespaceFree(nsPtr);*/ ckfree(nsPtr->fullName); @@ -518,8 +519,8 @@ } } - /*fprintf(stderr, "CscFinish done\n");*/ } + /*fprintf(stderr, "CscFinish done\n");*/ }