Article View: comp.lang.tcl
Article #136Re: #define Tcl_BounceObj Tcl_DecrObj for 8.6?
From: Harald Oehlmann
Date: Fri, 20 Nov 2026 13:10
Date: Fri, 20 Nov 2026 13:10
68 lines
3274 bytes
3274 bytes
Am 20.11.2026 um 12:46 schrieb Ralf Fassel:
> * Harald Oehlmann <wortkarg3@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
Technical Details
Message-ID:
<11dpgso$36fbe$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11dp90e$33fif$1@dont-email.me> <ygase0v4ter.fsf@akutech.de>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Harald Oehlmann <wortkarg3@yahoo.com> Newsgroups: comp.lang.tcl Subject: Re: #define Tcl_BounceObj Tcl_DecrObj for 8.6? Date: Fri, 20 Nov 2026 14:10:14 +0100 Organization: A noiseless patient Spider Lines: 68 Message-ID: <11dpgso$36fbe$1@dont-email.me> References: <11dp90e$33fif$1@dont-email.me> <ygase0v4ter.fsf@akutech.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 20 Nov 2026 13:10:49 +0000 (UTC) Injection-Info: dont-email.me; logging-data="3358062"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18WslkGNp0B5vqHue95vAQp"; posting-host="f21fafc14b5fef21a0af0e9ea3f5f996" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:pHDh/Jb+vy2wzCTHCoJwV4zfvT0= sha256:SrdoSbtUi3JBNah09/pUe7hdqopaSsqrcwOH4i0wsUo= sha1:UAMx8hNh3sTWgyUncM/IAGpq+Ks= sha256:Ao9Txok/8wmzPC3M1osAQYlWajEbO4yU/EuxLr+dNE8= Content-Language: en-GB In-Reply-To: <ygase0v4ter.fsf@akutech.de>