From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Thread: 103376,74166d5f7afa0c82 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!proxad.net!usenet-fr.net!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Duncan Sands Newsgroups: comp.lang.ada Subject: Re: Return_By_Reference or Return_By_Copy (GNAT bug?) Date: Tue, 08 Mar 2005 17:12:57 +0100 Organization: Cuivre, Argent, Or Message-ID: References: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Trace: melchior.cuivre.fr.eu.org 1110298396 99025 212.85.156.195 (8 Mar 2005 16:13:16 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Tue, 8 Mar 2005 16:13:16 +0000 (UTC) Cc: comp.lang.ada@ada-france.org To: Randy Brukardt Return-Path: In-Reply-To: X-Mailer: Evolution 2.0.2 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: g2news1.google.com comp.lang.ada:8864 Date: 2005-03-08T17:12:57+01:00 On Mon, 2005-01-10 at 15:05 -0600, Randy Brukardt wrote: > "Duncan Sands" wrote in message > news:mailman.38.1105189579.527.comp.lang.ada@ada-france.org... > > Hi Randy, > > > > > > I was playing around with return by reference to see if it is possible > to > > > > get unserialized access to a protected variable using the Rosen trick > (it > > > is, > > > > see example below, especially the protected object P in package C). > Will > > > this > > > > be illegal in Ada 2005? > > > > > > Yes, it will. > > > > it seems to be legal to have a protected procedure pass out an access to a > > protected variable, allowing that variable to be accessed without > serialisation. > > I somehow expected this to be illegal... Is there any legitimate use for > it? > > I would have expected that accessibility checks would have made that > illegal. Or that it would have been legal in Ada 95. But I haven't been able > to convince myself that either is the case. I'm pretty sure that no one has > thought about this as a problem. > > Since we're still fixing problems in the standard, there is still time to > consider this issue. Therefore, I'd suggest writing an example using Ada > 2005 anonymous access functions and sending it to Ada-Comment@ada-auth.org > along with your question. That way, it will get some airing in front of the > ARG. Hi Randy, in fact there is no need for anonymous access types. Consider the following program. The protected procedure PT.G passes a pointer to one of its protected variables to an outside procedure DDD, which merrily modifies the variable with no synchronization at all. With the latest GNAT compiler I see: $ ./ddd 0 1 All the best, Duncan. -- chop here -- package CCC is type IA is access all Integer; protected PT is procedure G (P : out IA); function H return Integer; private I : aliased Integer; end; end CCC; package body CCC is protected body PT is procedure G (P : out IA) is begin P := I'Access; end; function H return Integer is begin return I; end; end; end CCC; with Ada.Text_IO; use Ada.Text_IO; with CCC; use CCC; procedure DDD is X : IA; begin Put_Line (Integer'Image (PT.H)); PT.G (X); X.all := 1; Put_Line (Integer'Image (PT.H)); end DDD;