comp.lang.ada
 help / color / mirror / Atom feed
* GNAT 4.2.3 Ubuntu reports weird compile error wrt Unchecked_Access
@ 2008-08-15 20:26 Jerry
  2008-08-16 10:26 ` Ludovic Brenta
  2008-08-17  5:59 ` anon
  0 siblings, 2 replies; 10+ messages in thread
From: Jerry @ 2008-08-15 20:26 UTC (permalink / raw)


I have a curious report from two members of the development team for
PLplot, a popular plotting package for which I have written bindings
in Ada. The project is mature enough that the team decided to enable
Ada by default when building, so I am concerned about the following e-
mail.

========== begin e-mail ============

<First comment from team member>

This latest change to the Ada bindings causes a build error for me
with gnat 4.2.3 on Ubuntu.

plplot.adb:2751:37: non-local pointer cannot point to local object
The offending line is
    PL_Pen_Labels(Index) := Temp_C_String'Unchecked_Access;

<Response from another team member>

This must depend on the version of gnat since I don't see this error
for gnat 4.3.1-2 from Debian testing (and I presume Jerry didn't see
it for his gnat-4.3 version as well).

========= end e-mail ==============

I (Jerry) in fact did not see a problem on my OS X 4.3 compiler.

I could supply more details of the code and might even try to write a
small program but testing on someone else's machine would be a bit
tedious. BUT--this error makes no sense to me--I would expect to (and
_do_) see this error if the line in question is

    PL_Pen_Labels(Index) := Temp_C_String'Access;

The whole purpose of using Unchecked_Access is to make this error go
away. It this a known problem on 4.2.3 Unbutu? Is it a compiler error?
Why does it work as expected on my 4.3 OS X, on 4.3.1-2 Debian
testing, but not 4.2.3 Ubuntu?

Jerry



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

* Re: GNAT 4.2.3 Ubuntu reports weird compile error wrt Unchecked_Access
  2008-08-15 20:26 GNAT 4.2.3 Ubuntu reports weird compile error wrt Unchecked_Access Jerry
@ 2008-08-16 10:26 ` Ludovic Brenta
  2008-08-16 10:35   ` Ludovic Brenta
  2008-08-17  0:03   ` Jerry
  2008-08-17  5:59 ` anon
  1 sibling, 2 replies; 10+ messages in thread
From: Ludovic Brenta @ 2008-08-16 10:26 UTC (permalink / raw)


Jerry wrote:
> The whole purpose of using Unchecked_Access is to make this error go
> away. It this a known problem on 4.2.3 Unbutu? Is it a compiler error?
> Why does it work as expected on my 4.3 OS X, on 4.3.1-2 Debian
> testing, but not 4.2.3 Ubuntu?

Without more context I cannot tell for sure but I believe this is a
compiler error in the sense that gnat-4.2 does not implement all the
new (and more permissive) rules in Ada 2005 regarding anonymous access
types. gnat-3.2 implements these rules.

BTW, I've mentioned already that Ubuntu 8.04 has broken support for
Ada. Better stick to Debian.

--
Ludovic Brenta.



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

