comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Files and controlled types
Date: Mon, 10 Mar 2008 08:37:49 -0700 (PDT)
Date: 2008-03-10T08:37:49-07:00	[thread overview]
Message-ID: <240c1667-3489-4094-9a77-e1284defa88e@s8g2000prg.googlegroups.com> (raw)
In-Reply-To: e1019237-f828-4db1-80d8-666ed82c8858@n75g2000hsh.googlegroups.com

On Mar 9, 6:27 am, Maciej Sobczak <see.my.homep...@gmail.com> wrote:
> On 9 Mar, 04:12, "Jeffrey R. Carter" <spam.jrcarter....@spam.acm.org>
> wrote:
>
> > > File types are not Controlled.
> > > What is the rationale for this?
>
> > What makes you think they're not controlled.
>
> a) AARM
> b) trivial test
>
> > The ARM only gives the public view,
> > which is limited private; there's nothing to prevent the full view from being
> > controlled.
>
> There is nothing that mandates it and therefore I have to assume it is
> not done. This is actually what I see in tests.
>
> > In addition, the descriptions of Ada.Sequential_IO, Ada.Direct_IO,
> > and Ada.Text_IO all include the language "The type File_Type needs finalization
> > (see 7.6)".
>
> This is very good - I haven't notice it.
> It is very good, because then instead of broken library definition we
> can talk about implementation bugs - these are easier to fix.
>
> My little test follows:
>
> with Ada.Text_IO;
> procedure A is
>
>    procedure New_File (I : in Integer) is
>       Name : String := "temp/" & Integer'Image (I) & ".txt";
>       F : Ada.Text_IO.File_Type;
>    begin
>       Ada.Text_IO.Put_Line ("Opening " & Name);
>       Ada.Text_IO.Create (F, Ada.Text_IO.Out_File, Name);
> --      Ada.Text_IO.Close (F);
>    end New_File;
>
> begin
>    for I in -1000 .. -1 loop
>       New_File (I);
>    end loop;
> end;
>
> This program creates 1000 files with names "temp/-1000.txt",
> "temp/-999.txt", etc. (I use negative counters because I don't want to
> waste my time with that useless space in front of the image of
> positive integer value).
> If the File_Type has finalization, then this program is expected to
> finish correctly without the Close call (uncommented above).
> On my computer it fails with USE_ERROR after creating 253 files. If we
> add the three standard I/O streams, we get a reasonable assumption
> that the program has hit an implementation limit (256?) of open file
> descriptors.
> If I uncomment the Close call, the program properly creates full 1000
> set of files.
> I expect Close to be called automatically as part of finalization.

I'm not so sure.  What happens here?

    procedure New_File (I : in Integer) is
       Name : String := "temp/" & Integer'Image (I) & ".txt";
       F : Ada.Text_IO.File_Type;
    begin
       Ada.Text_IO.Put_Line ("Opening " & Name);
       Ada.Text_IO.Create (F, Ada.Text_IO.Out_File, Name);
       Ada.Text_IO.Set_Output (F);
    end New_File;

    procedure Proc is
    begin
       New_File (-17);
       Ada.Text_IO.Put_Line ("This is written to default output");
    end Proc;

New_File will set the current default output file to File.  When Proc
calls Put_Line, will it then write to that default output file, or
will Put_Line raise an exception or be erroneous?  I'm not 100% clear
on this.  Another question is, what do we (as language designers)
*want* it to do, or what should it do?

But in any case, I haven't seen anywhere in the RM that says that
finalizing a File_Type object involves closing it.  And examples like
this, involving default files or File_Access, show that perhaps you
don't *want* files to be closed when File_Type objects are finalized.
(The RM phrase that says a File_Type "needs finalization" is, I'm
afraid, a smokescreen; this clause has *no* impact whatsoever unless
you have a "pragma Restrictions(No_Nested_Finalization)" in effect,
which would make it illegal to declare certain File_Type objects.  See
AI95-360, http://www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00360.TXT?rev=1.11
.
This clause doesn't have any effect on the semantics.)

The bottom line is that things just aren't so simple, and it's not
obvious whether a File_Type "should" cause a Close when the File_Type
is finalized.

                               -- Adam



  reply	other threads:[~2008-03-10 15:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-08 21:22 Files and controlled types Maciej Sobczak
2008-03-08 21:56 ` gpriv
2008-03-09  3:12 ` Jeffrey R. Carter
2008-03-09 13:27   ` Maciej Sobczak
2008-03-10 15:37     ` Adam Beneschan [this message]
2008-03-10 21:45       ` Maciej Sobczak
2008-03-09 16:39   ` gpriv
2008-03-10 15:28 ` Eric Hughes
2008-03-10 22:45   ` Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox