182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
-
+
|
unsigned char bytes[TCLFLEXARRAY]; /* The array of bytes. The actual size of this
* field depends on the 'allocated' field
* above. */
} ByteArray;
#define BYTEARRAY_MAX_LEN (TCL_SIZE_MAX - (Tcl_Size)offsetof(ByteArray, bytes))
#define BYTEARRAY_SIZE(len) \
( (len < 0 || BYTEARRAY_MAX_LEN < (len)) \
( (len < 0 || BYTEARRAY_MAX_LEN < (len)) \
? (Tcl_Panic("negative length specified or max size of a Tcl value exceeded"), 0) \
: (offsetof(ByteArray, bytes) + (len)) )
#define GET_BYTEARRAY(irPtr) ((ByteArray *) (irPtr)->twoPtrValue.ptr1)
#define SET_BYTEARRAY(irPtr, baPtr) \
(irPtr)->twoPtrValue.ptr1 = (baPtr)
int
|
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
|
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
|
-
+
|
*----------------------------------------------------------------------
*/
unsigned char *
Tcl_SetByteArrayLength(
Tcl_Obj *objPtr, /* The ByteArray object. */
Tcl_Size numBytes) /* Number of bytes in resized array
* Must be >= 0 */
* Must be >= 0 */
{
ByteArray *byteArrayPtr;
Tcl_ObjInternalRep *irPtr;
assert(numBytes >= 0);
if (Tcl_IsShared(objPtr)) {
Tcl_Panic("%s called with shared object", "Tcl_SetByteArrayLength");
|
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
|
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
|
+
-
-
+
+
-
-
-
+
-
|
if ((BYTEARRAY_MAX_LEN - byteArrayPtr->used) < len) {
/* Will wrap around !! */
Tcl_Panic("max size of a byte array exceeded");
}
needed = byteArrayPtr->used + len;
if (needed > byteArrayPtr->allocated) {
Tcl_Size newCapacity;
byteArrayPtr =
(ByteArray *)TclReallocElemsEx(byteArrayPtr,
byteArrayPtr = (ByteArray *)
TclReallocElemsEx(byteArrayPtr, needed, 1,
needed,
1,
offsetof(ByteArray, bytes),
offsetof(ByteArray, bytes), &newCapacity);
&newCapacity);
byteArrayPtr->allocated = newCapacity;
SET_BYTEARRAY(irPtr, byteArrayPtr);
}
if (bytes) {
memcpy(byteArrayPtr->bytes + byteArrayPtr->used, bytes, len);
}
|