comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Reference counter in smart pointers are not updated properly when used by multiple tasks
Date: Thu, 1 Feb 2018 18:09:37 -0600
Date: 2018-02-01T18:09:37-06:00	[thread overview]
Message-ID: <p50a81$o5v$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: p4v9b8$8o1$1@dont-email.me

"Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> wrote in message 
news:p4v9b8$8o1$1@dont-email.me...
> The referenced code has a library-level generic package 
> Orka.Smart_Pointers with the public declaration
>
> type Free_Ptr is not null access procedure (Value : in out Object_Type);
>
> The body of the generic pkg has
>
>    procedure Set
>      (Object : in out Abstract_Pointer;
>       Value  : Object_Type;
>       Free   : not null access procedure (Value : in out Object_Type))
>    is
>       Procedure_Free : constant Free_Ptr := Free;

This is illegal. An anonymous access-to-subprogram has "infinite" 
accessibility, so it cannot be assigned to any other kind of 
access-to-subprogram type. The entire idea is that such parameters don't 
live longer than the call that created them.

GNAT allows doing this with the distinctly non-Standard 
'Unrestricted_Access, so it probably can actually execute it, but that would 
not be the case for other Ada compilers.

If the parameter Free had type Free_Ptr, then this would work.

...
> Set's parameter Free is an anonymous access-to-subprogram parameter; one 
> is not supposed to be able to assign those and call them later, but that 
> is exactly what this code does. Is this code legal? GNAT compiles it fine. 
> If it is legal, should it be?

It's definitely not legal.

                    Randy.



  parent reply	other threads:[~2018-02-02  0:09 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-01  5:52 Reference counter in smart pointers are not updated properly when used by multiple tasks onox
2018-02-01  8:39 ` Dmitry A. Kazakov
2018-02-01 10:01   ` onox
2018-02-01 10:28     ` onox
2018-02-01 10:51       ` Dmitry A. Kazakov
2018-02-01 10:57     ` Dmitry A. Kazakov
2018-02-01  8:41 ` Simon Wright
2018-02-01 14:48 ` Jeffrey R. Carter
2018-02-01 19:37   ` onox
2018-02-01 20:12     ` Jeffrey R. Carter
2018-02-02  0:09   ` Randy Brukardt [this message]
2018-02-01 19:04 ` 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