* Re: GNAT 4.2.3 Ubuntu reports weird compile error wrt Unchecked_Access
  2008-08-16 10:26 ` Ludovic Brenta
@ 2008-08-16 10:35   ` Ludovic Brenta
  2008-08-17  0:03   ` Jerry
  1 sibling, 0 replies; 10+ messages in thread
From: Ludovic Brenta @ 2008-08-16 10:35 UTC (permalink / raw)


I wrote:
> gnat-4.2 does not implement all the new (and more permissive)
> rules in Ada 2005 regarding anonymous access types.

By more permissive I mean that some compile-time checks are deferred
until run-time, and anonymous access types are now allowed in more
places.

> gnat-3.2 implements these rules.

Of course I meant gnat-4.3.

--
Ludovic Brenta.




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

* Re: GNAT 4.2.3 Ubuntu reports weird compile error wrt Unchecked_Access
  2008-08-16 10:26 ` Ludovic Brenta
  2008-08-16 10:35   ` Ludovic Brenta
@ 2008-08-17  0:03   ` Jerry
  2008-08-17 17:14     ` Simon Wright
  1 sibling, 1 reply; 10+ messages in thread
From: Jerry @ 2008-08-17  0:03 UTC (permalink / raw)


On Aug 16, 3:26 am, Ludovic Brenta <ludo...@ludovic-brenta.org> wrote:
> Without more context I cannot tell for sure but I believe this is a
> compiler error in the sense that gnat-4.2 does not implement all the
> new (and more permissive) rules in Ada 2005 regarding anonymous access
> types. gnat-3.2 implements these rules.
>
> BTW, I've mentioned already that Ubuntu 8.04 has broken support for
> Ada. Better stick to Debian.
>
> --
> Ludovic Brenta.

I can quickly get in over my head here and I'm not very familiar with
anonymous access types, but isn't 'Unchecked_Access a part of Ada 95
if not 83?

Jerry




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

* Re: GNAT 4.2.3 Ubuntu reports weird compile error wrt Unchecked_Access
  2008-08-15 20:26 GNAT 4.2.3 Ubuntu reports weird compile error wrt Unchecked_Access Jerry
  2008-08-16 10:26 ` Ludovic Brenta
@ 2008-08-17  5:59 ` anon
  2008-08-17 19:47   ` anon
  2008-08-17 20:58   ` Jerry
  1 sibling, 2 replies; 10+ messages in thread
From: anon @ 2008-08-17  5:59 UTC (permalink / raw)


If the GNAT compiler follows the RM on "accessibility" rules.  Then it
will force you to use the "Unchecked_Access" attribute for any non-local 
pointer trying to point to local object".  Solution: If possible move the 
object to be access to a package global variable (non-local), then you can 
use Access attribute.


Note:
RM 13.10 (1) => "The attribute Unchecked_Access is used to create access 
values in an unsafe manner -- the programmer is responsible for 
preventing 'dangling references.' "



In <7053ea09-38cd-4e30-9827-a1384bafd190@p31g2000prf.googlegroups.com>, Jerry <lanceboyle@qwest.net> writes:
>I have a curious report from two members of the development team for
>PLplot, a popular plotting package for which I have written bindings
>in Ada. The project is mature enough that the team decided to enable
>Ada by default when building, so I am concerned about the following e-
>mail.
>
>========== begin e-mail ============
>
><First comment from team member>
>
>This latest change to the Ada bindings causes a build error for me
>with gnat 4.2.3 on Ubuntu.
>
>plplot.adb:2751:37: non-local pointer cannot point to local object
>The offending line is
>    PL_Pen_Labels(Index) := Temp_C_String'Unchecked_Access;
>
><Response from another team member>
>
>This must depend on the version of gnat since I don't see this error
>for gnat 4.3.1-2 from Debian testing (and I presume Jerry didn't see
>it for his gnat-4.3 version as well).
>
>========= end e-mail ==============
>
>I (Jerry) in fact did not see a problem on my OS X 4.3 compiler.
>
>I could supply more details of the code and might even try to write a
>small program but testing on someone else's machine would be a bit
>tedious. BUT--this error makes no sense to me--I would expect to (and
>_do_) see this error if the line in question is
>
>    PL_Pen_Labels(Index) := Temp_C_String'Access;
>
>The whole purpose of using Unchecked_Access is to make this error go
>away. It this a known problem on 4.2.3 Unbutu? Is it a compiler error?
>Why does it work as expected on my 4.3 OS X, on 4.3.1-2 Debian
>testing, but not 4.2.3 Ubuntu?
>
>Jerry




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

* Re: GNAT 4.2.3 Ubuntu reports weird compile error wrt Unchecked_Access
  2008-08-17  0:03   ` Jerry
@ 2008-08-17 17:14     ` Simon Wright
  2008-08-17 21:05       ` Jerry
  0 siblings, 1 reply; 10+ messages in thread
From: Simon Wright @ 2008-08-17 17:14 UTC (permalink / raw)


Jerry <lanceboyle@qwest.net> writes:

