Issue #22: HostFiles.NewWriter violating the specification

Re: B1: HostFiles.NewWriter is violating the specification

Postby DGDanforth » Fri Sep 19, 2014 3:52 am

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?
User avatar
DGDanforth
 
Posts: 1061
Joined: Tue Sep 17, 2013 1:16 am
Location: Palo Alto, California, USA

Re: B1: HostFiles.NewWriter is violating the specification

Postby Ivan Denisov » Fri Sep 19, 2014 4:07 am

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.
Ivan Denisov
 
Posts: 1694
Joined: Tue Sep 17, 2013 12:21 am
Location: Russia

Re: B1: HostFiles.NewWriter is violating the specification

Postby DGDanforth » Fri Sep 19, 2014 7:40 am

"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.
User avatar
DGDanforth
 
Posts: 1061
Joined: Tue Sep 17, 2013 1:16 am
Location: Palo Alto, California, USA

Re: B1: HostFiles.NewWriter is violating the specification

Postby Ivan Denisov » Sat Sep 20, 2014 12:24 am

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.
Ivan Denisov
 
Posts: 1694
Joined: Tue Sep 17, 2013 12:21 am
Location: Russia

Re: B1: HostFiles.NewWriter is violating the specification

Postby DGDanforth » Sat Sep 20, 2014 5:09 am

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
DGDanforth
 
Posts: 1061
Joined: Tue Sep 17, 2013 1:16 am
Location: Palo Alto, California, USA

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

Postby Josef Templ » Tue Dec 09, 2014 10:15 am

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
User avatar
Josef Templ
 
Posts: 2012
Joined: Tue Sep 17, 2013 6:50 am

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

Postby Zinn » Sat Dec 13, 2014 6:33 am

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
Zinn
 
Posts: 470
Joined: Tue Mar 25, 2014 5:56 pm
Location: Frankfurt am Main

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

Postby Josef Templ » Mon Dec 15, 2014 8:48 am

> 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
User avatar
Josef Templ
 
Posts: 2012
Joined: Tue Sep 17, 2013 6:50 am

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

Postby Ivan Denisov » Mon Dec 15, 2014 10:58 pm

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.
Ivan Denisov
 
Posts: 1694
Joined: Tue Sep 17, 2013 12:21 am
Location: Russia

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

Postby Josef Templ » Tue Dec 16, 2014 8:14 am

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
User avatar
Josef Templ
 
Posts: 2012
Joined: Tue Sep 17, 2013 6:50 am

PreviousNext

Return to Resolved (Bugs)

Who is online

Users browsing this forum: No registered users and 1 guest

cron