Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Tcl_ListObjIndex returns empty string instead of NULL for lseq

Closed / Fixed30e4e9102f3f1080713ce7766719d1fc02ea8ab0Created 3 years agoUpdated 3 years ago
Descriptionmarkdown2023-07-29 06:24:31

The Tcl_ListObjIndex command is documented to return TCL_OK and set the output objPtr to NULL in case the index is out of bounds. This is tested by the listObj-14.X tests and fails when the list is a lseq where an empty Tcl_Obj is returned in objPtr instead.

My preference for a fix would be to define semantics of the Tcl_ObjType.indexProc to behave like Tcl_ListObjIndex and return NULL for this case (and TCL_OK).

On a related note, the Tcl_ObjType methods including indexProc are documented in the manpages as paralleling the script level commands like lindex. This should really be documented as paralleling the C API for lists and should be implemented accordingly. (The TIP itself is silent on exact semantics). There are issues like sharing of objects etc. that do not arise at the script level but must be obeyed by the methods in the same manner as the public C API. There are also functional differences between the script and C levels, the above index bounds being just one. For folks writing abstract list variations, the distinction is important.

/Ashok

Referenced by3
  • ec0babae5cMerge [22fc4699a34f11e1], "Corrections and additions for ObjectType Abstract List descriptions. Part of bug [30e4e9102f]". For the "unchained" branch this documentation isn't correct anway, and will be fixed later. check-in2024-08-20 11:40:06
  • 22fc4699a3Corrections and additions for ObjectType Abstract List descriptions. Part of bug [30e4e9102f] check-in2023-08-08 22:55:50
  • 93be83f416Fix bug [30e4e9102f] - Abstract List ListIndex should return NULL when index out of range. check-in2023-08-08 17:10:20
apnadkarniplain2023-08-08 08:14:48
Brian, assigning to you for comments.
griffinplain2023-08-08 15:50:15
What I vaguely recall is that I saw this pattern elsewhere and copied it. But clearly this is wrong. 
I will fix it.
griffinplain2023-08-08 17:31:35
Log in (anonymous is fine) to add a comment.