Still one argument against this code at all - if caller want to release ownership of the object (should not hold own reference anymore after set variable, the caller should currently take care by the decreasing of it.<br/>
Especially in the error case of <code>Tcl_ObjSetVar2</code> (because this time it should then always do it). How it can be sure, that <code>Tcl_ObjSetVar2</code> did it not already?
So for example:
<code><pre>
/* we get someValue from somewhere and take ownership of reference now */
someValue = TransmitObjFromSomewhere(...);
...
if (!Tcl_ObjSetVar2(interp, varName, NULL, someValue, ...)) {
  /* [**BAD**] error case - decrease and return */
  Tcl_DecrRefCount(someValue);
  /* [**/BAD**] */
  return ...;
}
/* do somewhat else also, e. g. using this object, for example: */
... Tcl_GetString(someValue) ...

/* we are ready here, release our ownership (further in var) */
Tcl_DecrRefCount(someValue);
return ...;


But currently we cannot do this sane...<br/>
I mean the code enclosed between
Because we can be not sure what happens with reference in <code>Tcl_ObjSetVar2</code>.

Possibly we should introduce a new flag (TCL_OWN_OBJREF) like here:
<code><pre>
<b tcl.h:</b>

<b style="color:green">+ /* Indicate the object reference supplied to Tcl_ObjSetVar2 etc should be not owned by caller anymore
<b style="color:green">+ #define TCL_OWN_OBJREF           0x800000</b>

<b everywhere where expected to transmit the reference ownership to var:</b>

<b style="color:red">- Tcl_ObjSetVar2(interp, varName, NULL, someValue, TCL_LEAVE_ERR_MSG);</b>
<b style="color:red">- Tcl_DecrRefCount(someValue);</b>
<b style="color:green">+ Tcl_ObjSetVar2(interp, varName, NULL, someValue, TCL_OWN_OBJREF | TCL_LEAVE_ERR_MSG);</b>


It could then set the variable value with decreasing of the refCount by variable assignment routines (but always, not only in error case if refCount was 0).

IMHO only this would be the right way, to make it sane.