OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [insight/] [tcl/] [doc/] [SetResult.3] - Blame information for rev 1765

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
'\"
2
'\" Copyright (c) 1989-1993 The Regents of the University of California.
3
'\" Copyright (c) 1994-1997 Sun Microsystems, Inc.
4
'\"
5
'\" See the file "license.terms" for information on usage and redistribution
6
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7
'\"
8
'\" RCS: @(#) $Id: SetResult.3,v 1.1.1.1 2002-01-16 10:25:24 markom Exp $
9
'\"
10
.so man.macros
11
.TH Tcl_SetResult 3 7.5 Tcl "Tcl Library Procedures"
12
.BS
13
.SH NAME
14
Tcl_SetObjResult, Tcl_GetObjResult, Tcl_SetResult, Tcl_GetStringResult, Tcl_AppendResult, Tcl_AppendElement, Tcl_ResetResult \- manipulate Tcl result
15
.SH SYNOPSIS
16
.nf
17
\fB#include \fR
18
.sp
19
\fBTcl_SetObjResult\fR(\fIinterp, objPtr\fR)
20
.sp
21
Tcl_Obj *
22
\fBTcl_GetObjResult\fR(\fIinterp\fR)
23
.sp
24
\fBTcl_SetResult\fR(\fIinterp, string, freeProc\fR)
25
.sp
26
char *
27
\fBTcl_GetStringResult\fR(\fIinterp\fR)
28
.sp
29
\fBTcl_AppendResult\fR(\fIinterp, string, string, ... , \fB(char *) NULL\fR)
30
.sp
31
\fBTcl_AppendElement\fR(\fIinterp, string\fR)
32
.sp
33
\fBTcl_ResetResult\fR(\fIinterp\fR)
34
.sp
35
\fBTcl_FreeResult\fR(\fIinterp\fR)
36
.SH ARGUMENTS
37
.AS Tcl_FreeProc freeProc
38
.AP Tcl_Interp *interp out
39
Interpreter whose result is to be modified or read.
40
.AP Tcl_Obj *objPtr in
41
Object value to become result for \fIinterp\fR.
42
.AP char *string in
43
String value to become result for \fIinterp\fR or to be
44
appended to the existing result.
45
.AP Tcl_FreeProc *freeProc in
46
Address of procedure to call to release storage at
47
\fIstring\fR, or \fBTCL_STATIC\fR, \fBTCL_DYNAMIC\fR, or
48
\fBTCL_VOLATILE\fR.
49
.BE
50
 
51
.SH DESCRIPTION
52
.PP
53
The procedures described here are utilities for manipulating the
54
result value in a Tcl interpreter.
55
The interpreter result may be either a Tcl object or a string.
56
For example, \fBTcl_SetObjResult\fR and \fBTcl_SetResult\fR
57
set the interpreter result to, respectively, an object and a string.
58
Similarly, \fBTcl_GetObjResult\fR and \fBTcl_GetStringResult\fR
59
return the interpreter result as an object and as a string.
60
The procedures always keep the string and object forms
61
of the interpreter result consistent.
62
For example, if \fBTcl_SetObjResult\fR is called to set
63
the result to an object,
64
then \fBTcl_GetStringResult\fR is called,
65
it will return the object's string value.
66
.PP
67
\fBTcl_SetObjResult\fR
68
arranges for \fIobjPtr\fR to be the result for \fIinterp\fR,
69
replacing any existing result.
70
The result is left pointing to the object
71
referenced by \fIobjPtr\fR.
72
\fIobjPtr\fR's reference count is incremented
73
since there is now a new reference to it from \fIinterp\fR.
74
The reference count for any old result object
75
is decremented and the old result object is freed if no
76
references to it remain.
77
.PP
78
\fBTcl_GetObjResult\fR returns the result for \fIinterp\fR as an object.
79
The object's reference count is not incremented;
80
if the caller needs to retain a long-term pointer to the object
81
they should use \fBTcl_IncrRefCount\fR to increment its reference count
82
in order to keep it from being freed too early or accidently changed.
83
.PP
84
\fBTcl_SetResult\fR
85
arranges for \fIstring\fR to be the result for the current Tcl
86
command in \fIinterp\fR, replacing any existing result.
87
The \fIfreeProc\fR argument specifies how to manage the storage
88
for the \fIstring\fR argument;
89
it is discussed in the section
90
\fBTHE TCL_FREEPROC ARGUMENT TO TCL_SETRESULT\fR below.
91
If \fIstring\fR is \fBNULL\fR, then \fIfreeProc\fR is ignored
92
and \fBTcl_SetResult\fR
93
re-initializes \fIinterp\fR's result to point to an empty string.
94
.PP
95
\fBTcl_GetStringResult\fR returns the result for \fIinterp\fR as an string.
96
If the result was set to an object by a \fBTcl_SetObjResult\fR call,
97
the object form will be converted to a string and returned.
98
If the object's string representation contains null bytes,
99
this conversion will lose information.
100
For this reason, programmers are encouraged to
101
write their code to use the new object API procedures
102
and to call \fBTcl_GetObjResult\fR instead.
103
.PP
104
\fBTcl_ResetResult\fR clears the result for \fIinterp\fR
105
and leaves the result in its normal empty initialized state.
106
If the result is an object,
107
its reference count is decremented and the result is left
108
pointing to an unshared object representing an empty string.
109
If the result is a dynamically allocated string, its memory is free*d
110
and the result is left as a empty string.
111
\fBTcl_ResetResult\fR also clears the error state managed by
112
\fBTcl_AddErrorInfo\fR, \fBTcl_AddObjErrorInfo\fR,
113
and \fBTcl_SetErrorCode\fR.
114
 
115
.SH OLD STRING PROCEDURES
116
.PP
117
Use of the following procedures is deprecated
118
since they manipulate the Tcl result as a string.
119
Procedures such as \fBTcl_SetObjResult\fR
120
that manipulate the result as an object
121
can be significantly more efficient.
122
.PP
123
\fBTcl_AppendResult\fR makes it easy to build up Tcl results in pieces.
124
It takes each of its \fIstring\fR arguments and appends them in order
125
to the current result associated with \fIinterp\fR.
126
If the result is in its initialized empty state (e.g. a command procedure
127
was just invoked or \fBTcl_ResetResult\fR was just called),
128
then \fBTcl_AppendResult\fR sets the result to the concatenation of
129
its \fIstring\fR arguments.
130
\fBTcl_AppendResult\fR may be called repeatedly as additional pieces
131
of the result are produced.
132
\fBTcl_AppendResult\fR takes care of all the
133
storage management issues associated with managing \fIinterp\fR's
134
result, such as allocating a larger result area if necessary.
135
It also converts the current interpreter result from an object
136
to a string, if necessary, before appending the argument strings.
137
Any number of \fIstring\fR arguments may be passed in a single
138
call; the last argument in the list must be a NULL pointer.
139
.PP
140
\fBTcl_AppendElement\fR is similar to \fBTcl_AppendResult\fR in
141
that it allows results to be built up in pieces.
142
However, \fBTcl_AppendElement\fR takes only a single \fIstring\fR
143
argument and it appends that argument to the current result
144
as a proper Tcl list element.
145
\fBTcl_AppendElement\fR adds backslashes or braces if necessary
146
to ensure that \fIinterp\fR's result can be parsed as a list and that
147
\fIstring\fR will be extracted as a single element.
148
Under normal conditions, \fBTcl_AppendElement\fR will add a space
149
character to \fIinterp\fR's result just before adding the new
150
list element, so that the list elements in the result are properly
151
separated.
152
However if the new list element is the first in a list or sub-list
153
(i.e. \fIinterp\fR's current result is empty, or consists of the
154
single character ``{'', or ends in the characters `` {'') then no
155
space is added.
156
.PP
157
\fBTcl_FreeResult\fR performs part of the work
158
of \fBTcl_ResetResult\fR.
159
It frees up the memory associated with \fIinterp\fR's result.
160
It also sets \fIinterp->freeProc\fR to zero, but doesn't
161
change \fIinterp->result\fR or clear error state.
162
\fBTcl_FreeResult\fR is most commonly used when a procedure
163
is about to replace one result value with another.
164
 
165
.SH DIRECT ACCESS TO INTERP->RESULT IS DEPRECATED
166
.PP
167
It used to be legal for programs to
168
directly read and write \fIinterp->result\fR
169
to manipulate the interpreter result.
170
Direct access to \fIinterp->result\fR is now strongly deprecated
171
because it can make the result's string and object forms inconsistent.
172
Programs should always read the result
173
using the procedures \fBTcl_GetObjResult\fR or \fBTcl_GetStringResult\fR,
174
and write the result using \fBTcl_SetObjResult\fR or \fBTcl_SetResult\fR.
175
 
176
.SH THE TCL_FREEPROC ARGUMENT TO TCL_SETRESULT
177
.PP
178
\fBTcl_SetResult\fR's \fIfreeProc\fR argument specifies how
179
the Tcl system is to manage the storage for the \fIstring\fR argument.
180
If \fBTcl_SetResult\fR or \fBTcl_SetObjResult\fR are called
181
at a time when \fIinterp\fR holds a string result,
182
they do whatever is necessary to dispose of the old string result
183
(see the \fBTcl_Interp\fR manual entry for details on this).
184
.PP
185
If \fIfreeProc\fR is \fBTCL_STATIC\fR it means that \fIstring\fR
186
refers to an area of static storage that is guaranteed not to be
187
modified until at least the next call to \fBTcl_Eval\fR.
188
If \fIfreeProc\fR
189
is \fBTCL_DYNAMIC\fR it means that \fIstring\fR was allocated with a call
190
to \fBTcl_Alloc\fR and is now the property of the Tcl system.
191
\fBTcl_SetResult\fR will arrange for the string's storage to be
192
released by calling \fBTcl_Free\fR when it is no longer needed.
193
If \fIfreeProc\fR is \fBTCL_VOLATILE\fR it means that \fIstring\fR
194
points to an area of memory that is likely to be overwritten when
195
\fBTcl_SetResult\fR returns (e.g. it points to something in a stack frame).
196
In this case \fBTcl_SetResult\fR will make a copy of the string in
197
dynamically allocated storage and arrange for the copy to be the
198
result for the current Tcl command.
199
.PP
200
If \fIfreeProc\fR isn't one of the values \fBTCL_STATIC\fR,
201
\fBTCL_DYNAMIC\fR, and \fBTCL_VOLATILE\fR, then it is the address
202
of a procedure that Tcl should call to free the string.
203
This allows applications to use non-standard storage allocators.
204
When Tcl no longer needs the storage for the string, it will
205
call \fIfreeProc\fR. \fIFreeProc\fR should have arguments and
206
result that match the type \fBTcl_FreeProc\fR:
207
.CS
208
typedef void Tcl_FreeProc(char *\fIblockPtr\fR);
209
.CE
210
When \fIfreeProc\fR is called, its \fIblockPtr\fR will be set to
211
the value of \fIstring\fR passed to \fBTcl_SetResult\fR.
212
 
213
.SH "SEE ALSO"
214
Tcl_AddErrorInfo, Tcl_CreateObjCommand, Tcl_SetErrorCode, Tcl_Interp
215
 
216
.SH KEYWORDS
217
append, command, element, list, object, result, return value, interpreter

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.