Page 3 of 4

Re: B1: HostFiles.NewWriter is violating the specification

PostPosted: Fri Sep 19, 2014 3:52 am
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?

Re: B1: HostFiles.NewWriter is violating the specification

PostPosted: Fri Sep 19, 2014 4:07 am
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.

Re: B1: HostFiles.NewWriter is violating the specification

PostPosted: Fri Sep 19, 2014 7:40 am
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.

Re: B1: HostFiles.NewWriter is violating the specification

PostPosted: Sat Sep 20, 2014 12:24 am
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.

Re: B1: HostFiles.NewWriter is violating the specification

PostPosted: Sat Sep 20, 2014 5:09 am
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.

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

PostPosted: Tue Dec 09, 2014 10:15 am
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

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

PostPosted: Sat Dec 13, 2014 6:33 am
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

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

PostPosted: Mon Dec 15, 2014 8:48 am
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

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

PostPosted: Mon Dec 15, 2014 10:58 pm
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.

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

PostPosted: Tue Dec 16, 2014 8:14 am
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