Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/doc/SaveResult.3 @ 25

Last change on this file since 25 was 25, checked in by landauf, 16 years ago

added tcl to libs

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