1Tcl_ByteArrayObj(3) Tcl Library Procedures Tcl_ByteArrayObj(3)
2
3
4
5______________________________________________________________________________
6
8 Tcl_NewByteArrayObj, Tcl_SetByteArrayObj, Tcl_GetByteArrayFromObj,
9 Tcl_SetByteArrayLength - manipulate Tcl objects as a arrays of bytes
10
12 #include <tcl.h>
13
14 Tcl_Obj *
15 Tcl_NewByteArrayObj(bytes, length)
16
17 void
18 Tcl_SetByteArrayObj(objPtr, bytes, length)
19
20 unsigned char *
21 Tcl_GetByteArrayFromObj(objPtr, lengthPtr)
22
23 unsigned char *
24 Tcl_SetByteArrayLength(objPtr, length)
25
27 CONST unsigned char *bytes(in)
28 The array of bytes used to ini‐
29 tialize or set a byte-array
30 object.
31
32 int length (in) The length of the array of
33 bytes. It must be >= 0.
34
35 Tcl_Obj *objPtr (in/out) For Tcl_SetByteArrayObj, this
36 points to the object to be con‐
37 verted to byte-array type. For
38 Tcl_GetByteArrayFromObj and
39 Tcl_SetByteArrayLength, this
40 points to the object from which
41 to get the byte-array value; if
42 objPtr does not already point to
43 a byte-array object, it will be
44 converted to one.
45
46 int *lengthPtr (out) If non-NULL, filled with the
47 length of the array of bytes in
48 the object.
49_________________________________________________________________
50
51
53 These procedures are used to create, modify, and read Tcl byte-array
54 objects from C code. Byte-array objects are typically used to hold the
55 results of binary IO operations or data structures created with the
56 binary command. In Tcl, an array of bytes is not equivalent to a
57 string. Conceptually, a string is an array of Unicode characters,
58 while a byte-array is an array of 8-bit quantities with no implicit
59 meaning. Accesser functions are provided to get the string representa‐
60 tion of a byte-array or to convert an arbitrary object to a byte-array.
61 Obtaining the string representation of a byte-array object (by calling
62 Tcl_GetStringFromObj) produces a properly formed UTF-8 sequence with a
63 one-to-one mapping between the bytes in the internal representation and
64 the UTF-8 characters in the string representation.
65
66 Tcl_NewByteArrayObj and Tcl_SetByteArrayObj will create a new object of
67 byte-array type or modify an existing object to have a byte-array type.
68 Both of these procedures set the object's type to be byte-array and set
69 the object's internal representation to a copy of the array of bytes
70 given by bytes. Tcl_NewByteArrayObj returns a pointer to a newly allo‐
71 cated object with a reference count of zero. Tcl_SetByteArrayObj
72 invalidates any old string representation and, if the object is not
73 already a byte-array object, frees any old internal representation.
74
75 Tcl_GetByteArrayFromObj converts a Tcl object to byte-array type and
76 returns a pointer to the object's new internal representation as an
77 array of bytes. The length of this array is stored in lengthPtr if
78 lengthPtr is non-NULL. The storage for the array of bytes is owned by
79 the object and should not be freed. The contents of the array may be
80 modified by the caller only if the object is not shared and the caller
81 invalidates the string representation.
82
83 Tcl_SetByteArrayLength converts the Tcl object to byte-array type and
84 changes the length of the object's internal representation as an array
85 of bytes. If length is greater than the space currently allocated for
86 the array, the array is reallocated to the new length; the newly allo‐
87 cated bytes at the end of the array have arbitrary values. If length
88 is less than the space currently allocated for the array, the length of
89 array is reduced to the new length. The return value is a pointer to
90 the object's new array of bytes.
91
92
94 Tcl_GetStringFromObj, Tcl_NewObj, Tcl_IncrRefCount, Tcl_DecrRefCount
95
96
98 object, byte array, utf, unicode, internationalization
99
100
101
102Tcl 8.1 Tcl_ByteArrayObj(3)