[25] | 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 |
---|
| 14 | Tcl_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 |
---|
| 19 | Tcl_InterpState |
---|
| 20 | \fBTcl_SaveInterpState\fR(\fIinterp, status\fR) |
---|
| 21 | .sp |
---|
| 22 | int |
---|
| 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 |
---|
| 35 | Interpreter for which state should be saved. |
---|
| 36 | .AP int status in |
---|
| 37 | Return code value to save as part of interpreter state. |
---|
| 38 | .AP Tcl_InterpState state in |
---|
| 39 | Saved state token to be restored or discarded. |
---|
| 40 | .AP Tcl_SavedResult *savedPtr in |
---|
| 41 | Pointer to location where interpreter result should be saved or restored. |
---|
| 42 | .BE |
---|
| 43 | |
---|
| 44 | .SH DESCRIPTION |
---|
| 45 | .PP |
---|
| 46 | .VS 8.5 |
---|
| 47 | These routines allows a C procedure to take a snapshot of the current |
---|
| 48 | state of an interpreter so that it can be restored after a call |
---|
| 49 | to \fBTcl_Eval\fR or some other routine that modifies the interpreter |
---|
| 50 | state. There are two triplets of routines meant to work together. |
---|
| 51 | .PP |
---|
| 52 | The first triplet stores the snapshot of interpreter state in |
---|
| 53 | an opaque token returned by \fBTcl_SaveInterpState\fR. That token |
---|
| 54 | value may then be passed back to one of \fBTcl_RestoreInterpState\fR |
---|
| 55 | or \fBTcl_DiscardInterpState\fR, depending on whether the interp |
---|
| 56 | state is to be restored. So long as one of the latter two routines |
---|
| 57 | is called, Tcl will take care of memory management. |
---|
| 58 | .PP |
---|
| 59 | The second triplet stores the snapshot of only the interpreter |
---|
| 60 | result (not its complete state) in memory allocated by the caller. |
---|
| 61 | These routines are passed a pointer to a \fBTcl_SavedResult\fR structure |
---|
| 62 | that is used to store enough information to restore the interpreter result. |
---|
| 63 | This structure can be allocated on the stack of the calling |
---|
| 64 | procedure. These routines do not save the state of any error |
---|
| 65 | information in the interpreter (e.g. the \fB\-errorcode\fR or |
---|
| 66 | \fB\-errorinfo\fR return options, when an error is in progress). |
---|
| 67 | .PP |
---|
| 68 | Because the routines \fBTcl_SaveInterpState\fR, |
---|
| 69 | \fBTcl_RestoreInterpState\fR, and \fBTcl_DiscardInterpState\fR perform |
---|
| 70 | a superset of the functions provided by the other routines, |
---|
| 71 | any new code should only make use of the more powerful routines. |
---|
| 72 | The older, weaker routines \fBTcl_SaveResult\fR, \fBTcl_RestoreResult\fR, |
---|
| 73 | and \fBTcl_DiscardResult\fR continue to exist only for the sake |
---|
| 74 | of existing programs that may already be using them. |
---|
| 75 | .PP |
---|
| 76 | \fBTcl_SaveInterpState\fR takes a snapshot of those portions of |
---|
| 77 | interpreter state that make up the full result of script evaluation. |
---|
| 78 | This include the interpreter result, the return code (passed in |
---|
| 79 | as the \fIstatus\fR argument, and any return options, including |
---|
| 80 | \fB\-errorinfo\fR and \fB\-errorcode\fR when an error is in progress. |
---|
| 81 | This snapshot is returned as an opaque token of type \fBTcl_InterpState\fR. |
---|
| 82 | The call to \fBTcl_SaveInterpState\fR does not itself change the |
---|
| 83 | state of the interpreter. Unlike \fBTcl_SaveResult\fR, it does |
---|
| 84 | not reset the interpreter. |
---|
| 85 | .PP |
---|
| 86 | \fBTcl_RestoreInterpState\fR accepts a \fBTcl_InterpState\fR token |
---|
| 87 | previously returned by \fBTcl_SaveInterpState\fR and restores the |
---|
| 88 | state of the interp to the state held in that snapshot. The return |
---|
| 89 | value of \fBTcl_RestoreInterpState\fR is the status value originally |
---|
| 90 | passed to \fBTcl_SaveInterpState\fR when the snapshot token was |
---|
| 91 | created. |
---|
| 92 | .PP |
---|
| 93 | \fBTcl_DiscardInterpState\fR is called to release a \fBTcl_InterpState\fR |
---|
| 94 | token previously returned by \fBTcl_SaveInterpState\fR when that |
---|
| 95 | snapshot is not to be restored to an interp. |
---|
| 96 | .PP |
---|
| 97 | The \fBTcl_InterpState\fR token returned by \fBTcl_SaveInterpState\fR |
---|
| 98 | must eventually be passed to either \fBTcl_RestoreInterpState\fR |
---|
| 99 | or \fBTcl_DiscardInterpState\fR to avoid a memory leak. Once |
---|
| 100 | the \fBTcl_InterpState\fR token is passed to one of them, the |
---|
| 101 | token 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 |
---|
| 105 | of \fIinterp\fR into the location specified by \fIstatePtr\fR. |
---|
| 106 | \fBTcl_SaveResult\fR clears the result for \fIinterp\fR and |
---|
| 107 | leaves 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 |
---|
| 111 | already in the interpreter will be cleared. The \fIstatePtr\fR is left |
---|
| 112 | in 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 |
---|
| 116 | stored at \fBstatePtr\fR. The state structure is left in an |
---|
| 117 | uninitialized state and cannot be used until another call to |
---|
| 118 | \fBTcl_SaveResult\fR. |
---|
| 119 | .PP |
---|
| 120 | Once \fBTcl_SaveResult\fR is called to save the interpreter |
---|
| 121 | result, either \fBTcl_RestoreResult\fR or |
---|
| 122 | \fBTcl_DiscardResult\fR must be called to properly clean up the |
---|
| 123 | memory associated with the saved state. |
---|
| 124 | |
---|
| 125 | .SH KEYWORDS |
---|
| 126 | result, state, interp |
---|