Zoran Vasiljevic schrieb:
Hi!
After I have observed some very subtle and hard-to-reproduce
bugs in our app, I found out that Tcl object handling in
some places in NS code, although "by the book" is really a
source of trouble. Like:
Tcl_SetIntObj(Tcl_GetObjResult(interp), 1); /* Unsafe? */
This construct assumes that object stored in the interp
result is not shared.
But, when I modify it to look like:
Tcl_SetObjResult(interp, Tcl_NewIntObj(1)); /* Safe! */
Another option is to use
Tcl_ResetResult()
* Side effects:
* It resets the result object to an unshared empty object. It
* then restores the interpreter's string result area to its default
* initialized state, freeing up any memory that may have been
* allocated. It also clears any error information for the interpreter.
When i developed the byte-code support for xotcl, i found some
subtle differences on that, depending on byte-code-compiled code or
not (this was with some earlier tcl 8.4 versions).
Not sure, what's faster, resetResult() + setIntObj() or
setObjResult() + newIntObj(). The difference in speed is most likely
not significant. however, resetResult allows to append to the object,
clears error state, etc.
-gustaf