comp.lang.ada
 help / color / mirror / Atom feed
* Aliased Unchecked_Unions not seen or taken notice of
@ 2018-11-12 17:56 Lucretia
  2018-11-12 18:29 ` Lucretia
  2018-11-12 18:53 ` Per Sandberg
  0 siblings, 2 replies; 8+ messages in thread
From: Lucretia @ 2018-11-12 17:56 UTC (permalink / raw)


Hi,

I'm trying to binding the MPC parser library and have come upon an issue with unchecked_unions and aliased.

The error in my minimal sample is:

test.adb:36:07: prefix of "access" attribute must be aliased

Source:

procedure test is
   type Errors is null record with
     Convention => C;

   type Errors_Ptr is access Errors with
     Convention => C;

   type Values is null record with
     Convention => C;

   type Values_Ptr is access Values;

   type Results (Success : Boolean) is
   record
      case Success is
         when False =>
            Error : Errors_Ptr;

         when True =>
            Output : Values_Ptr;
      end case;
   end record with
     Convention      => C_Pass_By_Copy,
     Unchecked_Union => True;

   type Results_Ptr is access all Results with
     Convention => C;

   procedure B (R : in Results_Ptr) is
   begin
      null;
   end B;

   Result : aliased Results := (Success => False, others => <>);
