Skip to content
Tcl Source Code Changes To Migrating C extensions to Tcl 9
Login

Changes To Migrating C extensions to Tcl 9

Changes to "Migrating C extensions to Tcl 9" between 2023-10-30 21:11:17 and 2023-10-30 21:34:51

︙
24
25
26
27
28
29
30
31

32
24
25
26
27
28
29
30

31
32







-
+


See the Tcl_RegisterObjType manual page for more details, as well as TIPs #644 and #636.

## Tcl Lists

### Tcl_Obj reference counting

It is often common practice when indexing a Tcl List, to not include Incr and Decr RefCounts on the element Tcl_Obj when the use is local and temporary. This was because the List already has a reference to the element, and the Incr/Decr sequence would have no material effect. A minor performance gain.  With the introduction of Abstract Lists, it is possible for elements to be created on demand by the Index operation, so the new element Obj will have a refCount of 0. Therefore, existing code that skip RefCounting operations could be at risk of leaking memory.  Such code should include appropriate Incr/Decr calls, or make use of the new Tcl_BounceRefCount() function. This new function will check for a zero refCount and free the Tcl_Obj. 
It is often common practice when indexing a Tcl List, to not include Incr and Decr RefCounts on the element Tcl_Obj when the use is local and temporary. This was because the List already has a reference to the element, and the Incr/Decr sequence would have no material effect. A minor performance gain.  With the introduction of Abstract Lists, it is possible for elements to be created on demand by the Index operation, so the new element Obj may have a refCount of 0. Therefore, existing code that skip RefCounting operations could be at risk of leaking memory.  Such code should include appropriate Incr/Decr calls, or make use of the new Tcl_BounceRefCount() function. This new function will check for a zero refCount and free the Tcl_Obj.