comp.lang.ada
 help / color / mirror / Atom feed
* gcc-7 breaks unsized C array bindings
@ 2017-08-25  8:03 ytomino
  2017-08-27  7:16 ` Shark8
  2017-08-30 21:27 ` Simon Wright
  0 siblings, 2 replies; 4+ messages in thread
From: ytomino @ 2017-08-25  8:03 UTC (permalink / raw)


Hello.

I'm upgrading my code from gcc-6 to 7, and noticed mysterious Storage_Error in some C bindings.
The cause is array (size_t) for importing unsized C arrays, like below.

C header:

 extern int unsized_C_array[];

Ada binding:

 unsized_C_array : array (Interfaces.C.size_t) of Interfaces.C.int
    with Import, Convention => C, External_Name => "unsized_C_array";

gcc-7 treats this common idiom as a runtime error. Moreover, it reports no message on compile-time. This behavior is very malicious mischief.
(I have already reported it as https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81961 )

Therefore; some bindings are broken now. One way is array (0 .. 0) and pragma Suppress (Index_Check), but I feel it's not smart.
What is better replacement how to rewrite them?

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

* Re: gcc-7 breaks unsized C array bindings
  2017-08-25  8:03 gcc-7 breaks unsized C array bindings ytomino
@ 2017-08-27  7:16 ` Shark8
  2017-08-27  7:57   ` Jeffrey R. Carter
  2017-08-30 21:27 ` Simon Wright
  1 sibling, 1 reply; 4+ messages in thread
From: Shark8 @ 2017-08-27  7:16 UTC (permalink / raw)


On Friday, August 25, 2017 at 2:03:08 AM UTC-6, ytomino wrote:
> 
> Ada binding:
> 
>  unsized_C_array : array (Interfaces.C.size_t) of Interfaces.C.int
>     with Import, Convention => C, External_Name => "unsized_C_array";

This creates an array of exactly 0..size_t'last elements -- where size_t'last is at least Integer'Pred(2**16) -- this is quite obviously /NOT/ what you want, and the source of your Storage_Error (as each unsized_C_array takes up so much space).

If I did more interfacing with C I could point you in the right direction, but I can't so someone else will have to weigh in on what a good solution would be.

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

* Re: gcc-7 breaks unsized C array bindings
  2017-08-27  7:16 ` Shark8
@ 2017-08-27  7:57   ` Jeffrey R. Carter
  0 siblings, 0 replies; 4+ messages in thread
From: Jeffrey R. Carter @ 2017-08-27  7:57 UTC (permalink / raw)


On 08/27/2017 09:16 AM, Shark8 wrote:
> On Friday, August 25, 2017 at 2:03:08 AM UTC-6, ytomino wrote:
>>
>> Ada binding:
>>
>>   unsized_C_array : array (Interfaces.C.size_t) of Interfaces.C.int
>>      with Import, Convention => C, External_Name => "unsized_C_array";
> 
> This creates an array of exactly 0..size_t'last elements -- where size_t'last is at least Integer'Pred(2**16) -- this is quite obviously /NOT/ what you want, and the source of your Storage_Error (as each unsized_C_array takes up so much space).

No, because of Import, it should expect the object to be created by something 
else and should simply make this another name for it. If it is allocating space 
for this object, then that should be a compiler error.

I've done more interfacing with C than I would like, but I've never encountered 
this construct, so I've been reluctant to comment. A lot will depend on how the 
construct is used in the Ada. Is it simply passed to C functions, or are 
components actually accessed by indices?

-- 
Jeff Carter
"No one is to stone anyone until I blow this whistle,
do you understand? Even--and I want to make this
absolutely clear--even if they do say, 'Jehovah.'"
Monty Python's Life of Brian
74


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

* Re: gcc-7 breaks unsized C array bindings
  2017-08-25  8:03 gcc-7 breaks unsized C array bindings ytomino
  2017-08-27  7:16 ` Shark8
@ 2017-08-30 21:27 ` Simon Wright
  1 sibling, 0 replies; 4+ messages in thread
From: Simon Wright @ 2017-08-30 21:27 UTC (permalink / raw)


ytomino <aghia05@gmail.com> writes:

> C header:
>
>  extern int unsized_C_array[];
>
> Ada binding:
>
>  unsized_C_array : array (Interfaces.C.size_t) of Interfaces.C.int
>     with Import, Convention => C, External_Name => "unsized_C_array";
>
> gcc-7 treats this common idiom as a runtime error. Moreover, it
> reports no message on compile-time. This behavior is very malicious
> mischief.  (I have already reported it as
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81961 )

Still present in GCC 8.0.0 (20170820).

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

end of thread, other threads:[~2017-08-30 21:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-25  8:03 gcc-7 breaks unsized C array bindings ytomino
2017-08-27  7:16 ` Shark8
2017-08-27  7:57   ` Jeffrey R. Carter
2017-08-30 21:27 ` Simon Wright

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