> On Aug 16, 3:26�am, Ludovic Brenta <ludo...@ludovic-brenta.org> wrote:
>> Without more context I cannot tell for sure but I believe this is a
>> compiler error in the sense that gnat-4.2 does not implement all the
>> new (and more permissive) rules in Ada 2005 regarding anonymous access
>> types. gnat-3.2 implements these rules.
>>
>> BTW, I've mentioned already that Ubuntu 8.04 has broken support for
>> Ada. Better stick to Debian.
>>
>> --
>> Ludovic Brenta.
>
> I can quickly get in over my head here and I'm not very familiar with
> anonymous access types, but isn't 'Unchecked_Access a part of Ada 95
> if not 83?

Not 83, I think.

The thing is, 'Unchecked_Access may well be allowed in more places in
'05 than it was in '95; and compilers don't always get this sort of
thing right first time.

GNAT has 'Unrestricted_Access for places where the rules (or the
compiler) don't allow 'Unhchecked_Access.



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

* Re: GNAT 4.2.3 Ubuntu reports weird compile error wrt Unchecked_Access
  2008-08-17  5:59 ` anon
@ 2008-08-17 19:47   ` anon
  2008-08-17 21:14     ` Jerry
  2008-08-17 20:58   ` Jerry
  1 sibling, 1 reply; 10+ messages in thread
From: anon @ 2008-08-17 19:47 UTC (permalink / raw)


Addition:

The problem is that local data is stored on the primary stack and if an error 
is encounter the exception handlers could remove the local data off the stack, 
creating a 'dangling references.'. Which would makes the pointer (Access 
variable) invalid or unsafe.

So, you must use the "Unchecked_Access" for local data and the programmer 
is responsible for catching any exceptions or other conditions that might 
cause a 'dangling reference.'

Also, because of the specs refering to "Access" and "Unchecked_Access" 
in both Ada_95 and Ada_2005 is basically unchanged you can use 
"Unchecked_Access" instead of "Access" but be warned you must insure 
the code is safe.

And any GNAT that does not support this type of safety should be concerned 
as corrupt and unusable.

PS.  As for Ada-83, the answer is no!  "Unchecked_Access" was added 
during the creation of Ada-95. 



In <37Ppk.5180$Mh5.1917@bgtnsc04-news.ops.worldnet.att.net>, anon@anon.org (anon) writes:
>If the GNAT compiler follows the RM on "accessibility" rules.  Then it
>will force you to use the "Unchecked_Access" attribute for any non-local 
>pointer trying to point to local object".  Solution: If possible move the 
>object to be access to a package global variable (non-local), then you can 
>use Access attribute.
>
>
>Note:
>RM 13.10 (1) => "The attribute Unchecked_Access is used to create access 
>values in an unsafe manner -- the programmer is responsible for 
>preventing 'dangling references.' "
>
>
>
>In <7053ea09-38cd-4e30-9827-a1384bafd190@p31g2000prf.googlegroups.com>, Jerry <lanceboyle@qwest.net> writes:
>>I have a curious report from two members of the development team for
>>PLplot, a popular plotting package for which I have written bindings
>>in Ada. The project is mature enough that the team decided to enable
>>Ada by default when building, so I am concerned about the following e-
>>mail.
>>
>>========== begin e-mail ============
>>
>><First comment from team member>
>>
>>This latest change to the Ada bindings causes a build error for me
>>with gnat 4.2.3 on Ubuntu.
>>
>>plplot.adb:2751:37: non-local pointer cannot point to local object
>>The offending line is
>>    PL_Pen_Labels(Index) := Temp_C_String'Unchecked_Access;
>>
>><Response from another team member>
>>
>>This must depend on the version of gnat since I don't see this error
>>for gnat 4.3.1-2 from Debian testing (and I presume Jerry didn't see
>>it for his gnat-4.3 version as well).
>>
>>========= end e-mail ==============
>>
>>I (Jerry) in fact did not see a problem on my OS X 4.3 compiler.
>>
>>I could supply more details of the code and might even try to write a
>>small program but testing on someone else's machine would be a bit
>>tedious. BUT--this error makes no sense to me--I would expect to (and
>>_do_) see this error if the line in question is
>>
>>    PL_Pen_Labels(Index) := Temp_C_String'Access;
>>
>>The whole purpose of using Unchecked_Access is to make this error go
>>away. It this a known problem on 4.2.3 Unbutu? Is it a compiler error?
>>Why does it work as expected on my 4.3 OS X, on 4.3.1-2 Debian
>>testing, but not 4.2.3 Ubuntu?
>>
>>Jerry
>




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

