Bug #22
Updated by J. Templ over 9 years ago
According to the specification (System/Docu/Files) in a case of read-only files (shared) NewWriter should return NIL. The current implementation, however, generates > PROCEDURE (f: File) NewWriter (old: Writer): Writer > NEW, ABSTRACT > Returns a TRAP. 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 specification needs 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 aligned with retained if possible. > If an old writer is passed as parameter, it is the implementation. In order application's responsibility to be able to avoid the TRAP, two new File methods (Shared() and Closed()) should be introduced guarantee that return 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 <pre> However the file's current state. 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; </pre> ASSERT(f.state # shared, 21); means TRAP except RETURN NIL.