Tcl_SaveInterpState(3)
π Tcl_SaveInterpState β the save/restore-your-interp-state manual, bestie edition π
okay so this is a page from the Tcl Library Procedures collection, and it's all about Tcl_SaveInterpState(3) β plus its two ride-or-die besties Tcl_RestoreInterpState and Tcl_DiscardInterpState. if you write C extensions for Tcl, this trio is about to become your whole personality. π«Ά
β¨ NAME β¨
Tcl_SaveInterpState, Tcl_RestoreInterpState, Tcl_DiscardInterpState β save and restore an interpreter's state, no cap π
β¨ SYNOPSIS β¨
the whole squad, together at last:
#include <tcl.h>
Tcl_InterpState
Tcl_SaveInterpState(interp, status)
int
Tcl_RestoreInterpState(interp, state)
Tcl_DiscardInterpState(state)
β¨ ARGUMENTS β¨
Tcl_Interp *interp(in) β the interpreter whose state you're trying to save. it's giving "main character interp". β¨int status(in) β the return code value you want stored as part of the interpreter state.Tcl_InterpState state(in) β the saved state token, the one you're gonna restore or discard. it's the little ticket you keep in your pocket. π
β¨ DESCRIPTION β¨
so these routines let a C procedure take a snapshot πΈ of the current state of an interpreter β so you can bring that exact vibe back after calling Tcl_Eval or literally any other routine that messes with the interpreter state. it's a save point. it's the checkpoint before the boss fight. iconic behavior, honestly.
Tcl_SaveInterpState stores a snapshot of the interpreter state in an opaque token returned by Tcl_SaveInterpState. that token value can then be handed back to either Tcl_RestoreInterpState or Tcl_DiscardInterpState, depending on whether the interp state is actually getting restored or not. and here's the slay part: as long as you call one of those latter two routines, Tcl handles the memory management for you. no manual cleanup. we love a service. π
Tcl_SaveInterpState takes a snapshot of those portions of interpreter state that make up the full result of script evaluation. that includes:
- the interpreter result
- the return code (passed in as the
statusargument) - any return options, including
-errorinfoand-errorcodewhen an error is in progress π
that snapshot comes back to you as an opaque token of type Tcl_InterpState. and important: the call to Tcl_SaveInterpState does not itself change the state of the interpreter. it just looks. it does not touch. respectful king. π
Tcl_RestoreInterpState accepts a Tcl_InterpState token that was previously returned by Tcl_SaveInterpState and restores the state of the interp to whatever was held in that snapshot. and the return value of Tcl_RestoreInterpState is the status value originally passed to Tcl_SaveInterpState back when the snapshot token was created. so it gives you the receipt back. π§Ύ
Tcl_DiscardInterpState is the one you call to release a Tcl_InterpState token previously returned by Tcl_SaveInterpState when that snapshot is not going to be restored to an interp. it's the "nah, we're not doing that anymore" button. π
β οΈ okay bestie, this next part is the real one, do not scroll past it: theTcl_InterpStatetoken returned byTcl_SaveInterpStatemust eventually be passed to eitherTcl_RestoreInterpStateorTcl_DiscardInterpStateto avoid a memory leak. π and once thatTcl_InterpStatetoken has been passed to one of them, the token is no longer valid and should not be used anymore. periodt. don't text it back. it's over. β
β¨ KEYWORDS β¨
result, state, interp πΈ
and that's the whole page, bestie!! this one's from the Tcl manual, version 8.1, filed under Tcl_SaveInterpState(3) β go forth and snapshot responsibly. π¦β¨π
π¦ where this page comes from
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· TCL
- fedora 43: tcl-doc 1:9.0.2-1.fc43 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- fedora 44: tcl-doc 1:9.0.2-1.fc44 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- nixos 26.05: tcl 9.0.3
- nixpkgs unstable: tcl 9.1.0
- Copyright (c) 1997 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms