about summary refs log tree commit diff
path: root/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/Makefile5
-rw-r--r--stdlib/grouping.c202
-rw-r--r--stdlib/grouping.h176
-rw-r--r--stdlib/groupingwc.c2
-rw-r--r--stdlib/rpmatch.c10
-rw-r--r--stdlib/strtod.c23
6 files changed, 242 insertions, 176 deletions
diff --git a/stdlib/Makefile b/stdlib/Makefile
index 4d471c911b..7a155031d3 100644
--- a/stdlib/Makefile
+++ b/stdlib/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1991-1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+# Copyright (C) 1991-2002, 2003 Free Software Foundation, Inc.
 # This file is part of the GNU C Library.
 
 # The GNU C Library is free software; you can redistribute it and/or
@@ -49,6 +49,7 @@ routines	:=							      \
 	rpmatch strfmon strfmon_l getsubopt xpg_basename fmtmsg		      \
 	strtoimax strtoumax wcstoimax wcstoumax				      \
 	getcontext setcontext makecontext swapcontext
+aux =	grouping groupingwc
 
 # These routines will be omitted from the libc shared object.
 # Instead the static object files will be included in a special archive
@@ -73,7 +74,7 @@ mpn-headers = longlong.h gmp.h gmp-impl.h gmp-mparam.h asm-syntax.h
 routines := $(strip $(routines) $(mpn-routines))	\
 	    dbl2mpn ldbl2mpn				\
 	    mpn2flt mpn2dbl mpn2ldbl
-aux := fpioconst mp_clz_tab
+aux += fpioconst mp_clz_tab
 distribute := $(distribute) $(mpn-headers) gen-mpn-copy fpioconst.h
 
 generated += isomac isomac.out
