Skip to content
Tcl Source Code History Of Ticket fa00fbbbabe2d779
Login

History Of Ticket fa00fbbbabe2d779

Artifacts Associated With Ticket fa00fbbbabe2d779

  1. Ticket change [d315be1fe1] (rid 212643) by apnadkarni on 2023-04-12 14:31:09:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-markdown"
    4. comment initialized to:
      I expect lindex with indices larger than list size to return empty string. This is the case with small lseq ranges but not large ones (64-bit build)
      
      ```
      % lindex [lseq 0x10] 0x11 -> correctly returns empty string
      % lindex [lseq 0x7fffffff] 0x80000000  -> generates error instead
      index 2147483648 is out of bounds 0 to 2147483646
      %
      ```
      
      Another possibly related (on 32-bit build)
      
      ```
      % lindex [lseq 0xffffffff] 0x80000000 -> should return 2147483648
      %
      ```
      
      This last may be related to signed/unsigned indexing and may go away with TIP 660.
      
      Finally, some check (and exception) is needed when list limit is exceeded. The following on *32-bit* Tcl should generate an error since the full range of elements cannot be accessed by indexing.
      
      ```
      % llength [lseq 0x100000000]
      0
      ```
      
      I have not tried this on the tip-636 branch.
      
      /Ashok
      
    5. foundin initialized to: "9.0"
    6. is_private initialized to: "0"
    7. login: "apnadkarni"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "9546e9877f1a8899e25a89082561ee694e7fb402"
    10. resolution initialized to: "None"
    11. severity initialized to: "Important"
    12. status initialized to: "Open"
    13. submitter initialized to: "apnadkarni"
    14. subsystem initialized to: "- New Builtin Commands"
    15. title initialized to: "lseq / lindex discrepancies"
    16. type initialized to: "Bug"
  2. Ticket change [c37e20118a] (rid 212647) by apnadkarni on 2023-04-12 15:33:52:

    1. comment changed to:
      I expect lindex with indices larger than list size to return empty string. This is the case with small lseq ranges but not large ones (64-bit build)
      
      ```
      % lindex [lseq 0x10] 0x11 -> correctly returns empty string
      % lindex [lseq 0x7fffffff] 0x80000000  -> generates error instead
      index 2147483648 is out of bounds 0 to 2147483646
      %
      ```
      
      Another possibly related (on 32-bit build). This may be related to signed/unsigned indexing and may go away with TIP 660.
      
      ```
      % lindex [lseq 0xffffffff] 0x80000000 -> should return 2147483648
      %
      ```
      
      Finally, some check (and exception) is needed when list limit is exceeded. The following on *32-bit* Tcl should generate an error since the full range of elements cannot be accessed by indexing.
      
      ```
      % llength [lseq 0x100000000]
      0
      ```
      
      I have not tried this on the tip-636 branch.
      
      /Ashok
      
    2. login: "apnadkarni"
    3. mimetype: "text/plain"
  3. Ticket change [301d94bd2c] (rid 212750) by apnadkarni on 2023-04-14 02:54:19:

    1. icomment:
      The equivalent on 64 bit builds also fails.
      
      ```
      % set l [lseq 0x7fffffffffffffff]; llength $l
      9223372036854775807
      % lindex $l 9223372036854775800 -> returns empty string
      % 
      ```
      
      Again, I'm not sure if this is a Tcl index implementation issue or lseq since it is not possible to test equivalent in "traditional" lists that cannot reach that size.
      
    2. login: "apnadkarni"
    3. mimetype: "text/plain"
  4. Ticket change [b5b7d0c2b6] (rid 212751) by apnadkarni on 2023-04-14 02:54:56:

    1. login: "apnadkarni"
    2. mimetype: "text/plain"
  5. Ticket change [a08d9bf350] (rid 212752) by apnadkarni on 2023-04-14 03:01:47:

    1. icomment:
      There is also a difference between the compiled and uncompiled results, neither of which is the correct result:
      
      ```
      % set l [lseq 0x7fffffffffffffff]; llength $l
      9223372036854775807
      % lindex $l 9223372036854775800
      % set lindex lindex
      lindex
      % $lindex $l 9223372036854775800
      -9223372036854775808% set l [lseq 0x7fffffffffffffff]; llength $l
      9223372036854775807
      % lindex $l 9223372036854775800
      % set lindex lindex
      lindex
      % $lindex $l 9223372036854775800
      -9223372036854775808
      ```
      
    2. login: "apnadkarni"
    3. mimetype: "text/plain"
  6. Ticket change [901c1085fd] (rid 213108) by griffin on 2023-04-16 23:02:10:

    1. icomment:
      The last issue is a general problem with byte compiler and index values. This comment from tclUtil.c explains:
      
       * TclIndexEncode --
       *
       *      Parse objPtr to determine if it is an index value. Two cases
       *	are possible.  The value objPtr might be parsed as an absolute
       *	index value in the C signed int range.  Note that this includes
       *	index values that are integers as presented and it includes index
       *      arithmetic expressions. The absolute index values that can be
       *	directly meaningful as an index into either a list or a string are
       *	those integer values >= TCL_INDEX_START (0)
       *	and < INT_MAX.
       *      The largest string supported in Tcl 8 has bytelength INT_MAX.
       *      This means the largest supported character length is also INT_MAX,
       *      and the index of the last character in a string of length INT_MAX
       *      is INT_MAX-1.
      
      It looks like this was missed when moving from 32-bit indices to 64-bit indices.
      
    2. login: "griffin"
    3. mimetype: "text/plain"
  7. Ticket change [04fcc06f03] (rid 213118) by apnadkarni on 2023-04-17 01:59:33:

    1. icomment:
      I don't think that TclIndexEncode was missed in moving to 64-bits but rather it was intentional. Iirc, the byte code format is limited to 32-bits and the TclIndexEncode/TclIndexDecode are only used for immediate literal operands (N or end-N) in that range. Operands in variables or outside that range use the TclGetIntForIndexM (or its function equivalent) and load the value from Tcl_Objs on the stack. That is my understanding.
      
      Having said that, there is a ticket logged for some index values so there are definitely some issues that need to be resolved in that area.
      
    2. login: "apnadkarni"
    3. mimetype: "text/plain"
  8. Ticket change [b45c490cfb] (rid 213119) by griffin on 2023-04-17 03:10:31:

    1. icomment:
      Ok then.  I will fix the compilation to detect overflow for literals and take appropriate measures.
      Thanks!
      
    2. login: "griffin"
    3. mimetype: "text/plain"
  9. Ticket change [b57b6950c2] (rid 213514) by griffin on 2023-04-21 15:44:23:

    1. assignee changed to: "griffin"
    2. login: "griffin"
    3. mimetype: "text/plain"
  10. Ticket change [fb5d0ecad2] (rid 213918) by griffin on 2023-04-26 16:29:15:

    1. closedate changed to: "2460061.18698139"
    2. closer changed to: "griffin"
    3. icomment: "Fixed with check-in [a610e50b2faa8c52]"
    4. login: "griffin"
    5. mimetype: "text/x-fossil-plain"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"