Bug #22

HostFiles.NewWriter violating the specification

Added by I. Denisov almost 5 years ago. Updated over 3 years ago.

Status:ClosedStart date:11/23/2014
Priority:HighDue date:
Assignee:I. Denisov% Done:

70%

Category:-
Target version:1.7
Forum topic:

Description

According to the specification (System/Docu/Files) in case of read-only files (shared) NewWriter should return NIL. The current implementation, however, generates a TRAP. The specification needs to be aligned with the implementation. In order to be able to avoid the TRAP, two new File methods (Shared() and Closed()) should be introduced that return the file's current state.

Reported by Ilya Ermakov, 2009-10-12.

Associated revisions

Revision 8ed4dba1
Added by I. Denisov almost 5 years ago

Documentation for Files fixed according the sources logic. New procedures Shared() and Closed() were added for balancing of ASSERTs inside NewWriter procedure. Refs: #22

Revision 8563d473
Added by I. Denisov almost 5 years ago

ScriptHostFiles updated according new Files interface. Refs: #22

Revision 3d256d55
Added by I. Denisov almost 5 years ago

Documentation for Closed and Shared. The changes marked in the headers of the sources. Refs: #22

History

#1 Updated by I. Denisov over 4 years ago

  • Status changed from In Progress to Closed

#2 Updated by J. Templ over 3 years ago

  • Description updated (diff)

PROCEDURE (f: File) NewWriter (old: Writer): Writer
NEW, ABSTRACT
Returns a writer which has the appropriate type (for this file type). If old = NIL, then a new writer is allocated. If old # NIL and old has the appropriate type, old is returned. Otherwise, a new writer is allocated. The returned writer is connected to f, and its position is somewhere on the file. If an old writer is passed as parameter, the old position will be retained if possible.
If an old writer is passed as parameter, it is the application's responsibility to guarantee that it is not in use anymore. Passing an unused old writer is recommended because it avoids unnecessary allocations.
[b]Read-only files allow no writers at all. In such cases, NewWriter returns NIL.[/b]

Post
result # NIL
old # NIL & old.Base() = f
result.Pos() = old.Pos()
old = NIL OR old.Base() # f
result.Pos() = f.Length()
result = NIL
read-only file

However the code of HostFiles is next:
       PROCEDURE (f: File) NewWriter (old: Files.Writer): Files.Writer;
          VAR w: Writer;
       BEGIN   (* portable *)
          ASSERT(f.state # closed, 20); ASSERT(f.state # shared, 21);
          IF (old # NIL) & (old IS Writer) THEN w := old(Writer) ELSE NEW(w) END;
          IF w.base # f THEN
             w.base := f; w.buf := NIL; w.SetPos(f.len)
          END;
          RETURN w
       END NewWriter;

ASSERT; means TRAP except RETURN NIL.

#3 Updated by J. Templ over 3 years ago

  • Description updated (diff)

Also available in: Atom PDF