[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[commits] r1514 - in /fsf/trunk/libc: ChangeLog stdio-common/printf_fp.c stdio-common/vfscanf.c



Author: eglibc
Date: Tue Feb 20 00:01:34 2007
New Revision: 1514

Log:
Import glibc-mainline for 2007-02-20

Modified:
    fsf/trunk/libc/ChangeLog
    fsf/trunk/libc/stdio-common/printf_fp.c
    fsf/trunk/libc/stdio-common/vfscanf.c

Modified: fsf/trunk/libc/ChangeLog
==============================================================================
--- fsf/trunk/libc/ChangeLog (original)
+++ fsf/trunk/libc/ChangeLog Tue Feb 20 00:01:34 2007
@@ -1,3 +1,10 @@
+2007-02-19  Ulrich Drepper  <drepper@xxxxxxxxxx>
+
+	* stdio-common/printf_fp.c (___printf_fp): Cleanups and minor
+	optimization.
+
+	* stdio-common/vfscanf.c: Small cleanups throughout.
+
 2007-02-18  Ulrich Drepper  <drepper@xxxxxxxxxx>
 
 	[BZ #3325]

Modified: fsf/trunk/libc/stdio-common/printf_fp.c
==============================================================================
--- fsf/trunk/libc/stdio-common/printf_fp.c (original)
+++ fsf/trunk/libc/stdio-common/printf_fp.c Tue Feb 20 00:01:34 2007
@@ -1,6 +1,6 @@
 /* Floating point output for `printf'.
-   Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2006
-   Free Software Foundation, Inc.
+   Copyright (C) 1995-2003, 2006, 2007 Free Software Foundation, Inc.
+
    This file is part of the GNU C Library.
    Written by Ulrich Drepper <drepper@xxxxxxxxxxxxxx>, 1995.
 
@@ -811,12 +811,14 @@
     int chars_needed;
     int expscale;
     int intdig_max, intdig_no = 0;
-    int fracdig_min, fracdig_max, fracdig_no = 0;
+    int fracdig_min;
+    int fracdig_max;
     int dig_max;
     int significant;
     int ngroups = 0;
-
-    if (_tolower (info->spec) == 'e')
+    char spec = _tolower (info->spec);
+
+    if (spec == 'e')
       {
 	type = info->spec;
 	intdig_max = 1;
@@ -826,7 +828,7 @@
 	dig_max = INT_MAX;		/* Unlimited.  */
 	significant = 1;		/* Does not matter here.  */
       }
-    else if (_tolower (info->spec) == 'f')
+    else if (spec == 'f')
       {
 	type = 'f';
 	fracdig_min = fracdig_max = info->prec < 0 ? 6 : info->prec;
@@ -887,7 +889,7 @@
        other output.  If the amount of memory we have to allocate is too
        large use `malloc' instead of `alloca'.  */
     buffer_malloced = ! __libc_use_alloca (chars_needed * 2 * sizeof (wchar_t));
-    if (buffer_malloced)
+    if (__builtin_expect (buffer_malloced, 0))
       {
 	wbuffer = (wchar_t *) malloc ((2 + chars_needed) * sizeof (wchar_t));
 	if (wbuffer == NULL)
@@ -923,6 +925,7 @@
       }
 
     /* Generate the needed number of fractional digits.	 */
+    int fracdig_no = 0;
     while (fracdig_no < fracdig_min
 	   || (fracdig_no < fracdig_max && (fracsize > 1 || frac[0] != 0)))
       {
@@ -972,7 +975,7 @@
 	    /* Process fractional digits.  Terminate if not rounded or
 	       radix character is reached.  */
 	    while (*--wtp != decimalwc && *wtp == L'9')
-	      *wtp = '0';
+	      *wtp = L'0';
 	    if (*wtp != decimalwc)
 	      /* Round up.  */
 	      (*wtp)++;
@@ -1120,15 +1123,14 @@
 	  else
 	    thousands_sep_len = strlen (thousands_sep);
 
-	  if (buffer_malloced)
+	  if (__builtin_expect (buffer_malloced, 0))
 	    {
 	      buffer = (char *) malloc (2 + chars_needed + decimal_len
 					+ ngroups * thousands_sep_len);
 	      if (buffer == NULL)
 		{
 		  /* Signal an error to the caller.  */
-		  if (buffer_malloced)
-		    free (wbuffer);
+		  free (wbuffer);
 		  return -1;
 		}
 	    }
@@ -1162,7 +1164,7 @@
       PRINT (tmpptr, wstartp, wide ? wcp - wstartp : cp - tmpptr);
 
       /* Free the memory if necessary.  */
-      if (buffer_malloced)
+      if (__builtin_expect (buffer_malloced, 0))
 	{
 	  free (buffer);
 	  free (wbuffer);

Modified: fsf/trunk/libc/stdio-common/vfscanf.c
==============================================================================
--- fsf/trunk/libc/stdio-common/vfscanf.c (original)
+++ fsf/trunk/libc/stdio-common/vfscanf.c Tue Feb 20 00:01:34 2007
@@ -52,16 +52,19 @@
 #endif
 
 /* Those are flags in the conversion format. */
-#define LONG		0x001	/* l: long or double */
-#define LONGDBL		0x002	/* L: long long or long double */
-#define SHORT		0x004	/* h: short */
-#define SUPPRESS	0x008	/* *: suppress assignment */
-#define POINTER		0x010	/* weird %p pointer (`fake hex') */
-#define NOSKIP		0x020	/* do not skip blanks */
-#define GROUP		0x080	/* ': group numbers */
-#define MALLOC		0x100	/* a: malloc strings */
-#define CHAR		0x200	/* hh: char */
-#define I18N		0x400	/* I: use locale's digits */
+#define LONG		0x0001	/* l: long or double */
+#define LONGDBL		0x0002	/* L: long long or long double */
+#define SHORT		0x0004	/* h: short */
+#define SUPPRESS	0x0008	/* *: suppress assignment */
+#define POINTER		0x0010	/* weird %p pointer (`fake hex') */
+#define NOSKIP		0x0020	/* do not skip blanks */
+#define NUMBER_SIGNED	0x0040	/* signed integer */
+#define GROUP		0x0080	/* ': group numbers */
+#define MALLOC		0x0100	/* a: malloc strings */
+#define CHAR		0x0200	/* hh: char */
+#define I18N		0x0400	/* I: use locale's digits */
+#define HEXA_FLOAT	0x0800	/* hexadecimal float */
+#define READ_POINTER	0x1000	/* this is a pointer value */
 
 
 #include <locale/localeinfo.h>
@@ -203,9 +206,6 @@
 #define exp_char not_in
   /* Base for integral numbers.  */
   int base;
-  /* Signedness for integral numbers.  */
-  int number_signed;
-#define is_hexa number_signed
   /* Decimal point character.  */
 #ifdef COMPILE_WSCANF
   wint_t decimal;
@@ -237,8 +237,6 @@
      possibly be matched even if in the input stream no character is
      available anymore.  */
   int skip_space = 0;
-  /* Nonzero if we are reading a pointer.  */
-  int read_pointer;
   /* Workspace.  */
   CHAR_T *tw;			/* Temporary pointer.  */
   CHAR_T *wp = NULL;		/* Workspace.  */
@@ -401,9 +399,6 @@
       /* This is the start of the conversion string. */
       flags = 0;
 
-      /* Not yet decided whether we read a pointer or not.  */
-      read_pointer = 0;
-
       /* Initialize state of modifiers.  */
       argpos = 0;
 
@@ -436,7 +431,12 @@
 	    flags |= SUPPRESS;
 	    break;
 	  case L_('\''):
-	    flags |= GROUP;
+#ifdef COMPILE_WSCANF
+	    if (thousands != L'\0')
+#else
+	    if (thousands != NULL)
+#endif
+	      flags |= GROUP;
 	    break;
 	  case L_('I'):
 	    flags |= I18N;
@@ -1076,27 +1076,24 @@
 	case L_('x'):	/* Hexadecimal integer.  */
 	case L_('X'):	/* Ditto.  */
 	  base = 16;
-	  number_signed = 0;
 	  goto number;
 
 	case L_('o'):	/* Octal integer.  */
 	  base = 8;
-	  number_signed = 0;
 	  goto number;
 
 	case L_('u'):	/* Unsigned decimal integer.  */
 	  base = 10;
-	  number_signed = 0;
 	  goto number;
 
 	case L_('d'):	/* Signed decimal integer.  */
 	  base = 10;
-	  number_signed = 1;
+	  flags |= NUMBER_SIGNED;
 	  goto number;
 
 	case L_('i'):	/* Generic number.  */
 	  base = 0;
-	  number_signed = 1;
+	  flags |= NUMBER_SIGNED;
 
 	number:
 	  c = inchar ();
@@ -1361,13 +1358,7 @@
 
 		  if (n < 10)
 		    c = L_('0') + n;
-		  else if ((flags & GROUP)
-#ifdef COMPILE_WSCANF
-			   && thousands != L'\0'
-#else
-			   && thousands != NULL
-#endif
-			   )
+		  else if (flags & GROUP)
 		    {
 		      /* Try matching against the thousands separator.  */
 #ifdef COMPILE_WSCANF
@@ -1433,13 +1424,7 @@
 		  }
 		else if (!ISDIGIT (c) || (int) (c - L_('0')) >= base)
 		  {
-		    if (base == 10 && (flags & GROUP)
-#ifdef COMPILE_WSCANF
-			&& thousands != L'\0'
-#else
-			&& thousands != NULL
-#endif
-			)
+		    if (base == 10 && (flags & GROUP))
 		      {
 			/* Try matching against the thousands separator.  */
 #ifdef COMPILE_WSCANF
@@ -1500,7 +1485,7 @@
 	      /* There was no number.  If we are supposed to read a pointer
 		 we must recognize "(nil)" as well.  */
 	      if (__builtin_expect (wpsize == 0
-				    && read_pointer
+				    && (flags & READ_POINTER)
 				    && (width < 0 || width >= 0)
 				    && c == '('
 				    && TOLOWER (inchar ()) == L_('n')
@@ -1527,14 +1512,14 @@
 	  ADDW (L_('\0'));
 	  if (need_longlong && (flags & LONGDBL))
 	    {
-	      if (number_signed)
+	      if (flags & NUMBER_SIGNED)
 		num.q = __strtoll_internal (wp, &tw, base, flags & GROUP);
 	      else
 		num.uq = __strtoull_internal (wp, &tw, base, flags & GROUP);
 	    }
 	  else
 	    {
-	      if (number_signed)
+	      if (flags & NUMBER_SIGNED)
 		num.l = __strtol_internal (wp, &tw, base, flags & GROUP);
 	      else
 		num.ul = __strtoul_internal (wp, &tw, base, flags & GROUP);
@@ -1544,7 +1529,20 @@
 
 	  if (!(flags & SUPPRESS))
 	    {
-	      if (! number_signed)
+	      if (flags & NUMBER_SIGNED)
+		{
+		  if (need_longlong && (flags & LONGDBL))
+		    *ARG (LONGLONG int *) = num.q;
+		  else if (need_long && (flags & LONG))
+		    *ARG (long int *) = num.l;
+		  else if (flags & SHORT)
+		    *ARG (short int *) = (short int) num.l;
+		  else if (!(flags & CHAR))
+		    *ARG (int *) = (int) num.l;
+		  else
+		    *ARG (signed char *) = (signed char) num.ul;
+		}
+	      else
 		{
 		  if (need_longlong && (flags & LONGDBL))
 		    *ARG (unsigned LONGLONG int *) = num.uq;
@@ -1557,19 +1555,6 @@
 		    *ARG (unsigned int *) = (unsigned int) num.ul;
 		  else
 		    *ARG (unsigned char *) = (unsigned char) num.ul;
-		}
-	      else
-		{
-		  if (need_longlong && (flags & LONGDBL))
-		    *ARG (LONGLONG int *) = num.q;
-		  else if (need_long && (flags & LONG))
-		    *ARG (long int *) = num.l;
-		  else if (flags & SHORT)
-		    *ARG (short int *) = (short int) num.l;
-		  else if (!(flags & CHAR))
-		    *ARG (int *) = (int) num.l;
-		  else
-		    *ARG (signed char *) = (signed char) num.ul;
 		}
 	      ++done;
 	    }
@@ -1689,7 +1674,6 @@
 	      goto scan_float;
 	    }
 
-	  is_hexa = 0;
 	  exp_char = L_('e');
 	  if (width != 0 && c == L_('0'))
 	    {
@@ -1702,7 +1686,7 @@
 		  /* It is a number in hexadecimal format.  */
 		  ADDW (c);
 
-		  is_hexa = 1;
+		  flags |= HEXA_FLOAT;
 		  exp_char = L_('p');
 
 		  /* Grouping is not allowed.  */
@@ -1717,7 +1701,7 @@
 	    {
 	      if (ISDIGIT (c))
 		ADDW (c);
-	      else if (!got_e && is_hexa && ISXDIGIT (c))
+	      else if (!got_e && (flags & HEXA_FLOAT) && ISXDIGIT (c))
 		ADDW (c);
 	      else if (got_e && wp[wpsize - 1] == exp_char
 		       && (c == L_('-') || c == L_('+')))
@@ -1736,8 +1720,7 @@
 		      ADDW (c);
 		      got_dot = 1;
 		    }
-		  else if ((flags & GROUP) != 0 && thousands != L'\0'
-			   && ! got_dot && c == thousands)
+		  else if ((flags & GROUP) != 0 && ! got_dot && c == thousands)
 		    ADDW (c);
 		  else
 		    {
@@ -1781,8 +1764,7 @@
 			 we can compare against it.  */
 		      const char *cmp2p = thousands;
 
-		      if ((flags & GROUP) != 0 && thousands != NULL
-			  && ! got_dot)
+		      if ((flags & GROUP) != 0 && ! got_dot)
 			{
 			  while (cmp2p - thousands < cmpp - decimal
 				 && *cmp2p == decimal[cmp2p - thousands])
@@ -1831,7 +1813,7 @@
 	  if (__builtin_expect ((flags & I18N) != 0, 0)
 	      /* Hexadecimal floats make no sense, fixing localized
 		 digits with ASCII letters.  */
-	      && !is_hexa
+	      && !(flags & HEXA_FLOAT)
 	      /* Minimum requirement.  */
 	      && (wpsize == 0 || got_dot)
 	      && (map = __wctrans ("to_inpunct")) != NULL)
@@ -1884,14 +1866,18 @@
 	      if (match_so_far)
 #endif
 		{
-		  int have_locthousands = true;
+		  bool have_locthousands = (flags & GROUP) != 0;
+
 		  /* Now get the digits and the thousands-sep equivalents.  */
 	          for (int n = 0; n < 11; ++n)
 		    {
 		      if (n < 10)
 			wcdigits[n] = __towctrans (L'0' + n, map);
 		      else if (n == 10)
-			wcdigits[10] = __towctrans (L',', map);
+			{
+			  wcdigits[10] = __towctrans (L',', map);
+			  have_locthousands &= wcdigits[10] != L'\0';
+			}
 
 #ifndef COMPILE_WSCANF
 		      memset (&state, '\0', sizeof (state));
@@ -1902,9 +1888,7 @@
 			{
 			  if (n == 10)
 			    {
-			      if (thousands == NULL || (flags & GROUP) == 0)
-				have_locthousands = false;
-			      else
+			      if (have_locthousands)
 				{
 				  size_t thousands_len = strlen (thousands);
 				  if (thousands_len <= MB_LEN_MAX)
@@ -1993,7 +1977,7 @@
 				      got_dot = 1;
 				    }
 				  else if (n == 10 && (flags & GROUP) != 0
-					   && thousands != NULL && ! got_dot)
+					   && ! got_dot)
 				    {
 				      /* Add all the characters.  */
 				      for (cmpp = thousands; *cmpp != '\0';
@@ -2046,7 +2030,8 @@
 	     in hexadecimal notation and we have read only the `0x'
 	     prefix or no exponent this is an error.  */
 	  if (__builtin_expect (wpsize == 0
-				|| (is_hexa && (wpsize == 2 || ! got_e)), 0))
+				|| ((flags & HEXA_FLOAT)
+				    && (wpsize == 2 || ! got_e)), 0))
 	    conv_error ();
 
 	scan_float:
@@ -2585,8 +2570,7 @@
 	  flags &= ~(SHORT|LONGDBL);
 	  if (need_long)
 	    flags |= LONG;
-	  number_signed = 0;
-	  read_pointer = 1;
+	  flags |= READ_POINTER;
 	  goto number;
 
 	default: