<i>Tcl_SaveInterpState/Tcl_RestoreInterpState are not usable to save interpreter state (error info/code)</i> status still Open with 4 other changes
by
.
D 2020-02-10T16:44:27.012
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\s[/timeline?r=bug-554117edde|bug-554117edde]\swith\stest\scases\s[95db6756e8bd9f96]\sillustrating\sthat.
J icomment As\sone\scan\ssee\sboth\s1.9.*\stest\scases\sfails:\r\n<code><pre\sstyle="padding-left:10pt">\r\n====\sresult-1.9.1\sTcl_SaveInterpState:\s"safe"\seval\swithout\smodifying\sstates\sFAILED\r\n...\r\n----\sResult\swas:\r\n<b\sstyle="color:red">{UNEXPERR\sINVISIBLE}\s{ERROR\sin\ssafe\sblock}</b>\r\n----\sResult\sshould\shave\sbeen\s(exact\smatching):\r\n{EXPERR\sTEST-ERROR}\s{ERROR\sexpected\serror}\r\n====\sresult-1.9.1\sFAILED\r\n\r\n\r\n====\sresult-1.9.2\sTcl_SaveInterpState:\snested\ssave\sstate\sdoes\snot\smodify\serror\sinfo/code\sFAILED\r\n...\r\n----\sResult\swas:\r\n<b\sstyle="color:red">0\s{UNEXPERR\sINVISIBLE}\s{ERROR\sin\ssafe\sblock}</b>\r\n----\sResult\sshould\shave\sbeen\s(exact\smatching):\r\n0\s{EXPERR\sTEST-ERROR}\s{ERROR\sexpected\serror}\r\n====\sresult-1.9.2\sFAILED\r\n</pre></code>
J login sebres
J mimetype text/x-fossil-wiki
K 554117eddec7220f1cda04c16cc45a77d6c175e0
U sebres
Z f92aaec2e6d2d708e7b3689cebf42f93