Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: c2aa33b13690b581658364cf23ad1f3b3cb2400c
Ticket: 756883ffffffffffffffffffffffffffffffffff
ResetObjResult to call registered free function first time
User & Date: ysutjandra on 2003-06-18 22:24:41
Changes

  1. assignee changed to: "msofer"
  2. cmimetype changed to: "text/plain"
  3. comment changed 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
    
  4. foundin changed to: "None"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "ysutjandra"
  9. subsystem changed to: "10. Objects"
  10. title changed to:
    ResetObjResult to call registered free function first time
    
  11. type changed to: "RFE"