Avoiding putmsg Side Effects

It is important to note that the putmsg function can be called unexpectedly, so it should take care to avoid side effects. A typical case is the unexpected modification of $ret by putmsg after a statement generates errors. Variables like $ret and $loop should be preserved in putmsg with local variables if they are modified:

<A NAME=putmsg PRIVATE>
<LOCAL saveret=$ret saveloop=$loop savenext=$next>
  <LOOP $errmsg>
    <fmt "Note: %s\n" $errmsg>
  </LOOP>
  <$ret = $saveret>
  <$loop = $saveloop>
  <$next = $savenext>
</A>

Here the initial values of $ret, $loop and $next are preserved in local variables, and restored on exit, because they are modified by fmt and LOOP. In this way, these variables won't be truncated after a function, if error messages cause a putmsg call.


Copyright © Thunderstone Software     Last updated: Oct 24 2023
Copyright © 2024 Thunderstone Software LLC. All rights reserved.