Issue #22: HostFiles.NewWriter violating the specification

User avatar
DGDanforth
Posts: 1061
Joined: Tue Sep 17, 2013 1:16 am
Location: Palo Alto, California, USA
Contact:

Re: B1: HostFiles.NewWriter is violating the specification

Post by DGDanforth »

Ivan Denisov wrote:No. We need to remove:
"In such cases, NewWriter returns NIL."

Because it does not returns NIL, but TRAP.
OK I see your point. But what should NewWriter return if the file is closed?
Ivan Denisov
Posts: 1700
Joined: Tue Sep 17, 2013 12:21 am
Location: Russia

Re: B1: HostFiles.NewWriter is violating the specification

Post by Ivan Denisov »

According to the logic of Oberon microsystems it should call TRAP in that case.

This is wise, because this is the programmer fault, and it should be fixed by programmer.

The same is about SHARED files. Because documentation said that you should not use shared files for writing.

It is possible in rare cases, for this we can add Close() and Shared() procedures for knowing the state before making Writer.
User avatar
DGDanforth
Posts: 1061
Joined: Tue Sep 17, 2013 1:16 am
Location: Palo Alto, California, USA
Contact:

Re: B1: HostFiles.NewWriter is violating the specification

Post by DGDanforth »

"It is possible in rare cases, for this we can add Close() and Shared() procedures for knowing the state before making Writer."

You mean "Closed()", I assume.
Ivan Denisov
Posts: 1700
Joined: Tue Sep 17, 2013 12:21 am
Location: Russia

Re: B1: HostFiles.NewWriter is violating the specification

Post by Ivan Denisov »

DGDanforth wrote:"It is possible in rare cases, for this we can add Close() and Shared() procedures for knowing the state before making Writer."

You mean "Closed()", I assume.
Yes.
User avatar
DGDanforth
Posts: 1061
Joined: Tue Sep 17, 2013 1:16 am
Location: Palo Alto, California, USA
Contact:

Re: B1: HostFiles.NewWriter is violating the specification

Post by DGDanforth »

An aside comment.

In MyFiles (which is a wrapper around Files) I don't even export Writer so the issue of NewWriter never comes up.

I don't think I ever tried to open a read only file and attempted to write to it. But that possibility says I need to modify MyFiles to handle that case where an attempt to open such a file for writing will simply fail, return FALSE for

flag := wc.Open(wr, path, name);

where
wc: MyFiles.WriteController;
wr: Stores.Writer;

Ivan, I am still thinking about your recommendations.
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: Issue #22: HostFiles.NewWriter violating the specificati

Post by Josef Templ »

In addition to removing one sentence form the specification we should add a precondition
that defines the valid state(s) when calling NewWriter.

It will probably turn out to be helpful to have the functions Closed() and Shared() available
when specifying the precondition.

- Josef
Zinn
Posts: 476
Joined: Tue Mar 25, 2014 5:56 pm
Location: Frankfurt am Main
Contact:

Re: Issue #22: HostFiles.NewWriter violating the specificati

Post by Zinn »

Josef Templ wrote: It will probably turn out to be helpful to have the functions Closed() and Shared() available
when specifying the precondition.
- Josef
Does Shared() also mean that the file is already open for read?
For what do we need Closed()?
Sometimes I miss the function Exist().
What is about Readonly()? Do we need it too?

- Helmut
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: Issue #22: HostFiles.NewWriter violating the specificati

Post by Josef Templ »

> Does Shared() also mean that the file is already open for read?

the answer is YES, the file is open for reading because:

In HostFiles.NewWriter:
> ASSERT(f.state # closed, 20); ASSERT(f.state # shared, 21);

Closed() and Shared() refer to the states 'closed' and 'shared'.
Therefore shared implies NOT closed.

Closed() and Shared() allow to do a check of the precondition before calling NewWriter
and thereby avoiding a TRAP if the precondition is not true. This is used rarely (never so far)
but for the sake of completeness I would support their inclusion.
It would also make the precondition very simple to specify:

Pre:
~f.Closed() 20
~f.Shared() 21

- Josef
Ivan Denisov
Posts: 1700
Joined: Tue Sep 17, 2013 12:21 am
Location: Russia

Re: Issue #22: HostFiles.NewWriter violating the specificati

Post by Ivan Denisov »

I made branch for this issue. Please, check me:
http://redmine.blackboxframework.org/pr ... 2de8e6e1a9

This is version of BlackBox fixed according this discussion:
http://blackboxframework.org/unstable/i ... a1.035.zip

If all is ok, I think, that we are ready to vote.
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: Issue #22: HostFiles.NewWriter violating the specificati

Post by Josef Templ »

Code: Select all

    ASSERT(~f.Shared(), 21);
    (* Always TRAP 21 since all packed files are read only *)
In principle, this could be simplified to

Code: Select all

    HALT(21); (* Always TRAP 21 since all packed files are read only *)
- Josef
Post Reply