Ticket #10396: 0006-glibc-Remove-nested-function.patch

File 0006-glibc-Remove-nested-function.patch, 2.6 KB (added by js, 6 years ago)
  • src/system/libroot/posix/glibc/stdio-common/printf_fp.c

    From c782cce310e6bb69485184d1900e14fadfb229cf Mon Sep 17 00:00:00 2001
    From: Jonathan Schleifer <js@webkeks.org>
    Date: Fri, 10 Jan 2014 21:06:42 +0100
    Subject: [PATCH 06/10] glibc: Remove nested function.
    
    Nested functions are a (again, broken) GNU extension which is not
    supported by Clang. It has been replaced by a bunch of gotos and a
    variable that works as a return address.
    ---
     .../libroot/posix/glibc/stdio-common/printf_fp.c   | 34 +++++++++++++++++-----
     1 file changed, 27 insertions(+), 7 deletions(-)
    
    diff --git a/src/system/libroot/posix/glibc/stdio-common/printf_fp.c b/src/system/libroot/posix/glibc/stdio-common/printf_fp.c
    index 4c68c5e..d22c731 100644
    a b __printf_fp (FILE *fp,  
    200200  /* Nonzero if this is output on a wide character stream.  */
    201201  int wide = info->wide;
    202202
    203   auto wchar_t hack_digit (void);
     203  wchar_t hack_digit_ret;
     204  int hack_digit_callee;
    204205
    205   wchar_t hack_digit (void)
     206  while (0)
    206207    {
    207208      mp_limb_t hi;
    208209
     210hack_digit:
    209211      if (expsign != 0 && type == 'f' && exponent-- > 0)
    210212    hi = 0;
    211213      else if (scalesize == 0)
    __printf_fp (FILE *fp,  
    232234          /* We're not prepared for an mpn variable with zero
    233235             limbs.  */
    234236          fracsize = 1;
    235           return L'0' + hi;
     237          hack_digit_ret = L'0' + hi;
     238          goto hack_digit_end;
    236239        }
    237240        }
    238241
    __printf_fp (FILE *fp,  
    241244        frac[fracsize++] = cy;
    242245    }
    243246
    244       return L'0' + hi;
     247      hack_digit_ret = L'0' + hi;
     248hack_digit_end:
     249      switch (hack_digit_callee)
     250        {
     251      case 1: goto hack_digit_callee1;
     252      case 2: goto hack_digit_callee2;
     253      case 3: goto hack_digit_callee3;
     254      default: abort();
     255    }
    245256    }
    246257
    247258
    __printf_fp (FILE *fp,  
    885896    while (intdig_no < intdig_max)
    886897      {
    887898        ++intdig_no;
    888         *wcp++ = hack_digit ();
     899        hack_digit_callee = 1;
     900        goto hack_digit;
     901hack_digit_callee1:
     902        *wcp++ = hack_digit_ret;
    889903      }
    890904    significant = 1;
    891905    if (info->alt
    __printf_fp (FILE *fp,  
    907921       || (fracdig_no < fracdig_max && (fracsize > 1 || frac[0] != 0)))
    908922      {
    909923    ++fracdig_no;
    910     *wcp = hack_digit ();
     924    hack_digit_callee = 2;
     925    goto hack_digit;
     926hack_digit_callee2:
     927    *wcp++ = hack_digit_ret;
    911928    if (*wcp != L'0')
    912929      significant = 1;
    913930    else if (significant == 0)
    __printf_fp (FILE *fp,  
    920937      }
    921938
    922939    /* Do rounding.  */
    923     digit = hack_digit ();
     940    hack_digit_callee = 3;
     941    goto hack_digit;
     942hack_digit_callee3:
     943    digit = hack_digit_ret;
    924944    if (digit > L'4')
    925945      {
    926946    wchar_t *wtp = wcp;