diff --git a/stdlib/grouping.c b/stdlib/grouping.c
new file mode 100644
index 0000000000..4e01dc3bdd
--- /dev/null
+++ b/stdlib/grouping.c
@@ -0,0 +1,202 @@
+/* Internal header for proving correct grouping in strings of numbers.
+   Copyright (C) 1995,1996,1997,1998,2000,2003 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <limits.h>
+#include <stddef.h>
+#include <string.h>
+
+#ifndef MAX
+#define MAX(a,b)	({ typeof(a) _a = (a); typeof(b) _b = (b); \
+			   _a > _b ? _a : _b; })
+#endif
+
+#ifdef USE_WIDE_CHAR
+# include <wctype.h>
+# define L_(Ch) L##Ch
+# define UCHAR_TYPE wint_t
+# define STRING_TYPE wchar_t
+#else
+# define L_(Ch) Ch
+# define UCHAR_TYPE unsigned char
+# define STRING_TYPE char
+#endif
+
+#include "grouping.h"
+
+/* Find the maximum prefix of the string between BEGIN and END which
+   satisfies the grouping rules.  It is assumed that at least one digit
+   follows BEGIN directly.  */
+
+const STRING_TYPE *
+#ifdef USE_WIDE_CHAR
+__correctly_grouped_prefixwc (const STRING_TYPE *begin, const STRING_TYPE *end,
+			      wchar_t thousands,
+#else
+__correctly_grouped_prefixmb (const STRING_TYPE *begin, const STRING_TYPE *end,
+			      const char *thousands,
+#endif
+			      const char *grouping)
+{
+#ifndef USE_WIDE_CHAR
+  size_t thousands_len;
+  int cnt;
+#endif
+
+  if (grouping == NULL)
+    return end;
+
+#ifndef USE_WIDE_CHAR
+  thousands_len = strlen (thousands);
+#endif
+
+  while (end > begin)
+    {
+      const STRING_TYPE *cp = end - 1;
+      const char *gp = grouping;
+
+      /* Check first group.  */
+      while (cp >= begin)
+	{
+#ifdef USE_WIDE_CHAR
+	  if (*cp == thousands)
+	    break;
+#else
+	  if (cp[thousands_len - 1] == *thousands)
+	    {
+	      for (cnt = 1; thousands[cnt] != '\0'; ++cnt)
+		if (thousands[cnt] != cp[thousands_len - 1 - cnt])
+		  break;
+	      if (thousands[cnt] == '\0')
+		break;
+	    }
+#endif
+	  --cp;
+	}
+
+      /* We allow the representation to contain no grouping at all even if
+	 the locale specifies we can have grouping.  */
+      if (cp < begin)
+	return end;
+
+      if (end - cp == (int) *gp + 1)
+	{
+	  /* This group matches the specification.  */
+
+	  const STRING_TYPE *new_end;
+
+	  if (cp < begin)
+	    /* There is just one complete group.  We are done.  */
+	    return end;
+
+	  /* CP points to a thousands separator character.  The preceding
+	     remainder of the string from BEGIN to NEW_END is the part we
+	     will consider if there is a grouping error in this trailing
+	     portion from CP to END.  */
+	  new_end = cp - 1;
+
+	  /* Loop while the grouping is correct.  */
+	  while (1)
+	    {
+	      /* Get the next grouping rule.  */
+	      ++gp;
+	      if (*gp == 0)
+		/* If end is reached use last rule.  */
+	        --gp;
+
+	      /* Skip the thousands separator.  */
+	      --cp;
+
+	      if (*gp == CHAR_MAX
+#if CHAR_MIN < 0
+		  || *gp < 0
+#endif
+		  )
+	        {
+	          /* No more thousands separators are allowed to follow.  */
+	          while (cp >= begin)
+		    {
+#ifdef USE_WIDE_CHAR
+		      if (*cp == thousands)
+			break;
+#else
+		      for (cnt = 0; thousands[cnt] != '\0'; ++cnt)
+			if (thousands[cnt] != cp[thousands_len - cnt - 1])
+			  break;
+		      if (thousands[cnt] == '\0')
+			break;
+#endif
+		      --cp;
+		    }
+
+	          if (cp < begin)
+		    /* OK, only digits followed.  */
+		    return end;
+	        }
+	      else
+	        {
+		  /* Check the next group.  */
+	          const STRING_TYPE *group_end = cp;
+
+		  while (cp >= begin)
+		    {
+#ifdef USE_WIDE_CHAR
+		      if (*cp == thousands)
+			break;
+#else
+		      for (cnt = 0; thousands[cnt] != '\0'; ++cnt)
+			if (thousands[cnt] != cp[thousands_len - cnt - 1])
+			  break;
+		      if (thousands[cnt] == '\0')
+			break;
+#endif
+		      --cp;
+		    }
+
+		  if (cp < begin && group_end - cp <= (int) *gp)
+		    /* Final group is correct.  */
+		    return end;
+
+		  if (cp < begin || group_end - cp != (int) *gp)
+		    /* Incorrect group.  Punt.  */
+		    break;
+		}
+	    }
+
+	  /* The trailing portion of the string starting at NEW_END
+	     contains a grouping error.  So we will look for a correctly
+	     grouped number in the preceding portion instead.  */
+	  end = new_end;
+	}
+      else
+	{
+	  /* Even the first group was wrong; determine maximum shift.  */
+	  if (end - cp > (int) *gp + 1)
+	    end = cp + (int) *gp + 1;
+	  else if (cp < begin)
+	    /* This number does not fill the first group, but is correct.  */
+	    return end;
+	  else
+	    /* CP points to a thousands separator character.  */
+	    end = cp;
+	}
+    }
+
+  return MAX (begin, end);
+}
diff --git a/stdlib/grouping.h b/stdlib/grouping.h
index 830304d2f1..c0f8d47fba 100644
--- a/stdlib/grouping.h
+++ b/stdlib/grouping.h
@@ -1,5 +1,5 @@
 /* Internal header for proving correct grouping in strings of numbers.
-   Copyright (C) 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1995,1996,1997,1998,2000,2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
 
@@ -18,169 +18,17 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
-#include <limits.h>
-
-#ifndef MAX
-#define MAX(a,b)	({ typeof(a) _a = (a); typeof(b) _b = (b); \
-			   _a > _b ? _a : _b; })
-#endif
-
 /* Find the maximum prefix of the string between BEGIN and END which
    satisfies the grouping rules.  It is assumed that at least one digit
    follows BEGIN directly.  */
-
-static inline const STRING_TYPE *
-correctly_grouped_prefix (const STRING_TYPE *begin, const STRING_TYPE *end,
-#ifdef USE_WIDE_CHAR
-			  wchar_t thousands,
-#else
-			  const char *thousands,
-#endif
-			  const char *grouping)
-{
-#ifndef USE_WIDE_CHAR
-  size_t thousands_len;
-  int cnt;
-#endif
-
-  if (grouping == NULL)
-    return end;
-
-#ifndef USE_WIDE_CHAR
-  thousands_len = strlen (thousands);
-#endif
-
-  while (end > begin)
-    {
-      const STRING_TYPE *cp = end - 1;
-      const char *gp = grouping;
-
-      /* Check first group.  */
-      while (cp >= begin)
-	{
-#ifdef USE_WIDE_CHAR
-	  if (*cp == thousands)
-	    break;
-#else
-	  if (cp[thousands_len - 1] == *thousands)
-	    {
-	      for (cnt = 1; thousands[cnt] != '\0'; ++cnt)
-		if (thousands[cnt] != cp[thousands_len - 1 - cnt])
-		  break;
-	      if (thousands[cnt] == '\0')
-		break;
-	    }
-#endif
-	  --cp;
-	}
-
-      /* We allow the representation to contain no grouping at all even if
-	 the locale specifies we can have grouping.  */
-      if (cp < begin)
-	return end;
-
-      if (end - cp == (int) *gp + 1)
-	{
-	  /* This group matches the specification.  */
-
-	  const STRING_TYPE *new_end;
-
-	  if (cp < begin)
-	    /* There is just one complete group.  We are done.  */
-	    return end;
-
-	  /* CP points to a thousands separator character.  The preceding
-	     remainder of the string from BEGIN to NEW_END is the part we
-	     will consider if there is a grouping error in this trailing
-	     portion from CP to END.  */
-	  new_end = cp - 1;
-
-	  /* Loop while the grouping is correct.  */
-	  while (1)
-	    {
-	      /* Get the next grouping rule.  */
-	      ++gp;
-	      if (*gp == 0)
-		/* If end is reached use last rule.  */
-	        --gp;
-
-	      /* Skip the thousands separator.  */
-	      --cp;
-
-	      if (*gp == CHAR_MAX
-#if CHAR_MIN < 0
-		  || *gp < 0
-#endif
-		  )
-	        {
-	          /* No more thousands separators are allowed to follow.  */
-	          while (cp >= begin)
-		    {
-#ifdef USE_WIDE_CHAR
-		      if (*cp == thousands)
-			break;
-#else
-		      for (cnt = 0; thousands[cnt] != '\0'; ++cnt)
-			if (thousands[cnt] != cp[thousands_len - cnt - 1])
-			  break;
-		      if (thousands[cnt] == '\0')
-			break;
-#endif
-		      --cp;
-		    }
-
-	          if (cp < begin)
-		    /* OK, only digits followed.  */
-		    return end;
-	        }
-	      else
-	        {
-		  /* Check the next group.  */
-	          const STRING_TYPE *group_end = cp;
-
-		  while (cp >= begin)
-		    {
-#ifdef USE_WIDE_CHAR
-		      if (*cp == thousands)
-			break;
-#else
-		      for (cnt = 0; thousands[cnt] != '\0'; ++cnt)
-			if (thousands[cnt] != cp[thousands_len - cnt - 1])
-			  break;
-		      if (thousands[cnt] == '\0')
-			break;
-#endif
-		      --cp;
-		    }
-
-		  if (cp < begin && group_end - cp <= (int) *gp)
-		    /* Final group is correct.  */
-		    return end;
-
-		  if (cp < begin || group_end - cp != (int) *gp)
-		    /* Incorrect group.  Punt.  */
-		    break;
-		}
-	    }
-
-	  /* The trailing portion of the string starting at NEW_END
-	     contains a grouping error.  So we will look for a correctly
-	     grouped number in the preceding portion instead.  */
-	  end = new_end;
-	}
-      else
-	{
-	  /* Even the first group was wrong; determine maximum shift.  */
-	  if (end - cp > (int) *gp + 1)
-	    end = cp + (int) *gp + 1;
-	  else if (cp < begin)
-	    /* This number does not fill the first group, but is correct.  */
-	    return end;
-	  else
-	    /* CP points to a thousands separator character.  */
-	    end = cp;
-	}
-    }
-
-  return MAX (begin, end);
-}
+extern const wchar_t *__correctly_grouped_prefixwc (const wchar_t *begin,
+						    const wchar_t *end,
+						    wchar_t thousands,
+						    const char *grouping)
+     attribute_hidden;
+
+extern const char *__correctly_grouped_prefixmb (const char *begin,
+						 const char *end,
+						 const char *thousands,
+						 const char *grouping)
+     attribute_hidden;
diff --git a/stdlib/groupingwc.c b/stdlib/groupingwc.c
new file mode 100644
index 0000000000..cd9675ee58
--- /dev/null
+++ b/stdlib/groupingwc.c
@@ -0,0 +1,2 @@
+#define USE_WIDE_CHAR	1
+#include "grouping.c"
diff --git a/stdlib/rpmatch.c b/stdlib/rpmatch.c
index f3cc520f8b..7714c2f497 100644
--- a/stdlib/rpmatch.c
+++ b/stdlib/rpmatch.c
@@ -1,7 +1,7 @@
 /* Determine whether string value is affirmation or negative response
    according to current locale's data.
    This file is part of the GNU C Library.
-   Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1996, 1997, 2000, 2003 Free Software Foundation, Inc.
 
    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -29,11 +29,11 @@ rpmatch (response)
 {
   /* Match against one of the response patterns, compiling the pattern
      first if necessary.  */
-  auto inline int try (const int tag, const int match, const int nomatch,
-		       const char **lastp, regex_t *re);
+  auto int try (const int tag, const int match, const int nomatch,
+		const char **lastp, regex_t *re);
 
-  inline int try (const int tag, const int match, const int nomatch,
-		  const char **lastp, regex_t *re)
+  int try (const int tag, const int match, const int nomatch,
+	   const char **lastp, regex_t *re)
     {
       const char *pattern = nl_langinfo (tag);
       if (pattern != *lastp)
diff --git a/stdlib/strtod.c b/stdlib/strtod.c
index 8d773ecb3d..63d7a4d5bb 100644
--- a/stdlib/strtod.c
+++ b/stdlib/strtod.c
@@ -207,7 +207,7 @@ static const mp_limb_t _tens_in_limb[MAX_DIG_PER_LIMB + 1] =
 
 /* Return a floating point number of the needed type according to the given
    multi-precision number after possible rounding.  */
-static inline FLOAT
+static FLOAT
 round_and_return (mp_limb_t *retval, int exponent, int negative,
 		  mp_limb_t round_limb, mp_size_t round_bit, int more_bits)
 {
@@ -302,7 +302,7 @@ round_and_return (mp_limb_t *retval, int exponent, int negative,
    character od the string that is not part of the integer as the function
    value.  If the EXPONENT is small enough to be taken as an additional
    factor for the resulting number (see code) multiply by it.  */
-static inline const STRING_TYPE *
+static const STRING_TYPE *
 str_to_mpn (const STRING_TYPE *str, int digcnt, mp_limb_t *n, mp_size_t *nsize,
 	    int *exponent
 #ifndef USE_WIDE_CHAR
@@ -401,10 +401,11 @@ str_to_mpn (const STRING_TYPE *str, int digcnt, mp_limb_t *n, mp_size_t *nsize,
    Tege doesn't like this function so I have to write it here myself. :)
    --drepper */
 static inline void
+__attribute ((always_inline))
 __mpn_lshift_1 (mp_limb_t *ptr, mp_size_t size, unsigned int count,
 		mp_limb_t limb)
 {
-  if (count == BITS_PER_MP_LIMB)
+  if (__builtin_constant_p (count) && count == BITS_PER_MP_LIMB)
     {
       /* Optimize the case of shifting by exactly a word:
 	 just copy words, with no actual bit-shifting.  */
@@ -692,7 +693,13 @@ INTERNAL (STRTOF) (nptr, endptr, group LOCALE_PARAM)
 			 || (CHAR_TYPE) TOLOWER (c) != L_('p')))
       && (base != 16 && (CHAR_TYPE) TOLOWER (c) != L_('e')))
     {
-      tp = correctly_grouped_prefix (start_of_digits, cp, thousands, grouping);
+#ifdef USE_WIDE_CHAR
+      tp = __correctly_grouped_prefixwc (start_of_digits, cp, thousands,
+					 grouping);
+#else
+      tp = __correctly_grouped_prefixmb (start_of_digits, cp, thousands,
+					 grouping);
+#endif
       /* If TP is at the start of the digits, there was no correctly
 	 grouped prefix of the string; so no number found.  */
       RETURN (0.0, tp == start_of_digits ? (base == 16 ? cp - 1 : nptr) : tp);
@@ -733,7 +740,13 @@ INTERNAL (STRTOF) (nptr, endptr, group LOCALE_PARAM)
   if (grouping && dig_no > 0)
     {
       /* Check the grouping of the digits.  */
-      tp = correctly_grouped_prefix (start_of_digits, cp, thousands, grouping);
+#ifdef USE_WIDE_CHAR
+      tp = __correctly_grouped_prefixwc (start_of_digits, cp, thousands,
+					 grouping);
+#else
+      tp = __correctly_grouped_prefixmb (start_of_digits, cp, thousands,
+					 grouping);
+#endif
       if (cp != tp)
         {
 	  /* Less than the entire string was correctly grouped.  */