Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: fbea0d45bddb79b7521cb5949d41276b99bc1b9deab9e6c82feefe776619d50b
Ticket: b8f575aa2398b0e44b5a037326b9d75037e2da4a
Tcl 9: eof erroneously flagged with not reported encoding read error
User & Date: jan.nijtmans on 2022-12-09 08:06:10
Changes

  1. assignee changed to: "jan.nijtmans"
  2. icomment:
    Compare this with (which works in both 8.7 and 9.0), using same data.txt
    <pre>
    % set myfd [open "data.txt"]
    file4
    % fconfigure $myfd -encoding utf-8 -eofchar D
    % set data [read $myfd]
    ABC
    % puts "eof [eof $myfd]"
    eof 1
    % puts "fblocked [fblocked $myfd]"
    fblocked 0
    % puts "data length [string length $data]"
    data length 4
    % puts "data: $data"
    data: ABC
    % set data [read $myfd]
    % puts "data: $data"
    data:
    % puts "data length [string length $data]"
    data length 0
    </pre>
    
    It's the same surprise. Since "-eofchar D", stops reading the stream when the 'D' is encountered, "-strictencoding 1" stops reading the stream when \x81 is encountered. The remaining of the characters are read as well, but stored in an internal buffer. So the "eof 1" is - kind of - logical but surprising: the stream reached EOF, but it's not visible yet because not all characters are returned.
    
    I could imagine that we want eof to report 0 in this case. That would encourage doing another "read", which throws an exception showing why the previous "read" stopped there.
    
    Thanks for the report!
    
  3. login: "jan.nijtmans"
  4. mimetype: "text/x-fossil-wiki"