* Re: GNAT 4.2.3 Ubuntu reports weird compile error wrt Unchecked_Access
  2008-08-17  5:59 ` anon
  2008-08-17 19:47   ` anon
@ 2008-08-17 20:58   ` Jerry
  1 sibling, 0 replies; 10+ messages in thread
From: Jerry @ 2008-08-17 20:58 UTC (permalink / raw)


Thank you for your comments, but they don't exactly apply to my
question.

The code snippet that I gave, though brief, shows the use of
'Unchecked_Access. I used it precisely to overcome the accessibility
rules ("Access-Type Lifetime Rule" in the terminology of Cohen, "Ada
as a Second Langugage").

As I understand it, the compiler should not have issued the error that
it did, and in fact on two of the compilers mentioned in my original
post, it did not issue the error. The error should only be issued, in
this case, when 'Access is used, and in fact, it is issued.

The compiler in question seems to have issued a spurious error
message.

Jerry

On Aug 16, 10:59 pm, a...@anon.org (anon) wrote:
> If the GNAT compiler follows the RM on "accessibility" rules.  Then it
> will force you to use the "Unchecked_Access" attribute for any non-local
> pointer trying to point to local object".  Solution: If possible move the
> object to be access to a package global variable (non-local), then you can
> use Access attribute.
>
> Note:
> RM 13.10 (1) => "The attribute Unchecked_Access is used to create access
> values in an unsafe manner -- the programmer is responsible for
> preventing 'dangling references.' "
>
> In <7053ea09-38cd-4e30-9827-a1384bafd...@p31g2000prf.googlegroups.com>, Jerry <lancebo...@qwest.net> writes:
>
> >I have a curious report from two members of the development team for
> >PLplot, a popular plotting package for which I have written bindings
> >in Ada. The project is mature enough that the team decided to enable
> >Ada by default when building, so I am concerned about the following e-
> >mail.
>
> >========== begin e-mail ============
>
> ><First comment from team member>
>
> >This latest change to the Ada bindings causes a build error for me
> >with gnat 4.2.3 on Ubuntu.
>
> >plplot.adb:2751:37: non-local pointer cannot point to local object
> >The offending line is
> >    PL_Pen_Labels(Index) := Temp_C_String'Unchecked_Access;
>
> ><Response from another team member>
>
> >This must depend on the version of gnat since I don't see this error
> >for gnat 4.3.1-2 from Debian testing (and I presume Jerry didn't see
> >it for his gnat-4.3 version as well).
>
> >========= end e-mail ==============
>
> >I (Jerry) in fact did not see a problem on my OS X 4.3 compiler.
>
> >I could supply more details of the code and might even try to write a
> >small program but testing on someone else's machine would be a bit
> >tedious. BUT--this error makes no sense to me--I would expect to (and
> >_do_) see this error if the line in question is
>
> >    PL_Pen_Labels(Index) := Temp_C_String'Access;
>
> >The whole purpose of using Unchecked_Access is to make this error go
> >away. It this a known problem on 4.2.3 Unbutu? Is it a compiler error?
> >Why does it work as expected on my 4.3 OS X, on 4.3.1-2 Debian
> >testing, but not 4.2.3 Ubuntu?
>
> >Jerry




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

* Re: GNAT 4.2.3 Ubuntu reports weird compile error wrt Unchecked_Access
  2008-08-17 17:14     ` Simon Wright
