Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 6461f5c50cad06b6d56a963024ce17cb3fd81943b70bda12bb3cca6d85ab8f39
Ticket: e9a2715d912d86448a2ed18b2d25788cd50769b4
Tcl 8.6.11: Incompatible Tcl_GetRange()
User & Date: petasis on 2022-01-18 14:54:51
Changes

  1. icomment:
    Dear Jan,
    
    At the Tcl level we have "end". The unofficial "end" being -1, is for users of the C API. Tcl_NewStringObj, Tcl_SetStringObj, Tcl_AppendToObj, all accept -1 (in fact any negative number) as "till the end of the string".
    
    Tcl_GetRange() documentation does not promise that (that the last parameter can be a negative number), but passing a negative number as the last used to "work as expected".
    
    What I can assure you, is that as a developer of several C extensions, I have used "-1" as an unofficial "end" position, because I have seen the code of Tcl_GetRange() and came to a conclusion that it is safe to do so, as it was using Tcl_NewStringObj() and friends internally.
    
    I do not suggest that this was correct, or that the documentation suggests so. I am raising the issue that like me there may be other C extensions that are using this "convenience", and that this change deserves at least a mention of incompatibility in the release notes of 8.6 & 8.7. What is written now (that error checking has been added) is not enough.
    
    To my view, and according to the documentation, passing a negative value to last in Tcl_GetString() is an erroneous situation. It should never happen.
    
    And input checking was added to the function. Which leads to a decision on what to do if "last" is negative. Given that a NULL cannot be returned (the documentation promises that a new object is always returned), the decision is to return an empty string.
    
    I would have taken a different decision, to be set to the last character of the string, because a) the length of the string is already known inside the function and b) is less code for the caller to find the last character of the string.
    But thats me :-) At least update the release notes to point out the potential incompatibility.
    
  2. login: "petasis"
  3. mimetype: "text/x-fossil-wiki"