Debian Codegraph @

doc/ByteArrObj.3

raw
1 '\"
2 '\" Copyright (c) 1997 Sun Microsystems, Inc.
3 '\"
4 '\" See the file "license.terms" for information on usage and redistribution
5 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6 '\"
7 .TH Tcl_ByteArrayObj 3 8.1 Tcl "Tcl Library Procedures"
8 .so man.macros
9 .BS
10 .SH NAME
11 Tcl_NewByteArrayObj, Tcl_SetByteArrayObj, Tcl_GetByteArrayFromObj, Tcl_SetByteArrayLength \- manipulate Tcl values as a arrays of bytes
12 .SH SYNOPSIS
13 .nf
14 \fB#include <tcl.h>\fR
15 .sp
16 Tcl_Obj *
17 \fBTcl_NewByteArrayObj\fR(\fIbytes, length\fR)
18 .sp
19 void
20 \fBTcl_SetByteArrayObj\fR(\fIobjPtr, bytes, length\fR)
21 .sp
22 unsigned char *
23 \fBTcl_GetByteArrayFromObj\fR(\fIobjPtr, lengthPtr\fR)
24 .sp
25 unsigned char *
26 \fBTcl_SetByteArrayLength\fR(\fIobjPtr, length\fR)
27 .SH ARGUMENTS
28 .AS "const unsigned char" *lengthPtr in/out
29 .AP "const unsigned char" *bytes in
30 The array of bytes used to initialize or set a byte-array value. May be NULL
31 even if \fIlength\fR is non-zero.
32 .AP int length in
33 The length of the array of bytes. It must be >= 0.
34 .AP Tcl_Obj *objPtr in/out
35 For \fBTcl_SetByteArrayObj\fR, this points to the value to be converted to
36 byte-array type. For \fBTcl_GetByteArrayFromObj\fR and
37 \fBTcl_SetByteArrayLength\fR, this points to the value from which to get
38 the byte-array value; if \fIobjPtr\fR does not already point to a byte-array
39 value, it will be converted to one.
40 .AP int *lengthPtr out
41 If non-NULL, filled with the length of the array of bytes in the value.
42 .BE
43
44 .SH DESCRIPTION
45 .PP
46 These procedures are used to create, modify, and read Tcl byte-array values
47 from C code. Byte-array values are typically used to hold the
48 results of binary IO operations or data structures created with the
49 \fBbinary\fR command. In Tcl, an array of bytes is not equivalent to a
50 string. Conceptually, a string is an array of Unicode characters, while a
51 byte-array is an array of 8-bit quantities with no implicit meaning.
52 Accessor functions are provided to get the string representation of a
53 byte-array or to convert an arbitrary value to a byte-array. Obtaining the
54 string representation of a byte-array value (by calling
55 \fBTcl_GetStringFromObj\fR) produces a properly formed UTF-8 sequence with a
56 one-to-one mapping between the bytes in the internal representation and the
57 UTF-8 characters in the string representation.
58 .PP
59 \fBTcl_NewByteArrayObj\fR and \fBTcl_SetByteArrayObj\fR will
60 create a new value of byte-array type or modify an existing value to have a
61 byte-array type. Both of these procedures set the value's type to be
62 byte-array and set the value's internal representation to a copy of the
63 array of bytes given by \fIbytes\fR. \fBTcl_NewByteArrayObj\fR returns a
64 pointer to a newly allocated value with a reference count of zero.
65 \fBTcl_SetByteArrayObj\fR invalidates any old string representation and, if
66 the value is not already a byte-array value, frees any old internal
67 representation. If \fIbytes\fR is NULL then the new byte array contains
68 arbitrary values.
69 .PP
70 \fBTcl_GetByteArrayFromObj\fR converts a Tcl value to byte-array type and
71 returns a pointer to the value's new internal representation as an array of
72 bytes. The length of this array is stored in \fIlengthPtr\fR if
73 \fIlengthPtr\fR is non-NULL. The storage for the array of bytes is owned by
74 the value and should not be freed. The contents of the array may be
75 modified by the caller only if the value is not shared and the caller
76 invalidates the string representation.
77 .PP
78 \fBTcl_SetByteArrayLength\fR converts the Tcl value to byte-array type
79 and changes the length of the value's internal representation as an
80 array of bytes. If \fIlength\fR is greater than the space currently
81 allocated for the array, the array is reallocated to the new length; the
82 newly allocated bytes at the end of the array have arbitrary values. If
83 \fIlength\fR is less than the space currently allocated for the array,
84 the length of array is reduced to the new length. The return value is a
85 pointer to the value's new array of bytes.
86
87 .SH "SEE ALSO"
88 Tcl_GetStringFromObj, Tcl_NewObj, Tcl_IncrRefCount, Tcl_DecrRefCount
89
90 .SH KEYWORDS
91 value, binary data, byte array, utf, unicode, internationalization