@ 2008-08-17 21:05       ` Jerry
  0 siblings, 0 replies; 10+ messages in thread
From: Jerry @ 2008-08-17 21:05 UTC (permalink / raw)


On Aug 17, 10:14 am, Simon Wright <simon.j.wri...@mac.com> wrote:
> Jerry <lancebo...@qwest.net> writes:
> > On Aug 16, 3:26 am, Ludovic Brenta <ludo...@ludovic-brenta.org> wrote:
> >> Without more context I cannot tell for sure but I believe this is a
> >> compiler error in the sense that gnat-4.2 does not implement all the
> >> new (and more permissive) rules in Ada 2005 regarding anonymous access
> >> types. gnat-3.2 implements these rules.
>
> >> BTW, I've mentioned already that Ubuntu 8.04 has broken support for
> >> Ada. Better stick to Debian.
>
> >> --
> >> Ludovic Brenta.
>
> > I can quickly get in over my head here and I'm not very familiar with
> > anonymous access types, but isn't 'Unchecked_Access a part of Ada 95
> > if not 83?
>
> Not 83, I think.
>
> The thing is, 'Unchecked_Access may well be allowed in more places in
> '05 than it was in '95; and compilers don't always get this sort of
> thing right first time.
>
> GNAT has 'Unrestricted_Access for places where the rules (or the
> compiler) don't allow 'Unhchecked_Access.

Thanks, Simon.

I believe that this particular use of 'Unchecked_Access was allowed in
Ada 95 and one would think that it would continue to work in Ada 2005,
separate from whether any new usages in Ada 2005 work the first time.
And the compiler in question is a 4.2.3 which I _think_ is not Ada
2005, but I could be mistaken. Furthermore, the two compilers
mentioned in the original post which _do_ behave correctly are both
4.3 which _are_ (mostly, anyway, I think) Ada 2005.

Jerry



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

* Re: GNAT 4.2.3 Ubuntu reports weird compile error wrt Unchecked_Access
  2008-08-17 19:47   ` anon
@ 2008-08-17 21:14     ` Jerry
  0 siblings, 0 replies; 10+ messages in thread
From: Jerry @ 2008-08-17 21:14 UTC (permalink / raw)


On Aug 17, 12:47 pm, a...@anon.org (anon) wrote:
> Addition:
>
> The problem is that local data is stored on the primary stack and if an error
> is encounter the exception handlers could remove the local data off the stack,
> creating a 'dangling references.'. Which would makes the pointer (Access
> variable) invalid or unsafe.
>
> So, you must use the "Unchecked_Access" for local data and the programmer
> is responsible for catching any exceptions or other conditions that might
> cause a 'dangling reference.'
>
> Also, because of the specs refering to "Access" and "Unchecked_Access"
> in both Ada_95 and Ada_2005 is basically unchanged you can use
> "Unchecked_Access" instead of "Access" but be warned you must insure
> the code is safe.
>
> And any GNAT that does not support this type of safety should be concerned
> as corrupt and unusable.
>
> PS.  As for Ada-83, the answer is no!  "Unchecked_Access" was added
> during the creation of Ada-95.
>
> In <37Ppk.5180$Mh5.1...@bgtnsc04-news.ops.worldnet.att.net>, a...@anon.org (anon) writes:
>

Thanks for clarifying the availability of 'Unchecked_Access across
language versions.

I have a fair grasp of the accessibility rules for access variables
(although I struggle with it sometimes). However, my original post was
not a question of how to use them per se, but about an apparent
compiler error on a particular version of GNAT on Ubuntu.

FWIW, I moved the declaration of Temp_C_String to the same place where
its type is declared and am now able to use 'Access, as in
Temp_C_String'Access. The developer who originally reported the
problem has responded to me that this has allowed the compilation to
progress normally. Given that, I probably won't pursue this too much
farther, but nevertheless, there might be some interest by others in
discovering if this possible compiler mistake is important enough to
chase down and fix.

Jerry



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

end of thread, other threads:[~2008-08-17 21:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-15 20:26 GNAT 4.2.3 Ubuntu reports weird compile error wrt Unchecked_Access Jerry
2008-08-16 10:26 ` Ludovic Brenta
2008-08-16 10:35   ` Ludovic Brenta
2008-08-17  0:03   ` Jerry
2008-08-17 17:14     ` Simon Wright
2008-08-17 21:05       ` Jerry
2008-08-17  5:59 ` anon
2008-08-17 19:47   ` anon
2008-08-17 21:14     ` Jerry
2008-08-17 20:58   ` Jerry

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