All of lore.kernel.org
 help / color / mirror / Atom feed
* [parisc-linux] Looking at vfprintf.c and alloca.
@ 2006-07-18  3:40 Carlos O'Donell
  2006-07-18 15:51 ` [parisc-linux] " Randolph Chung
  2006-07-19  2:36 ` John David Anglin
  0 siblings, 2 replies; 13+ messages in thread
From: Carlos O'Donell @ 2006-07-18  3:40 UTC (permalink / raw)
  To: John David Anglin, Randolph Chung, parisc-linux

I was looking at our tst-printfsz failures in glibc, and I noticed
some very cute code in vfprintf.c. The code uses alloca to create a
specs structure, and then using certain know addresses decides if the
stack grows down or up.

Does this look right? Anyone care to review if this actually works
with a newer GCC on hppa?

   1601     size_t nspecs = 0;
   1602     size_t nspecs_max = 32;     /* A more or less arbitrary
start value.  */
   1603     struct printf_spec *specs
   1604       = alloca (nspecs_max * sizeof (struct printf_spec));

...
   1636     for (f = lead_str_end; *f != L_('\0'); f = specs[nspecs++].next_fmt)
   1637       {
   1638         if (nspecs >= nspecs_max)
   1639           {
   1640             /* Extend the array of format specifiers.  */
   1641             struct printf_spec *old = specs;
   1642
   1643             nspecs_max *= 2;
   1644             specs = alloca (nspecs_max * sizeof (struct printf_spec));
   1645
   1646             if (specs == &old[nspecs])
   1647               /* Stack grows up, OLD was the last thing allocated;
   1648                  extend it.  */
   1649               nspecs_max += nspecs_max / 2;
   1650             else
   1651               {
   1652                 /* Copy the old array's elements to the new space.  */
   1653                 memcpy (specs, old, nspecs * sizeof (struct
printf_spec));
   1654                 if (old == &specs[nspecs])
   1655                   /* Stack grows down, OLD was just below the new
   1656                      SPECS.  We can use that space when the new space
   1657                      runs out.  */
   1658                   nspecs_max += nspecs_max / 2;
   1659               }
   1660           }

I didn't expect alloca's behaviour to be so explicitly defined.

Cheers,
Carlos.
_______________________________________________
parisc-linux mailing list
parisc-linux@lists.parisc-linux.org
http://lists.parisc-linux.org/mailman/listinfo/parisc-linux

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

end of thread, other threads:[~2006-07-20  4:54 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-18  3:40 [parisc-linux] Looking at vfprintf.c and alloca Carlos O'Donell
2006-07-18 15:51 ` [parisc-linux] " Randolph Chung
2006-07-18 16:51   ` Michael S. Zick
2006-07-19  3:22     ` John David Anglin
2006-07-18 19:30   ` Carlos O'Donell
2006-07-18 20:11     ` Michael S. Zick
2006-07-18 20:22     ` Matthew Wilcox
2006-07-18 20:49       ` Carlos O'Donell
2006-07-19  2:48   ` John David Anglin
2006-07-19  3:04     ` Randolph Chung
2006-07-19 15:22       ` Michael S. Zick
2006-07-20  4:54         ` John David Anglin
2006-07-19  2:36 ` John David Anglin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.