{"id":7214,"date":"2022-12-20T19:35:51","date_gmt":"2022-12-20T22:35:51","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/tcl_saveresult-man3\/"},"modified":"2022-12-20T19:35:51","modified_gmt":"2022-12-20T22:35:51","slug":"tcl_saveresult-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/tcl_saveresult-man3\/","title":{"rendered":"Tcl_SaveResult (man3)"},"content":{"rendered":"<h1 align=\"center\">Tcl_SaveResult<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#ARGUMENTS\">ARGUMENTS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#KEYWORDS\">KEYWORDS<\/a> <\/p>\n<hr>\n<p>______________________________________________________________________________<\/p>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Tcl_SaveInterpState, Tcl_RestoreInterpState, Tcl_DiscardInterpState, Tcl_SaveResult, Tcl_RestoreResult, Tcl_DiscardResult \u2212 save and restore an interpreter\u2019s state<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>#include <tcl.h><\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Tcl_InterpState <b><br \/> Tcl_SaveInterpState<\/b>(<i>interp, status<\/i>)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">int <b><br \/> Tcl_RestoreInterpState<\/b>(<i>interp, state<\/i>)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Tcl_DiscardInterpState<\/b>(<i>state<\/i>)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Tcl_SaveResult<\/b>(<i>interp, savedPtr<\/i>)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Tcl_RestoreResult<\/b>(<i>interp, savedPtr<\/i>)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Tcl_DiscardResult<\/b>(<i>savedPtr<\/i>)<\/p>\n<h2>ARGUMENTS <a name=\"ARGUMENTS\"><\/a> <\/h2>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"46%\">\n<p style=\"margin-top: 1em\">Tcl_Interp <i>*interp<\/i> (in)<\/p>\n<\/td>\n<td width=\"14%\"><\/td>\n<td width=\"29%\">\n<p style=\"margin-top: 1em\">Interpreter for which state should be saved.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"46%\">\n<p>int <i>status<\/i> (in)<\/p>\n<\/td>\n<td width=\"14%\"><\/td>\n<td width=\"29%\">\n<p>Return code value to save as part of interpreter state.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"46%\">\n<p>Tcl_InterpState <i>state<\/i> (in)<\/p>\n<\/td>\n<td width=\"14%\"><\/td>\n<td width=\"29%\">\n<p>Saved state token to be restored or discarded.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"46%\">\n<p>Tcl_SavedResult <i>*savedPtr<\/i> (in)<\/p>\n<\/td>\n<td width=\"14%\"><\/td>\n<td width=\"29%\">\n<p>Pointer to location where interpreter result should be saved or restored.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:71%;\">______________________________________________________________________________<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">These routines allows a C procedure to take a snapshot of the current state of an interpreter so that it can be restored after a call to <b>Tcl_Eval<\/b> or some other routine that modifies the interpreter state. There are two triplets of routines meant to work together.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The first triplet stores the snapshot of interpreter state in an opaque token returned by <b>Tcl_SaveInterpState<\/b>. That token value may then be passed back to one of <b>Tcl_RestoreInterpState<\/b> or <b>Tcl_DiscardInterpState<\/b>, depending on whether the interp state is to be restored. So long as one of the latter two routines is called, Tcl will take care of memory management.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The second triplet stores the snapshot of only the interpreter result (not its complete state) in memory allocated by the caller. These routines are passed a pointer to <b>Tcl_SavedResult<\/b> that is used to store enough information to restore the interpreter result. <b>Tcl_SavedResult<\/b> can be allocated on the stack of the calling procedure. These routines do not save the state of any error information in the interpreter (e.g. the <b>\u2212errorcode<\/b> or <b>\u2212errorinfo<\/b> return options, when an error is in progress).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Because the routines <b>Tcl_SaveInterpState<\/b>, <b>Tcl_RestoreInterpState<\/b>, and <b>Tcl_DiscardInterpState<\/b> perform a superset of the functions provided by the other routines, any new code should only make use of the more powerful routines. The older, weaker routines <b>Tcl_SaveResult<\/b>, <b>Tcl_RestoreResult<\/b>, and <b>Tcl_DiscardResult<\/b> continue to exist only for the sake of existing programs that may already be using them.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Tcl_SaveInterpState<\/b> takes a snapshot of those portions of interpreter state that make up the full result of script evaluation. This include the interpreter result, the return code (passed in as the <i>status<\/i> argument, and any return options, including <b>\u2212errorinfo<\/b> and <b>\u2212errorcode<\/b> when an error is in progress. This snapshot is returned as an opaque token of type <b>Tcl_InterpState<\/b>. The call to <b>Tcl_SaveInterpState<\/b> does not itself change the state of the interpreter. Unlike <b>Tcl_SaveResult<\/b>, it does not reset the interpreter.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Tcl_RestoreInterpState<\/b> accepts a <b>Tcl_InterpState<\/b> token previously returned by <b>Tcl_SaveInterpState<\/b> and restores the state of the interp to the state held in that snapshot. The return value of <b>Tcl_RestoreInterpState<\/b> is the status value originally passed to <b>Tcl_SaveInterpState<\/b> when the snapshot token was created.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Tcl_DiscardInterpState<\/b> is called to release a <b>Tcl_InterpState<\/b> token previously returned by <b>Tcl_SaveInterpState<\/b> when that snapshot is not to be restored to an interp.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>Tcl_InterpState<\/b> token returned by <b>Tcl_SaveInterpState<\/b> must eventually be passed to either <b>Tcl_RestoreInterpState<\/b> or <b>Tcl_DiscardInterpState<\/b> to avoid a memory leak. Once the <b>Tcl_InterpState<\/b> token is passed to one of them, the token is no longer valid and should not be used anymore.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Tcl_SaveResult<\/b> moves the string and value results of <i>interp<\/i> into the location specified by <i>statePtr<\/i>. <b>Tcl_SaveResult<\/b> clears the result for <i>interp<\/i> and leaves the result in its normal empty initialized state.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Tcl_RestoreResult<\/b> moves the string and value results from <i>statePtr<\/i> back into <i>interp<\/i>. Any result or error that was already in the interpreter will be cleared. The <i>statePtr<\/i> is left in an uninitialized state and cannot be used until another call to <b>Tcl_SaveResult<\/b>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Tcl_DiscardResult<\/b> releases the saved interpreter state stored at <b>statePtr<\/b>. The state structure is left in an uninitialized state and cannot be used until another call to <b>Tcl_SaveResult<\/b>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Once <b>Tcl_SaveResult<\/b> is called to save the interpreter result, either <b>Tcl_RestoreResult<\/b> or <b>Tcl_DiscardResult<\/b> must be called to properly clean up the memory associated with the saved state.<\/p>\n<h2>KEYWORDS <a name=\"KEYWORDS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">result, state, interp<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  Tcl_SaveInterpState, Tcl_RestoreInterpState, Tcl_DiscardInterpState, Tcl_SaveResult, Tcl_RestoreResult, Tcl_DiscardResult \u2212 save and restore an interpreter\u2019s state <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2536],"tags":[2538,3007,3544],"class_list":["post-7214","post","type-post","status-publish","format-standard","hentry","category-3-llamadas-de-bibliotecas","tag-2538","tag-man3","tag-tcl_discardresult"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7214","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=7214"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7214\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=7214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=7214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=7214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}