Debian Codegraph @

doc/SaveResult.3

raw
1 '\"
2 '\" Copyright (c) 1997 Sun Microsystems, Inc.
3 '\" Contributions from Don Porter, NIST, 2004. (not subject to US copyright)
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 .TH Tcl_SaveResult 3 8.1 Tcl "Tcl Library Procedures"
9 .so man.macros
10 .BS
11 .SH NAME
12 Tcl_SaveInterpState, Tcl_RestoreInterpState, Tcl_DiscardInterpState, Tcl_SaveResult, Tcl_RestoreResult, Tcl_DiscardResult \- save and restore an interpreter's state
13 .SH SYNOPSIS
14 .nf
15 \fB#include <tcl.h>\fR
16 .sp
17 Tcl_InterpState
18 \fBTcl_SaveInterpState\fR(\fIinterp, status\fR)
19 .sp
20 int
21 \fBTcl_RestoreInterpState\fR(\fIinterp, state\fR)
22 .sp
23 \fBTcl_DiscardInterpState\fR(\fIstate\fR)
24 .sp
25 \fBTcl_SaveResult\fR(\fIinterp, savedPtr\fR)
26 .sp
27 \fBTcl_RestoreResult\fR(\fIinterp, savedPtr\fR)
28 .sp
29 \fBTcl_DiscardResult\fR(\fIsavedPtr\fR)
30 .fi
31 .SH ARGUMENTS
32 .AS Tcl_InterpState savedPtr
33 .AP Tcl_Interp *interp in
34 Interpreter for which state should be saved.
35 .AP int status in
36 Return code value to save as part of interpreter state.
37 .AP Tcl_InterpState state in
38 Saved state token to be restored or discarded.
39 .AP Tcl_SavedResult *savedPtr in
40 Pointer to location where interpreter result should be saved or restored.
41 .BE
42 .SH DESCRIPTION
43 .PP
44 These routines allows a C procedure to take a snapshot of the current
45 state of an interpreter so that it can be restored after a call
46 to \fBTcl_Eval\fR or some other routine that modifies the interpreter
47 state. There are two triplets of routines meant to work together.
48 .PP
49 The first triplet stores the snapshot of interpreter state in
50 an opaque token returned by \fBTcl_SaveInterpState\fR. That token
51 value may then be passed back to one of \fBTcl_RestoreInterpState\fR
52 or \fBTcl_DiscardInterpState\fR, depending on whether the interp
53 state is to be restored. So long as one of the latter two routines
54 is called, Tcl will take care of memory management.
55 .PP
56 The second triplet stores the snapshot of only the interpreter
57 result (not its complete state) in memory allocated by the caller.
58 These routines are passed a pointer to \fBTcl_SavedResult\fR
59 that is used to store enough information to restore the interpreter result.
60 \fBTcl_SavedResult\fR can be allocated on the stack of the calling
61 procedure. These routines do not save the state of any error
62 information in the interpreter (e.g. the \fB\-errorcode\fR or
63 \fB\-errorinfo\fR return options, when an error is in progress).
64 .PP
65 Because the routines \fBTcl_SaveInterpState\fR,
66 \fBTcl_RestoreInterpState\fR, and \fBTcl_DiscardInterpState\fR perform
67 a superset of the functions provided by the other routines,
68 any new code should only make use of the more powerful routines.
69 The older, weaker routines \fBTcl_SaveResult\fR, \fBTcl_RestoreResult\fR,
70 and \fBTcl_DiscardResult\fR continue to exist only for the sake
71 of existing programs that may already be using them.
72 .PP
73 \fBTcl_SaveInterpState\fR takes a snapshot of those portions of
74 interpreter state that make up the full result of script evaluation.
75 This include the interpreter result, the return code (passed in
76 as the \fIstatus\fR argument, and any return options, including
77 \fB\-errorinfo\fR and \fB\-errorcode\fR when an error is in progress.
78 This snapshot is returned as an opaque token of type \fBTcl_InterpState\fR.
79 The call to \fBTcl_SaveInterpState\fR does not itself change the
80 state of the interpreter. Unlike \fBTcl_SaveResult\fR, it does
81 not reset the interpreter.
82 .PP
83 \fBTcl_RestoreInterpState\fR accepts a \fBTcl_InterpState\fR token
84 previously returned by \fBTcl_SaveInterpState\fR and restores the
85 state of the interp to the state held in that snapshot. The return
86 value of \fBTcl_RestoreInterpState\fR is the status value originally
87 passed to \fBTcl_SaveInterpState\fR when the snapshot token was
88 created.
89 .PP
90 \fBTcl_DiscardInterpState\fR is called to release a \fBTcl_InterpState\fR
91 token previously returned by \fBTcl_SaveInterpState\fR when that
92 snapshot is not to be restored to an interp.
93 .PP
94 The \fBTcl_InterpState\fR token returned by \fBTcl_SaveInterpState\fR
95 must eventually be passed to either \fBTcl_RestoreInterpState\fR
96 or \fBTcl_DiscardInterpState\fR to avoid a memory leak. Once
97 the \fBTcl_InterpState\fR token is passed to one of them, the
98 token is no longer valid and should not be used anymore.
99 .PP
100 \fBTcl_SaveResult\fR moves the string and value results
101 of \fIinterp\fR into the location specified by \fIstatePtr\fR.
102 \fBTcl_SaveResult\fR clears the result for \fIinterp\fR and
103 leaves the result in its normal empty initialized state.
104 .PP
105 \fBTcl_RestoreResult\fR moves the string and value results from
106 \fIstatePtr\fR back into \fIinterp\fR. Any result or error that was
107 already in the interpreter will be cleared. The \fIstatePtr\fR is left
108 in an uninitialized state and cannot be used until another call to
109 \fBTcl_SaveResult\fR.
110 .PP
111 \fBTcl_DiscardResult\fR releases the saved interpreter state
112 stored at \fBstatePtr\fR. The state structure is left in an
113 uninitialized state and cannot be used until another call to
114 \fBTcl_SaveResult\fR.
115 .PP
116 Once \fBTcl_SaveResult\fR is called to save the interpreter
117 result, either \fBTcl_RestoreResult\fR or
118 \fBTcl_DiscardResult\fR must be called to properly clean up the
119 memory associated with the saved state.
120 .SH KEYWORDS
121 result, state, interp