begin
   B (Result'Access);
end test;


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

* Re: Aliased Unchecked_Unions not seen or taken notice of
  2018-11-12 17:56 Aliased Unchecked_Unions not seen or taken notice of Lucretia
@ 2018-11-12 18:29 ` Lucretia
  2018-11-12 20:13   ` Dmitry A. Kazakov
  2018-11-12 18:53 ` Per Sandberg
  1 sibling, 1 reply; 8+ messages in thread
From: Lucretia @ 2018-11-12 18:29 UTC (permalink / raw)


On Monday, 12 November 2018 17:56:05 UTC, Lucretia  wrote:

>    type Results (Success : Boolean) is
>    record
>       case Success is
>          when False =>
>             Error : Errors_Ptr;
> 
>          when True =>
>             Output : Values_Ptr;
>       end case;
>    end record with
>      Convention      => C_Pass_By_Copy;

This compiles fine. So it seems impossible to use unchecked_union and access types together.

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

* Re: Aliased Unchecked_Unions not seen or taken notice of
  2018-11-12 17:56 Aliased Unchecked_Unions not seen or taken notice of Lucretia
  2018-11-12 18:29 ` Lucretia
@ 2018-11-12 18:53 ` Per Sandberg
  2018-11-12 19:44   ` Lucretia
  1 sibling, 1 reply; 8+ messages in thread
From: Per Sandberg @ 2018-11-12 18:53 UTC (permalink / raw)


You could always do.
   B (Result'Unrestricted_Access);
As a workaround
/P

On 11/12/18 6:56 PM, Lucretia wrote:
>    B (Result'Access);


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

* Re: Aliased Unchecked_Unions not seen or taken notice of
  2018-11-12 18:53 ` Per Sandberg
@ 2018-11-12 19:44   ` Lucretia
  2018-11-13  0:17     ` Randy Brukardt
  0 siblings, 1 reply; 8+ messages in thread
From: Lucretia @ 2018-11-12 19:44 UTC (permalink / raw)


On Monday, 12 November 2018 18:53:02 UTC, Per Sandberg  wrote:
> You could always do.
>    B (Result'Unrestricted_Access);
> As a workaround
> /P
> 
> On 11/12/18 6:56 PM, Lucretia wrote:
> >    B (Result'Access);

Thanks, that works.


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

* Re: Aliased Unchecked_Unions not seen or taken notice of
  2018-11-12 18:29 ` Lucretia
@ 2018-11-12 20:13   ` Dmitry A. Kazakov
  2018-11-12 21:02     ` Lucretia
  0 siblings, 1 reply; 8+ messages in thread
From: Dmitry A. Kazakov @ 2018-11-12 20:13 UTC (permalink / raw)


On 2018-11-12 19:29, Lucretia wrote:
> On Monday, 12 November 2018 17:56:05 UTC, Lucretia  wrote:
> 
>>     type Results (Success : Boolean) is
>>     record
>>        case Success is
>>           when False =>
>>              Error : Errors_Ptr;
>>
>>           when True =>
>>              Output : Values_Ptr;
>>        end case;
>>     end record with
>>       Convention      => C_Pass_By_Copy;
> 
> This compiles fine. So it seems impossible to use unchecked_union and access types together.

What about C_Pass_By_Copy? That looks much inconsistent with access to me.

BTW, why do you want to use unchecked union? In comparable cases I 
rather simply overload imported functions with whatever arguments:

    procedure Foo (X : in out int);
    procedure Foo (X : in out unsigned);

    pragma Import (C, Foo);

Ada is so great that it can fix C faults... (:-))

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


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

* Re: Aliased Unchecked_Unions not seen or taken notice of
  2018-11-12 20:13   ` Dmitry A. Kazakov
@ 2018-11-12 21:02     ` Lucretia
  2018-11-13  0:14       ` Randy Brukardt
  0 siblings, 1 reply; 8+ messages in thread
From: Lucretia @ 2018-11-12 21:02 UTC (permalink / raw)


On Monday, 12 November 2018 20:13:53 UTC, Dmitry A. Kazakov  wrote:
> On 2018-11-12 19:29, Lucretia wrote:
> > On Monday, 12 November 2018 17:56:05 UTC, Lucretia  wrote:
> > 
> >>     type Results (Success : Boolean) is
> >>     record
> >>        case Success is
> >>           when False =>
> >>              Error : Errors_Ptr;
> >>
> >>           when True =>
> >>              Output : Values_Ptr;
> >>        end case;
> >>     end record with
> >>       Convention      => C_Pass_By_Copy;
> > 
> > This compiles fine. So it seems impossible to use unchecked_union and access types together.
> 
> What about C_Pass_By_Copy? That looks much inconsistent with access to me.

I did try removing that too.
 
> BTW, why do you want to use unchecked union? In comparable cases I 
> rather simply overload imported functions with whatever arguments:

Because it's not that simple.

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

* Re: Aliased Unchecked_Unions not seen or taken notice of
  2018-11-12 21:02     ` Lucretia
@ 2018-11-13  0:14       ` Randy Brukardt
  0 siblings, 0 replies; 8+ messages in thread
From: Randy Brukardt @ 2018-11-13  0:14 UTC (permalink / raw)


"Lucretia" <laguest9000@googlemail.com> wrote in message 
news:bed99006-94ac-457c-9461-24d326eb4c60@googlegroups.com...
> On Monday, 12 November 2018 20:13:53 UTC, Dmitry A. Kazakov  wrote:
>> On 2018-11-12 19:29, Lucretia wrote:
>> > On Monday, 12 November 2018 17:56:05 UTC, Lucretia  wrote:
>> >
>> >>     type Results (Success : Boolean) is
>> >>     record
>> >>        case Success is
>> >>           when False =>
>> >>              Error : Errors_Ptr;
>> >>
>> >>           when True =>
>> >>              Output : Values_Ptr;
>> >>        end case;
>> >>     end record with
>> >>       Convention      => C_Pass_By_Copy;
>> >
>> > This compiles fine. So it seems impossible to use unchecked_union and 
>> > access types together.
>>
>> What about C_Pass_By_Copy? That looks much inconsistent with access to 
>> me.
>
> I did try removing that too.
>
>> BTW, why do you want to use unchecked union? In comparable cases I
>> rather simply overload imported functions with whatever arguments:
>
> Because it's not that simple.

Sure, but it's almost always simple enough. We built Claw without using 
Unchecked_Union at all (it didn't exist in Ada 95), and there weren't many 
(if any) cases where the result would have been better had it existed. 
Worse, Unchecked_Union is an easy way to introduce erroneous execution into 
one's program accidentally; at least using Unchecked_Conversion or some 
similar scheme makes that obvious. (Using the "wrong" discriminant is 
erroneous, even though that isn't checked or checkable.)

I'd keep the use of Unchecked_Union *very* limited, mostly to just cases 
where it is a component of some outer type. And even that might be better 
handled with Unchecked_Conversion (for reasons noted above).

                                               Randy.



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

* Re: Aliased Unchecked_Unions not seen or taken notice of
  2018-11-12 19:44   ` Lucretia
@ 2018-11-13  0:17     ` Randy Brukardt
  0 siblings, 0 replies; 8+ messages in thread
From: Randy Brukardt @ 2018-11-13  0:17 UTC (permalink / raw)


"Lucretia" <laguest9000@googlemail.com> wrote in message 
news:093d8491-8ab4-4233-9bfd-7de1cffa70bc@googlegroups.com...
> On Monday, 12 November 2018 18:53:02 UTC, Per Sandberg  wrote:
>> You could always do.
>>    B (Result'Unrestricted_Access);
>> As a workaround
>> /P
>>
>> On 11/12/18 6:56 PM, Lucretia wrote:
>> >    B (Result'Access);
>
> Thanks, that works.

BTW, I'd report a bug to AdaCore, too, as there doesn't seem to be any 
reason for what you wrote to not work. (If there was, the error message 
should explain it, not complain that something explicitly declared as 
aliased isn't aliased -- so there still is a bug to be fixed.)

                                              Randy.




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

end of thread, other threads:[~2018-11-13  0:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-12 17:56 Aliased Unchecked_Unions not seen or taken notice of Lucretia
2018-11-12 18:29 ` Lucretia
2018-11-12 20:13   ` Dmitry A. Kazakov
2018-11-12 21:02     ` Lucretia
2018-11-13  0:14       ` Randy Brukardt
2018-11-12 18:53 ` Per Sandberg
2018-11-12 19:44   ` Lucretia
2018-11-13  0:17     ` Randy Brukardt

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