Subject: Re: Tcl_Obj of type "bytearray" - DN [1]


Jeffrey Hobbs <jeffrey.hobbs@scriptics.com> - 15 Oct 1999 - comp.lang.tcl

 Mike Weiblen wrote:
 > I'm trying to pass binary data from a Tcl variable thru a Tcl_Obj to a
 > C++ extension, but the Tcl_Obj reports a different length; the Tcl
 > variable is length 256, but the Tcl_Obj says 385.  My hunch is that an
 > undesired Unicode conversion is occuring, but how to prevent??
 >
 > I realize its bad form to reach into the Tcl_Obj struct directly, but I
 > suspected Tcl_GetStringFromObj() as the culprit; is there something like
 > a Tcl_GetBinaryFromObj() to use instead?  Likewise I considered [string
 > length] was causing a string conversion, but removing it doesn't help
 > (the type stays bytearray anyway)

 You want to use Tcl_GetByteArrayFromObj, which will avoid the
 conversion that you are experiencing.  The [string length]
 magically checks whether you are operating on a ByteArray or
 a String.

 --
    Jeffrey Hobbs                          The Tcl Guy
    jeffrey.hobbs at scriptics.com         Scriptics Corp.

Last modified
1999-10-19

(195.108.246.51)

Note: you are looking at
the snapshot of an old wiki
- much of this information
is likely to be very outdated