From: Simon Belmont <sbelmont700@gmail.com>
Subject: Re: Preventing Unchecked_Deallocation?
Date: Sun, 5 Feb 2012 08:42:04 -0800 (PST)
Date: 2012-02-05T08:42:04-08:00 [thread overview]
Message-ID: <f4c34323-d0d8-4315-aaaa-31c0119e2ba4@n6g2000vbz.googlegroups.com> (raw)
In-Reply-To: ad427e2f-efdb-4e34-b4cf-ee55a3f8e9f5@f14g2000yqe.googlegroups.com
On Feb 4, 9:40 am, AdaMagica <christ-usch.gr...@t-online.de> wrote:
> Don't understand your problem. However, keep in mind that UD with a
> type different from the one with which the objects were allocated is
> erroneous.
When you say erroneous, do you mean forbidden by the language (i.e. an
exception) or that it will cause undefined operation? My concern is
that if a unit exposes an access value to other units, any of them may
use UD to delete the object at any time. Obviously this sort of
behavior would cause the program to quickly crash due to a null
pointer, but all things being equal I would prefer a compile-time
mechanism to prevent the UD outright. For instance:
package ud is
function Get return not null access Integer;
end ud;
package body ud is
type Int_Ptr is access all Integer;
o : Int_Ptr := new Integer'(42);
function Get return not null access Integer is
begin
return o;
end Get;
end ud;
procedure test is
type Fake_Ptr is access all Integer;
procedure Free is new Ada.Unchecked_Deallocation (Object => Integer,
Name => Fake_Ptr);
p : Fake_Ptr;
begin
p := Fake_Ptr(ud.Get); -- cast to a local type
Free (p); -- phuck the whole program
end test;
-sb
next prev parent reply other threads:[~2012-02-05 16:42 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-02 23:41 Preventing Unchecked_Deallocation? Simon Belmont
2012-02-04 14:40 ` AdaMagica
2012-02-05 16:42 ` Simon Belmont [this message]
2012-02-06 12:52 ` Julian Leyh
2012-02-06 16:05 ` Adam Beneschan
2012-02-06 16:21 ` Adam Beneschan
2012-02-06 18:34 ` AdaMagica
2012-02-07 0:14 ` Simon Belmont
2012-02-07 2:19 ` Shark8
2012-02-07 16:39 ` Robert A Duff
2012-02-07 11:42 ` Gautier write-only
2012-02-07 21:11 ` Simon Belmont
2012-02-07 21:30 ` Robert A Duff
2012-02-07 22:23 ` Simon Wright
2012-02-07 23:07 ` Robert A Duff
2012-02-08 8:43 ` Simon Wright
2012-02-08 15:06 ` Robert A Duff
2012-02-09 2:22 ` Randy Brukardt
2012-02-09 7:28 ` Simon Wright
2012-02-07 23:06 ` Alan Copeland
2012-02-07 23:10 ` Robert A Duff
2012-02-09 2:49 ` Randy Brukardt
2012-02-09 3:39 ` Jeffrey Carter
2012-02-09 15:47 ` Adam Beneschan
2012-02-09 19:16 ` Jeffrey Carter
2012-02-09 7:37 ` Simon Wright
2012-02-10 1:08 ` Randy Brukardt
2012-02-10 7:35 ` Simon Wright
2012-02-07 6:26 ` Jeffrey Carter
2012-02-08 8:49 ` Maciej Sobczak
2012-02-08 23:40 ` BrianG
2012-02-09 2:57 ` Randy Brukardt
2012-02-09 7:13 ` Pascal Obry
2012-02-10 1:12 ` Randy Brukardt
2012-02-09 8:08 ` Maciej Sobczak
2012-02-10 1:18 ` Randy Brukardt
2012-02-07 16:27 ` 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