OK I see your point. But what should NewWriter return if the file is closed?Ivan Denisov wrote:No. We need to remove:
"In such cases, NewWriter returns NIL."
Because it does not returns NIL, but TRAP.
Issue #22: HostFiles.NewWriter violating the specification
- 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
-
- Posts: 1700
- Joined: Tue Sep 17, 2013 12:21 am
- Location: Russia
Re: B1: HostFiles.NewWriter is violating the specification
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.
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.
- 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
"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.
You mean "Closed()", I assume.
-
- Posts: 1700
- Joined: Tue Sep 17, 2013 12:21 am
- Location: Russia
Re: B1: HostFiles.NewWriter is violating the specification
Yes.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.
- 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
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.
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.
- Josef Templ
- Posts: 2047
- Joined: Tue Sep 17, 2013 6:50 am
Re: Issue #22: HostFiles.NewWriter violating the specificati
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
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
Does Shared() also mean that the file is already open for read?Josef Templ wrote: It will probably turn out to be helpful to have the functions Closed() and Shared() available
when specifying the precondition.
- Josef
For what do we need Closed()?
Sometimes I miss the function Exist().
What is about Readonly()? Do we need it too?
- Helmut
- Josef Templ
- Posts: 2047
- Joined: Tue Sep 17, 2013 6:50 am
Re: Issue #22: HostFiles.NewWriter violating the specificati
> 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
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
-
- Posts: 1700
- Joined: Tue Sep 17, 2013 12:21 am
- Location: Russia
Re: Issue #22: HostFiles.NewWriter violating the specificati
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.
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.
- Josef Templ
- Posts: 2047
- Joined: Tue Sep 17, 2013 6:50 am
Re: Issue #22: HostFiles.NewWriter violating the specificati
Code: Select all
ASSERT(~f.Shared(), 21);
(* Always TRAP 21 since all packed files are read only *)
Code: Select all
HALT(21); (* Always TRAP 21 since all packed files are read only *)