Artifacts Associated With Ticket 756883ffffffffff
Ticket change [c2aa33b136] (rid 111522) by ysutjandra on 2003-06-18 22:24:41:
- assignee initialized to: "msofer"
- cmimetype initialized to: "text/plain"
- comment initialized to:
Hi, In tclResult.c inside function ResetObjResult(iPtr) Would you consider instead of... if (Tcl_IsShared(objResultPtr)) { ... } else { if ((objResultPtr->bytes != NULL) && (objResultPtr->bytes != tclEmptyStringRep)) { ckfree((char *) objResultPtr->bytes); } objResultPtr->bytes = tclEmptyStringRep; objResultPtr->length = 0; if ((objResultPtr->typePtr != NULL) && (objResultPtr->typePtr->freeIntRepProc ! = NULL)) { objResultPtr->typePtr->freeIntRepProc (objResultPtr); } objResultPtr->typePtr = (Tcl_ObjType *) NULL; } consider... if (Tcl_IsShared(objResultPtr)) { ... } else { TclDecrRefCount(objResultPtr); /* This automatically calls the free function if result object holds its own internal representation. And depending on the free function of the registered type It might already invalidate the 'bytes' field of the Tcl_Obj and set the 'bytes' to NULL and the 'length' to zero. */ if ((objResultPtr->bytes != NULL) && (objResultPtr->bytes != tclEmptyStringRep)) { ckfree((char *) objResultPtr->bytes); } objResultPtr->bytes = tclEmptyStringRep; objResultPtr->length = 0; objResultPtr->typePtr = (Tcl_ObjType *) NULL; Tcl_IncrRefCount(objResultPtr); } I'm not sure if it's a bug, but with the current implementation, the registered free function is called when refCount is still one. Moreover, if the result object holds its internal representation, the bytes field may hold ths string that is obtained from calling Tcl_UpdateStringObj, which calls the registered UpdateStringProc. The software client is free to use its own memory allocator when updating the bytes string. So I think it's a bug to assume that the bytes is allocated using ckalloc. -- Yohan - foundin initialized to: "None"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "ysutjandra"
- subsystem initialized to: "10. Objects"
- title initialized to:
ResetObjResult to call registered free function first time
- type initialized to: "RFE"
Ticket change [d1d55acf1c] (rid 113422) by jenglish on 2003-09-06 08:58:53:
- icomment:
Logged In: YES user_id=68433 > The software client is free to use its own memory allocator > when updating the bytes string This is incorrect: according to Tcl_RegisterObjType(3), the 'updateStringProc' method *must* use Tcl_Alloc or ckalloc to allocate storage for the byte array.
- login: "jenglish"
- mimetype: "text/plain"
- username: "jenglish"
- icomment:
Ticket change [c584e21b7e] (rid 112014) by ysutjandra on 2003-09-09 00:17:52:
- icomment:
Logged In: YES user_id=799156 You're right... we use Tcl_Alloc to allocate space for string bytes. But still please consider using Tcl_DecrRefCount and Tcl_IncrRefCount instead of calling the free function directly. The reason is that my program flags an error if the free function is called when refCount is still greater than zero. This flag is useful because a specific object type that we implement will not be able to be recreated once it is deleted. So the flag is to notify users that the current object held by a tcl variable has been freed and they should recreate the object themselves. -- Yohan
- login: "ysutjandra"
- mimetype: "text/plain"
- username: "ysutjandra"
- icomment:
Ticket change [538e4901e0] (rid 93778) by msofer on 2005-11-26 17:49:54:
- closedate changed to: "2005-11-26T10:49:54"
- closer changed to: "msofer"
- icomment:
Logged In: YES user_id=148712 The freeProc for any Tcl_Obj type may be called with any value of refCount - it will happen if the Tcl_Obj shimmers. A Tcl_Obj's internal rep must be able to be reconstructed from the string representation, by design.
- login: "msofer"
- mimetype: "text/plain"
- resolution changed to: "Rejected"
- status changed to: "Closed"
- username: "msofer"