comp.lang.ada
 help / color / mirror / Atom feed
* Re: Free'ing extended types
@ 1996-04-28  0:00 Jonas Nygren
  1996-04-28  0:00 ` Robert Dewar
  0 siblings, 1 reply; 21+ messages in thread
From: Jonas Nygren @ 1996-04-28  0:00 UTC (permalink / raw)



I forward this on the request of Laurent.

: Laurent Guerby wrote:
: > Jonas Nygren writes
: > : I read the following in the RM on unchecked_deallocation:
: > :
: > : 13.11.2(16)
: > :      .... The execution of a call to an instance of
: > :      Unchecked_Deallocation is erroneous if the object
: > :      was created other than by an allocator for an
: > :      access type whose pool is Name'Storage_Pool.
[deleted]
: Sorry, I got my example code wrong, it should have been:
:
:        procedure free is new unchecked_deallocation(a'Class, 
ap);
:
: 13.11.2(16) talks about 'erroneous execution', i.e. an error 
which the
: compiler can/need not detect. In the example 'p' is a pointer 
to a'class
: and when the call to free is made it actually points to an 
instance of
: type 'b'. So the question is, could this be considered an 
erroneous
: execution?

   I  *think*   that it (erroneous/not  erroneous)   is 
implementation
dependant, because for  each  access  type  the  Storage_Pool  
(if not
user-specified) is choosen  "in an implementation-defined 
manner", see
13.11(17). This has to be documented for each compiler. In the 
case of
GNAT, here is the code for Unchecked_Deallocation :

with System;

procedure Unchecked_Deallocation (X : in out Name) is
   procedure Free (A : System.Address);
   pragma Import (C, Free);

begin
   if X /= null then
      Free (X.all'Address);
      X := null;
   end if;
end Unchecked_Deallocation;

   So there's nothing that could lead  to an erroneous execution 
(note
the X.all'access, the libc then does what's needed).

: /jonas

PS: this  is of general interest, please  post your  correction 
and my
answer to  comp.lang.ada for  verification  (legality stuff   and 
GNAT
stuff) for me, my news server is down this week-end. Thank you.

--
--  Laurent Guerby, student at Telecom Bretagne (France), Team 
Ada.
--  "Use the Source, Luke. The Source will be with you, always 
(GPL)."
--  http://www-eleves.enst-bretagne.fr/~guerby/ (GATO Project).
--  Try GNAT, the GNU Ada 95 compiler 
(ftp://cs.nyu.edu/pub/gnat).




^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~1996-05-24  0:00 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-04-28  0:00 Free'ing extended types Jonas Nygren
1996-04-28  0:00 ` Robert Dewar
1996-04-29  0:00   ` Laurent Guerby
1996-04-29  0:00     ` Robert A Duff
1996-04-29  0:00       ` Robert Dewar
1996-04-29  0:00   ` Jonas Nygren
1996-04-29  0:00     ` Robert A Duff
1996-04-29  0:00       ` Robert Dewar
1996-04-29  0:00         ` Robert A Duff
1996-04-29  0:00       ` Jonas Nygren
1996-05-20  0:00       ` Type conversion between access types (was: Free'ing extended types) Scott Leschke
1996-05-21  0:00         ` Dale Stanbrough
1996-05-21  0:00           ` Robert A Duff
1996-05-21  0:00         ` Robert A Duff
1996-05-22  0:00           ` Scott Leschke
1996-05-23  0:00             ` Robert A Duff
1996-05-23  0:00               ` progers
1996-05-24  0:00               ` Scott Leschke
1996-05-24  0:00                 ` Robert A Duff
1996-04-29  0:00   ` Free'ing extended types Laurent Guerby
1996-04-29  0:00     ` Robert A Duff

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