Am 20.11.2026 um 12:46 schrieb Ralf Fassel:
> * Harald Oehlmann <wort…@yahoo.com>
> | I am not sure when to use Tcl_BounceObj in Tcl 9.
> | I only know, that there are many error issues with the abstract list.
> | Is it adviceable to:
> | - replace Tcl_DecrObj by Tcl_BounceObj in TCL 9?
> | - still use Tcl_DecrObj in TCL 8.6?
>
> ITYM Tcl_BounceRefCount?
>
> Looking at the source code (Tcl9.0.4), Tcl_BounceRefCount only frees the
> Tcl_Obj if the refcount is already 0.
>
> I *think* the intention is to replace
> obj = Tcl_NewObj();
> Tcl_IncrRefCount(obj);
> // do anything with obj that does *not* incr/decr the refcount
> Tcl_DecrRefCount(obj);
> by
> obj = Tcl_NewObj();
> // do anything with obj that does *not* incr/decr the refcount
> Tcl_BounceRefCount(obj);
>
> i.e. to avoid the Incr/Decr combo.
>
> Note however that if "do anything with obj" modifies the refcount, it is
> necessary to IncrRefCount before calling it, in which case you need to
> use Tcl_DecrRefCount, not Tcl_BounceRefCount.
>
> This means that simply replacing *any* Tcl_DecrRefCount by
> Tcl_BounceRefCount is wrong, only replacing a *matching*
> Tcl_IncrRefCount/Tcl_DecrRefCount by Tcl_BounceRefCount would be
> (sometimes :-) ok.
>
> My €0.01
> R'
Thanks, great!
My pattern in 8.6 is:
pKeyObj = Tcl_NewStringObj("key", -1);
Result = Tcl_DictObjGet(interp, pDeviceDict, pKeyObj, &pObj);
Tcl_DecrRefCount(pKeyObj);
if (Result != TCL_OK)
return RET_ERROR;
I use Tcl_DecrRefCount to delete the object.
So, the right pattern would be:
8.6:
pKeyObj = Tcl_NewStringObj("key", -1);
Tcl_IncrRefCount(pKeyObj);
Result = Tcl_DictObjGet(interp, pDeviceDict, pKeyObj, &pObj);
Tcl_DecrRefCount(pKeyObj);
if (Result != TCL_OK)
return RET_ERROR;
Tcl 9.0:
pKeyObj = Tcl_NewStringObj("key", -1);
Result = Tcl_DictObjGet(interp, pDeviceDict, pKeyObj, &pObj);
Tcl_BounceRefCount(pKeyObj);
if (Result != TCL_OK)
return RET_ERROR;
Thanks for all,
Harald