Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 329a7789680bdb16195fdd4f40ed7415cc67740e
Ticket: 436332ffffffffffffffffffffffffffffffffff
Need way to append bytearray objs
User & Date: jgullingsrud on 2003-09-22 12:06:43
Changes

  1. icomment:
    Logged In: YES 
    user_id=19365
    
    Here's a patch to tclVar.c (the TclPtrSetVar routine) that
    makes the append command respect ByteArray types.  It checks
    whether the object being appended to is of ByteArray type
    and, if so, retains this type and converts objects to be
    appended to ByteArray before appending their bytes.  Diff is
    from Tcl 8.4.4.
    
    --- tclVar.c.orig 2003-09-21 18:57:43.000000000 -0700
    +++ tclVar.c  2003-09-21 18:58:42.000000000 -0700
    @@ -1659,8 +1659,25 @@
            oldValuePtr = varPtr->value.objPtr;
            Tcl_IncrRefCount(oldValuePtr); /* since var is ref */
        }
    -   Tcl_AppendObjToObj(oldValuePtr, newValuePtr);
    -     }
    +    /*
    +     * If oldValuePtr is a ByteArray, append as bytes
    +     */
    +    if (oldValuePtr->typePtr == &tclByteArrayType) {
    +      unsigned char *oldbytes, *newbytes, *oldandnewbytes;
    +      int oldlength=-1, newlength=-1;
    +      oldbytes = Tcl_GetByteArrayFromObj(oldValuePtr,
    &oldlength);
    +      newbytes = Tcl_GetByteArrayFromObj(newValuePtr,
    &newlength);
    +      /*
    +       * Ok to to call SetByteArrayLength because we've
    already checked
    +       * if oldValuePtr is shared.
    +       */
    +      oldandnewbytes = Tcl_SetByteArrayLength(oldValuePtr,
    +          oldlength+newlength);
    +      memcpy(oldandnewbytes+(size_t)oldlength, newbytes,
    (size_t)newlength);
    +    } else {
    +     Tcl_AppendObjToObj(oldValuePtr, newValuePtr);
    +    }
    +      }
      }
         } else if (newValuePtr != oldValuePtr) {
      /*
    
    
    
    
    
  2. login: "jgullingsrud"
  3. mimetype: "text/plain"
  4. username: "jgullingsrud"