GNAT 4.2.3 Ubuntu reports weird compile error wrt Unchecked_Access

This is a discussion on GNAT 4.2.3 Ubuntu reports weird compile error wrt Unchecked_Access within the ADA forums in Programming Languages category; 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 ...

Go Back   Application Development Forum > Programming Languages > ADA

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-15-2008, 04:26 PM
Jerry
Guest
 
Default GNAT 4.2.3 Ubuntu reports weird compile error wrt Unchecked_Access

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
Reply With Quote
  #2  
Old 08-16-2008, 06:26 AM
Ludovic Brenta
Guest
 
Default Re: GNAT 4.2.3 Ubuntu reports weird compile error wrtUnchecked_Access

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.
Reply With Quote
  #3  
Old 08-16-2008, 06:35 AM
Ludovic Brenta
Guest
 
Default Re: GNAT 4.2.3 Ubuntu reports weird compile error wrtUnchecked_Access

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.

Reply With Quote
  #4  
Old 08-16-2008, 08:03 PM
Jerry
Guest
 
Default Re: GNAT 4.2.3 Ubuntu reports weird compile error wrtUnchecked_Access

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

Reply With Quote
  #5  
Old 08-17-2008, 01:59 AM
anon
Guest
 
Default Re: GNAT 4.2.3 Ubuntu reports weird compile error wrt Unchecked_Access

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


Reply With Quote
  #6  
Old 08-17-2008, 01:14 PM
Simon Wright
Guest
 
Default Re: GNAT 4.2.3 Ubuntu reports weird compile error wrt Unchecked_Access

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.
Reply With Quote
  #7  
Old 08-17-2008, 03:47 PM
anon
Guest
 
Default Re: GNAT 4.2.3 Ubuntu reports weird compile error wrt Unchecked_Access

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

>


Reply With Quote
  #8  
Old 08-17-2008, 04:58 PM
Jerry
Guest
 
Default Re: GNAT 4.2.3 Ubuntu reports weird compile error wrtUnchecked_Access

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


Reply With Quote
  #9  
Old 08-17-2008, 05:05 PM
Jerry
Guest
 
Default Re: GNAT 4.2.3 Ubuntu reports weird compile error wrtUnchecked_Access

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
Reply With Quote
  #10  
Old 08-17-2008, 05:14 PM
Jerry
Guest
 
Default Re: GNAT 4.2.3 Ubuntu reports weird compile error wrtUnchecked_Access

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
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 05:14 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.