diff mbox

[ada] : Fix bootstrap for Ada

Message ID BANLkTikZ9dd_DXPN+=vPE6o-ATnpF_wJ0Q@mail.gmail.com
State New
Headers show

Commit Message

Kai Tietz May 23, 2011, 6:52 p.m. UTC
Hi,

this patch fixes an obvious bootstrap issue caused by trying to assign
a constant pointer to an none-constant.

Comments

Arnaud Charlet May 24, 2011, 9:25 a.m. UTC | #1
> this patch fixes an obvious bootstrap issue caused by trying to assign
> a constant pointer to an none-constant.
> 
> Index: adaint.c
> ===================================================================
> 
> --- adaint.c    (revision 174060)
> +++ adaint.c    (working copy)
> @@ -3367,8 +3367,8 @@
>  char *
>  __gnat_to_canonical_file_list_next (void)
>  {
> -  static char *empty = "";
> -  return empty;
> +  static char empty[1];
> +  return &empty[0];
>  }

I'm confused. The above looks wrong to me: it does not return an empty string,
it returns a pointer to an uninitialized string, which cannot be right (and
should generate a warning :-)

Arno
Jakub Jelinek May 24, 2011, 9:31 a.m. UTC | #2
On Tue, May 24, 2011 at 11:25:20AM +0200, Arnaud Charlet wrote:
> > this patch fixes an obvious bootstrap issue caused by trying to assign
> > a constant pointer to an none-constant.
> > 
> > --- adaint.c    (revision 174060)
> > +++ adaint.c    (working copy)
> > @@ -3367,8 +3367,8 @@
> >  char *
> >  __gnat_to_canonical_file_list_next (void)
> >  {
> > -  static char *empty = "";
> > -  return empty;
> > +  static char empty[1];
> > +  return &empty[0];
> >  }
> 
> I'm confused. The above looks wrong to me: it does not return an empty string,
> it returns a pointer to an uninitialized string, which cannot be right (and
> should generate a warning :-)

No, static vars are implicitly zero initialized when not explicitly
initialized.

	Jakub
Arnaud Charlet May 24, 2011, 9:40 a.m. UTC | #3
> > I'm confused. The above looks wrong to me: it does not return an empty
> > string,
> > it returns a pointer to an uninitialized string, which cannot be right
> > (and
> > should generate a warning :-)
> 
> No, static vars are implicitly zero initialized when not explicitly
> initialized.

Hmm I see. Still, the above code is not easy to read IMO.

I'd suggest instead the following which is easier to read and understand:

__gnat_to_canonical_file_list_next (void)
{
  static char empty[] = "";
  return empty;
}

That's actually a change I was about to commit since we've done it recently
at AdaCore, so OK with the above variant.

Arno
Kai Tietz May 25, 2011, 12:03 p.m. UTC | #4
2011/5/24 Arnaud Charlet <charlet@adacore.com>:
>> > I'm confused. The above looks wrong to me: it does not return an empty
>> > string,
>> > it returns a pointer to an uninitialized string, which cannot be right
>> > (and
>> > should generate a warning :-)
>>
>> No, static vars are implicitly zero initialized when not explicitly
>> initialized.
>
> Hmm I see. Still, the above code is not easy to read IMO.
>
> I'd suggest instead the following which is easier to read and understand:
>
> __gnat_to_canonical_file_list_next (void)
> {
>  static char empty[] = "";
>  return empty;
> }
>
> That's actually a change I was about to commit since we've done it recently
> at AdaCore, so OK with the above variant.
>
> Arno

Ok applied patch as you suggested at revision 174185. Not sure that
sure if this is more readable, but anyway.

Regards,
Kai
diff mbox

Patch

Index: adaint.c
===================================================================
--- adaint.c    (revision 174060)
+++ adaint.c    (working copy)
@@ -3367,8 +3367,8 @@ 
 char *
 __gnat_to_canonical_file_list_next (void)
 {
-  static char *empty = "";
-  return empty;
+  static char empty[1];
+  return &empty[0];
 }

 void