comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Issue with GNAT GPL 2009 and GtkAda
Date: Tue, 30 Jun 2009 14:10:22 -0400
Date: 2009-06-30T14:10:22-04:00	[thread overview]
Message-ID: <wccbpo5vbht.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: uvdmem0ww.fsf@stephe-leake.org

Stephen Leake <stephen_leake@stephe-leake.org> writes:

> Robert A Duff <bobduff@shell01.TheWorld.com> writes:
>>     type T_Ref is access all T;
>>     Global : T_Ref;
>>
>>     procedure P (X : in out T) is -- Suppose T is tagged.
>>     begin
>>         Global := X'Access; -- Illegal!
>>     end P;
>>
>>     procedure Q (...) is
>>         Local : aliased T;
>>     begin
>>         P (Local);
>>     end Q;
>>
>> After calling Q, Global is a dangling pointer.  The language design rule
>> is:  If you do anything that _might_ create a dangling pointer, you
>> have to use 'Unchecked_Access (and take care).
>
> But if X was actually a global object, 'Access would be ok; I thought
> the run-time accessibility checks would handle that case for tagged
> types.
>
> But apparently accessibility information is only passed with access
> parameters (either 'access', or 'in [out]' of an access type).

Right.  Access parameters (anonymous access types only!) get the extra
info, other parameters, and regular objects and so on do not.

> This is my key mis-understanding. If 'in out' parameters of tagged types
> carried accessibility information that could be checked at runtime,
> the above example would be ok.

Yes.

> I'm not clear why you say that is the "wrong direction".

Because I think it was a mistake to use dynamic accessibility
for access parameters.  For the usual reasons:  Catching
errors sooner is better than later.  Especially when "later"
means "by the customer".  Run-time checks are inefficient.

Run-time checks give more flexibility, usually.  But in this
case, I don't find that important.  When using access parameters,
it's (almost?) always the case that either:

    1. The callee expects to store the pointer in a global,
       so the caller needs to pass a pointer to a global.

    2. The caller can pass pointers to local objects,
       so the callee had better not store the pointer in a global.

And this distinction is known when writing the code.
You don't see code like:

    if (the thing is pointing to a global) then
        Store it globally;
    else
        Do something else;
    end if;

Unfortunately, this distinction is not visible in the spec.
How is the caller supposed to know whether it's OK
to pass a pointer to local?  You have to look at the
body of the callee, or trust in comments.

I also don't like the fact that anonymity causes all kinds of magic.
It's confusing.  I think:

    type T is <some stuff>;
    X : T;

and

    X : <some stuff>;

ought to mean the same thing (whether X is a parameter,
or something else).

- Bob



  reply	other threads:[~2009-06-30 18:10 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-23 21:52 Issue with GNAT GPL 2009 and GtkAda Damien Carbonne
2009-06-24  7:40 ` Dmitry A. Kazakov
2009-06-24 10:15 ` Stephen Leake
2009-06-25  9:06   ` Stephen Leake
2009-06-25  9:39     ` Dmitry A. Kazakov
2009-06-25 19:02       ` Damien Carbonne
2009-06-26  9:31         ` Stephen Leake
2009-06-26 11:18           ` Niklas Holsti
2009-06-26 16:29             ` Damien Carbonne
2009-06-26 17:28               ` Dmitry A. Kazakov
2009-06-26 19:27                 ` Damien Carbonne
2009-06-26 19:50                   ` Dmitry A. Kazakov
2009-06-26 21:51             ` Randy Brukardt
2009-06-27 11:11               ` Stephen Leake
2009-06-27 17:04                 ` Robert A Duff
2009-06-30 11:11                   ` Stephen Leake
2009-06-30 18:10                     ` Robert A Duff [this message]
2009-06-29 22:11                 ` Randy Brukardt
2009-06-30 11:13                   ` Stephen Leake
2009-06-30 15:26                     ` Adam Beneschan
2009-06-30 15:59               ` Adam Beneschan
2009-06-30 23:11                 ` Randy Brukardt
2009-06-27  9:56             ` Stephen Leake
2009-06-26 21:03           ` Damien Carbonne
2009-06-27 11:21             ` Stephen Leake
2009-06-27 12:25               ` Damien Carbonne
2009-06-27 12:35                 ` Damien Carbonne
2009-06-29 22:15                   ` Randy Brukardt
2009-07-01 19:22                     ` Damien Carbonne
2009-06-30  0:48             ` Adam Beneschan
2009-06-30 11:18               ` Stephen Leake
2009-06-25 20:49       ` Randy Brukardt
2009-06-26  7:20         ` Dmitry A. Kazakov
2009-06-26  8:17           ` Georg Bauhaus
2009-06-26  8:52             ` Dmitry A. Kazakov
2009-06-26 21:38               ` Randy Brukardt
2009-06-27  7:47                 ` Dmitry A. Kazakov
2009-06-29 21:59                   ` Randy Brukardt
2009-06-30  8:31                     ` Dmitry A. Kazakov
2009-06-26 21:31           ` Randy Brukardt
2009-06-27  7:53             ` Dmitry A. Kazakov
2009-06-26  8:39       ` Alex R. Mosteo
2009-06-26  9:07         ` Dmitry A. Kazakov
2009-06-27  9:53           ` Stephen Leake
2009-06-26 21:40         ` Randy Brukardt
2009-06-29 10:04           ` Alex R. Mosteo
2009-06-26  9:02       ` Stephen Leake
2009-06-26  9:14         ` Dmitry A. Kazakov
replies disabled

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