<i>Tcl_SaveInterpState/Tcl_RestoreInterpState are not usable to save interpreter state (error info/code)</i>.
by
.
D 2020-02-10T16:35:07.877
J assignee nobody
J closer nobody
J cmimetype text/x-fossil-wiki
J comment Current\simplementation\sof\s<code>Tcl_SaveInterpState/Tcl_RestoreInterpState</code>\sdoes\snot\sconsider\s(legacy)\scopy\sof\sinterpreter\sstate\s(errorInfo/errorCode\svariables),\swhich\scan\sproduce\sunexpected\sbehavior\soverwriting\sboth\svalues\slike\sin\sfollowing\sexample:\r\n<code><pre\sstyle="padding-left:10pt">\r\nif\s{[catch\s{\r\n\s\s\s...\ssame\scode\sX\sproducing\serror\s...\r\n}\smsg]}\s{\r\n\s\s\slog\sINFO\s"unexpected\serror\sin\sblock\sX:\s$msg"\r\n\s\s\slog\sDEBUG\s$::errorCode\s$::errorInfo\r\n}\r\n</pre></code>\r\nif\sroutine\slog\s(can\sevaluate\ssomething\sin\sinterp\sand\seven\sgenerate\stemporary\serrors)\sdoes\s"safe"\shandling\sto\ssave\sinterp\sstate\s(uses\sTcl_SaveInterpState/Tcl_RestoreInterpState),\sit\scan\soverwrite\s<code>::errorInfo</code>\sand\s<code>::errorCode</code>\sor\srather\sdoes\snot\srestore\sboth\sproperly,\sif\ssome\s<code>Tcl_ResetResult</code>\s(called\sinternally)\sresets\sinterim\s<code>iPtr->errorInfo</code>\sand\s<code>iPtr->errorCode</code>\sto\sNULL.\r\n\r\nThis\scauses\sthat\ssystem\straces\sobserving\s<code>::errorInfo</code>\sand\s<code>::errorCode</code>\sdo\snothing\s(because\siPtr\sstates\sare\sNULL)\sand\sboth\svariables\sremain\soverwritten\svalues.\r\n\r\nAlthough\sI\sknow\sthat\s<code>::errorInfo</code>\sand\s<code>::errorCode</code>\sare\slegacy\seither\sand\sone\sshould\srather\suse\soption\sdictionary\s(second\sparameter\safter\smsg\svariable\sin\scatch),\sbut\s<code>Tcl_SaveInterpState/Tcl_RestoreInterpState</code>\sare\spretty\sunusable\stogether\swith\sany\skind\sof\sevaluation\s(especially\sbecause\s<code>Tcl_ResetResult</code>\sis\sinvolved\sin-between\sinternally,\sand\sit\sis\salmost\salways\sthe\scase).\r\n\r\nThe\serror\sis\sinitially\snoticed\sin\s[https://github.com/sebres/tclclockmod/issues/19#issuecomment-582639778|GH/sebres/tclclockmod/issues/19#issuecomment-582639778].\r\n\r\nBut\snow\sI\shave\sa\sbranch\swith\stest\scases\sillustrating\sthat.
J is_private 0
J login sebres
J priority 5\sMedium
J resolution None
J severity Minor
J status Open
J submitter sebres
J subsystem 45.\sParsing\sand\sEval
J title Tcl_SaveInterpState/Tcl_RestoreInterpState\sare\snot\susable\sto\ssave\sinterpreter\sstate\s(error\sinfo/code)
J type Bug
K 554117eddec7220f1cda04c16cc45a77d6c175e0
U sebres
Z 12d5b1cf8003ccfaa1479c997fb27c40