Tcl_Obj * Tcl_NewByteArrayObj(CONST unsigned char *bytes, int length)
Tcl_Obj * Tcl_NewByteArrayObj(bytes, length)
Tcl_NewByteArrayObj will create a new object of byte-array type. Both of these procedures set the object's type to be byte-array and set the object's internal representation to a copy of the array of bytes given by bytes. Tcl_NewByteArrayObj returns a pointer to a newly allocated object with a reference count of zero.
http://www.tcl.tk/man/tcl8.4/TclLib/ByteArrObj.htm
To populate a byte array by a C extension and return it as the result object, the following code might be used:
Tcl_Obj * pObj; unsigned char *pChar; pObj = Tcl_NewObj( ); pChar = Tcl_SetByteArrayLength( pObj, 3); // Dummy population functionality pChar[0] = '\1'; pChar[1] = '\xff'; pChar[2] = '\x80'; Tcl_InvalidateStringRep(pObj); Tcl_SetObjResult(interp,pObj);
Remarks:
if ( Tcl_IsShared(pObj) ) pObj = Tcl_DuplicateObj(pObj);