diff options
author | joseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d> | 2007-09-12 16:26:54 +0000 |
---|---|---|
committer | joseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d> | 2007-09-12 16:26:54 +0000 |
commit | 83584a7af898dd93c48600fe850d150c51b10899 (patch) | |
tree | 0affa8ffee374ab83e40501d8d8967a03569c44d /libc/stdlib | |
parent | 04b4d23592609edcd19fd5a461bbe6d3cc677b5b (diff) |
Merge changes between r2424 and r3467 from /fsf/trunk.
git-svn-id: svn://svn.eglibc.org/trunk@3468 7b3dc134-2b1b-0410-93df-9e9f96275f8d
Diffstat (limited to 'libc/stdlib')
-rw-r--r-- | libc/stdlib/Makefile | 3 | ||||
-rw-r--r-- | libc/stdlib/bits/stdlib-ldbl.h | 4 | ||||
-rw-r--r-- | libc/stdlib/stdlib.h | 145 | ||||
-rw-r--r-- | libc/stdlib/strtod.c | 5 | ||||
-rw-r--r-- | libc/stdlib/strtod_l.c | 11 | ||||
-rw-r--r-- | libc/stdlib/strtol.c | 3 | ||||
-rw-r--r-- | libc/stdlib/strtol_l.c | 3 | ||||
-rw-r--r-- | libc/stdlib/strtold.c | 4 | ||||
-rw-r--r-- | libc/stdlib/strtold_l.c | 10 | ||||
-rw-r--r-- | libc/stdlib/tst-strtod2.c | 2 | ||||
-rw-r--r-- | libc/stdlib/tst-strtod5.c | 88 |
11 files changed, 146 insertions, 132 deletions
diff --git a/libc/stdlib/Makefile b/libc/stdlib/Makefile index e93ffcbc6..68be3f5b7 100644 --- a/libc/stdlib/Makefile +++ b/libc/stdlib/Makefile @@ -75,7 +75,7 @@ tests := tst-strtol tst-strtod testmb testrand testsort testdiv \ tst-limits tst-rand48 bug-strtod tst-setcontext \ test-a64l tst-qsort tst-system testmb2 bug-strtod2 \ tst-atof1 tst-atof2 tst-strtod2 tst-rand48-2 \ - tst-makecontext tst-strtod4 + tst-makecontext tst-strtod4 tst-strtod5 tests-$(OPTION_EGLIBC_LOCALE_CODE) \ += tst-strtod3 include ../Makeconfig @@ -123,6 +123,7 @@ test-canon-ARGS = --test-dir=${common-objpfx}stdlib tst-strtod-ENV = LOCPATH=$(common-objpfx)localedata tst-strtod3-ENV = LOCPATH=$(common-objpfx)localedata tst-strtod4-ENV = LOCPATH=$(common-objpfx)localedata +tst-strtod5-ENV = LOCPATH=$(common-objpfx)localedata testmb2-ENV = LOCPATH=$(common-objpfx)localedata # Run a test on the header files we use. diff --git a/libc/stdlib/bits/stdlib-ldbl.h b/libc/stdlib/bits/stdlib-ldbl.h index b197c5754..d48e1f700 100644 --- a/libc/stdlib/bits/stdlib-ldbl.h +++ b/libc/stdlib/bits/stdlib-ldbl.h @@ -1,5 +1,5 @@ /* -mlong-double-64 compatibility mode for <stdlib.h> functions. - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2007 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 @@ -31,8 +31,6 @@ __END_NAMESPACE_C99 __LDBL_REDIR1_DECL (strtold_l, strtod_l) #endif -__LDBL_REDIR1_DECL (__strtold_internal, __strtod_internal) - #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED # ifdef __USE_MISC __LDBL_REDIR1_DECL (qecvt, ecvt) diff --git a/libc/stdlib/stdlib.h b/libc/stdlib/stdlib.h index aa5f514ca..d405cbf7b 100644 --- a/libc/stdlib/stdlib.h +++ b/libc/stdlib/stdlib.h @@ -273,125 +273,7 @@ extern long double strtold_l (__const char *__restrict __nptr, #endif /* GNU */ -/* The internal entry points for `strtoX' take an extra flag argument - saying whether or not to parse locale-dependent number grouping. */ - -extern double __strtod_internal (__const char *__restrict __nptr, - char **__restrict __endptr, int __group) - __THROW __nonnull ((1)) __wur; -extern float __strtof_internal (__const char *__restrict __nptr, - char **__restrict __endptr, int __group) - __THROW __nonnull ((1)) __wur; -extern long double __strtold_internal (__const char *__restrict __nptr, - char **__restrict __endptr, - int __group) - __THROW __nonnull ((1)) __wur; -#ifndef __strtol_internal_defined -extern long int __strtol_internal (__const char *__restrict __nptr, - char **__restrict __endptr, - int __base, int __group) - __THROW __nonnull ((1)) __wur; -# define __strtol_internal_defined 1 -#endif -#ifndef __strtoul_internal_defined -extern unsigned long int __strtoul_internal (__const char *__restrict __nptr, - char **__restrict __endptr, - int __base, int __group) - __THROW __nonnull ((1)) __wur; -# define __strtoul_internal_defined 1 -#endif -#if defined __GNUC__ || defined __USE_ISOC99 -# ifndef __strtoll_internal_defined -__extension__ -extern long long int __strtoll_internal (__const char *__restrict __nptr, - char **__restrict __endptr, - int __base, int __group) - __THROW __nonnull ((1)) __wur; -# define __strtoll_internal_defined 1 -# endif -# ifndef __strtoull_internal_defined -__extension__ -extern unsigned long long int __strtoull_internal (__const char * - __restrict __nptr, - char **__restrict __endptr, - int __base, int __group) - __THROW __nonnull ((1)) __wur; -# define __strtoull_internal_defined 1 -# endif -#endif /* GCC */ - #ifdef __USE_EXTERN_INLINES -/* Define inline functions which call the internal entry points. */ - -__BEGIN_NAMESPACE_STD -__extern_inline double -__NTH (strtod (__const char *__restrict __nptr, char **__restrict __endptr)) -{ - return __strtod_internal (__nptr, __endptr, 0); -} -__extern_inline long int -__NTH (strtol (__const char *__restrict __nptr, char **__restrict __endptr, - int __base)) -{ - return __strtol_internal (__nptr, __endptr, __base, 0); -} -__extern_inline unsigned long int -__NTH (strtoul (__const char *__restrict __nptr, char **__restrict __endptr, - int __base)) -{ - return __strtoul_internal (__nptr, __endptr, __base, 0); -} -__END_NAMESPACE_STD - -# ifdef __USE_ISOC99 -__BEGIN_NAMESPACE_C99 -__extern_inline float -__NTH (strtof (__const char *__restrict __nptr, char **__restrict __endptr)) -{ - return __strtof_internal (__nptr, __endptr, 0); -} -# ifndef __LDBL_COMPAT -__extern_inline long double -__NTH (strtold (__const char *__restrict __nptr, char **__restrict __endptr)) -{ - return __strtold_internal (__nptr, __endptr, 0); -} -# endif -__END_NAMESPACE_C99 -# endif - -# ifdef __USE_BSD -__extension__ __extern_inline long long int -__NTH (strtoq (__const char *__restrict __nptr, char **__restrict __endptr, - int __base)) -{ - return __strtoll_internal (__nptr, __endptr, __base, 0); -} -__extension__ __extern_inline unsigned long long int -__NTH (strtouq (__const char *__restrict __nptr, char **__restrict __endptr, - int __base)) -{ - return __strtoull_internal (__nptr, __endptr, __base, 0); -} -# endif - -# if defined __USE_MISC || defined __USE_ISOC99 -__BEGIN_NAMESPACE_C99 -__extension__ __extern_inline long long int -__NTH (strtoll (__const char *__restrict __nptr, char **__restrict __endptr, - int __base)) -{ - return __strtoll_internal (__nptr, __endptr, __base, 0); -} -__extension__ __extern_inline unsigned long long int -__NTH (strtoull (__const char * __restrict __nptr, char **__restrict __endptr, - int __base)) -{ - return __strtoull_internal (__nptr, __endptr, __base, 0); -} -__END_NAMESPACE_C99 -# endif - __BEGIN_NAMESPACE_STD __extern_inline double __NTH (atof (__const char *__nptr)) @@ -597,8 +479,11 @@ __END_NAMESPACE_STD __BEGIN_NAMESPACE_STD /* Re-allocate the previously allocated block in PTR, making the new block SIZE bytes long. */ +/* __attribute_malloc__ is not used, because if realloc returns + the same pointer that was passed to it, aliasing needs to be allowed + between objects pointed by the old and new pointers. */ extern void *realloc (void *__ptr, size_t __size) - __THROW __attribute_malloc__ __attribute_warn_unused_result__; + __THROW __attribute_warn_unused_result__; /* Free a block allocated by `malloc', `realloc' or `calloc'. */ extern void free (void *__ptr) __THROW; __END_NAMESPACE_STD @@ -729,6 +614,28 @@ extern int mkstemp64 (char *__template) __nonnull ((1)) __wur; extern char *mkdtemp (char *__template) __THROW __nonnull ((1)) __wur; #endif +#ifdef __USE_GNU +/* Generate a unique temporary file name from TEMPLATE similar to + mkstemp. But allow the caller to pass additional flags which are + used in the open call to create the file.. + + This function is a possible cancellation points and therefore not + marked with __THROW. */ +# ifndef __USE_FILE_OFFSET64 +extern int mkostemp (char *__template, int __flags) __nonnull ((1)) __wur; +# else +# ifdef __REDIRECT +extern int __REDIRECT (mkostemp, (char *__template, int __flags), mkostemp64) + __nonnull ((1)) __wur; +# else +# define mkostemp mkostemp64 +# endif +# endif +# ifdef __USE_LARGEFILE64 +extern int mkostemp64 (char *__template, int __flags) __nonnull ((1)) __wur; +# endif +#endif + __BEGIN_NAMESPACE_STD /* Execute the given line as a shell command. diff --git a/libc/stdlib/strtod.c b/libc/stdlib/strtod.c index d124bcdcd..0921724db 100644 --- a/libc/stdlib/strtod.c +++ b/libc/stdlib/strtod.c @@ -1,6 +1,6 @@ /* Read decimal floating point numbers. This file is part of the GNU C Library. - Copyright (C) 1995-2002, 2003, 2004, 2006 Free Software Foundation, Inc. + Copyright (C) 1995-2002,2003,2004,2006,2007 Free Software Foundation, Inc. Contributed by Ulrich Drepper <drepper@gnu.org>, 1995. The GNU C Library is free software; you can redistribute it and/or @@ -69,6 +69,9 @@ STRTOF (nptr, endptr) { return INTERNAL(STRTOF_L) (nptr, endptr, 0, _NL_CURRENT_LOCALE); } +#if defined _LIBC +libc_hidden_def (STRTOF) +#endif #ifdef LONG_DOUBLE_COMPAT # if LONG_DOUBLE_COMPAT(libc, GLIBC_2_0) diff --git a/libc/stdlib/strtod_l.c b/libc/stdlib/strtod_l.c index 4033e3bef..86b408e1f 100644 --- a/libc/stdlib/strtod_l.c +++ b/libc/stdlib/strtod_l.c @@ -700,7 +700,8 @@ ____STRTOF_INTERNAL (nptr, endptr, group, loc) #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); + RETURN (negative ? -0.0 : 0.0, + tp == start_of_digits ? (base == 16 ? cp - 1 : nptr) : tp); } /* Remember first significant digit and read following characters until the @@ -759,7 +760,7 @@ ____STRTOF_INTERNAL (nptr, endptr, group, loc) if (tp < startp) /* The number is validly grouped, but consists only of zeroes. The whole value is zero. */ - RETURN (0.0, tp); + RETURN (negative ? -0.0 : 0.0, tp); /* Recompute DIG_NO so we won't read more digits than are properly grouped. */ @@ -862,7 +863,7 @@ ____STRTOF_INTERNAL (nptr, endptr, group, loc) { /* Overflow or underflow. */ __set_errno (ERANGE); - result = (exp_negative ? 0.0 : + result = (exp_negative ? (negative ? -0.0 : 0.0) : negative ? -FLOAT_HUGE_VAL : FLOAT_HUGE_VAL); } @@ -1598,6 +1599,10 @@ __STRTOF (nptr, endptr, loc) { return ____STRTOF_INTERNAL (nptr, endptr, 0, loc); } +#if defined _LIBC +libc_hidden_def (__STRTOF) +libc_hidden_ver (__STRTOF, STRTOF) +#endif weak_alias (__STRTOF, STRTOF) #ifdef LONG_DOUBLE_COMPAT diff --git a/libc/stdlib/strtol.c b/libc/stdlib/strtol.c index 02ec19aab..e90c51cc5 100644 --- a/libc/stdlib/strtol.c +++ b/libc/stdlib/strtol.c @@ -1,5 +1,5 @@ /* Convert string representation of a number into an integer value. - Copyright (C) 1991,92,94,95,96,97,98,99,2000,2001,2002,2003,2004 + Copyright (C) 1991,92,94,95,96,97,98,99,2000,2001,2002,2003,2004,2007 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -109,3 +109,4 @@ strtol (nptr, endptr, base) { return INTERNAL (__strtol_l) (nptr, endptr, base, 0, _NL_CURRENT_LOCALE); } +libc_hidden_def (strtol) diff --git a/libc/stdlib/strtol_l.c b/libc/stdlib/strtol_l.c index e02a2747d..ba0aba791 100644 --- a/libc/stdlib/strtol_l.c +++ b/libc/stdlib/strtol_l.c @@ -1,5 +1,5 @@ /* Convert string representing a number to integer value, using given locale. - Copyright (C) 1997, 2002, 2004, 2006 Free Software Foundation, Inc. + Copyright (C) 1997, 2002, 2004, 2006, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -561,4 +561,5 @@ __strtol_l (nptr, endptr, base, loc) { return INTERNAL (__strtol_l) (nptr, endptr, base, 0, loc); } +libc_hidden_def (__strtol_l) weak_alias (__strtol_l, strtol_l) diff --git a/libc/stdlib/strtold.c b/libc/stdlib/strtold.c index 1f56deaa0..da9f92797 100644 --- a/libc/stdlib/strtold.c +++ b/libc/stdlib/strtold.c @@ -1,6 +1,6 @@ /* Read decimal floating point numbers. This file is part of the GNU C Library. - Copyright (C) 1995-2002, 2003, 2004, 2006 Free Software Foundation, Inc. + Copyright (C) 1995-2002,2003,2004,2006,2007 Free Software Foundation, Inc. Contributed by Ulrich Drepper <drepper@gnu.org>, 1995. The GNU C Library is free software; you can redistribute it and/or @@ -33,6 +33,8 @@ long double ____new_wcstold_internal (const wchar_t *, wchar_t **, int); long double __new_wcstold (const wchar_t *, wchar_t **); libc_hidden_proto (____new_strtold_internal) libc_hidden_proto (____new_wcstold_internal) +libc_hidden_proto (__new_strtold) +libc_hidden_proto (__new_wcstold) #else # define NEW(x) x #endif diff --git a/libc/stdlib/strtold_l.c b/libc/stdlib/strtold_l.c index 690a8a92e..2a7770799 100644 --- a/libc/stdlib/strtold_l.c +++ b/libc/stdlib/strtold_l.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc. +/* Copyright (C) 1999, 2002, 2004, 2007 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 @@ -20,6 +20,10 @@ #include <stdlib.h> #include <xlocale.h> +#if defined _LIBC || defined HAVE_WCHAR_H +# include <wchar.h> +#endif + #ifdef USE_WIDE_CHAR # define STRING_TYPE wchar_t # define STRTOLD wcstold_l @@ -55,4 +59,8 @@ __STRTOLD (const STRING_TYPE *nptr, STRING_TYPE **endptr, __locale_t loc) { return INTERNAL (__STRTOD) (nptr, endptr, 0, loc); } +#if defined _LIBC +libc_hidden_def (__STRTOLD) +libc_hidden_ver (__STRTOLD, STRTOLD) +#endif weak_alias (__STRTOLD, STRTOLD) diff --git a/libc/stdlib/tst-strtod2.c b/libc/stdlib/tst-strtod2.c index 30d8d9df6..a7df82ebb 100644 --- a/libc/stdlib/tst-strtod2.c +++ b/libc/stdlib/tst-strtod2.c @@ -32,7 +32,7 @@ do_test (void) } if (ep != tests[i].str + tests[i].offset) { - printf ("test %zu strtod parsed %ju characters, expected %zu\n", + printf ("test %zu strtod parsed %tu characters, expected %zu\n", i, ep - tests[i].str, tests[i].offset); status = 1; } diff --git a/libc/stdlib/tst-strtod5.c b/libc/stdlib/tst-strtod5.c new file mode 100644 index 000000000..337c74698 --- /dev/null +++ b/libc/stdlib/tst-strtod5.c @@ -0,0 +1,88 @@ +#include <locale.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> + +#define NBSP "\xc2\xa0" + +static const struct +{ + const char *in; + int group; + double expected; +} tests[] = + { + { "0", 0, 0.0 }, + { "000", 0, 0.0 }, + { "-0", 0, -0.0 }, + { "-000", 0, -0.0 }, + { "0,", 0, 0.0 }, + { "-0,", 0, -0.0 }, + { "0,0", 0, 0.0 }, + { "-0,0", 0, -0.0 }, + { "0e-10", 0, 0.0 }, + { "-0e-10", 0, -0.0 }, + { "0,e-10", 0, 0.0 }, + { "-0,e-10", 0, -0.0 }, + { "0,0e-10", 0, 0.0 }, + { "-0,0e-10", 0, -0.0 }, + { "0e-1000000", 0, 0.0 }, + { "-0e-1000000", 0, -0.0 }, + { "0,0e-1000000", 0, 0.0 }, + { "-0,0e-1000000", 0, -0.0 }, + { "0", 1, 0.0 }, + { "000", 1, 0.0 }, + { "-0", 1, -0.0 }, + { "-000", 1, -0.0 }, + { "0e-10", 1, 0.0 }, + { "-0e-10", 1, -0.0 }, + { "0e-1000000", 1, 0.0 }, + { "-0e-1000000", 1, -0.0 }, + { "000"NBSP"000"NBSP"000", 1, 0.0 }, + { "-000"NBSP"000"NBSP"000", 1, -0.0 } + }; +#define NTESTS (sizeof (tests) / sizeof (tests[0])) + + +static int +do_test (void) +{ + if (setlocale (LC_ALL, "cs_CZ.UTF-8") == NULL) + { + puts ("could not set locale"); + return 1; + } + + int status = 0; + + for (int i = 0; i < NTESTS; ++i) + { + char *ep; + double r; + + if (tests[i].group) + r = __strtod_internal (tests[i].in, &ep, 1); + else + r = strtod (tests[i].in, &ep); + + if (*ep != '\0') + { + printf ("%d: got rest string \"%s\", expected \"\"\n", i, ep); + status = 1; + } + + if (r != tests[i].expected + || copysign (10.0, r) != copysign (10.0, tests[i].expected)) + { + printf ("%d: got wrong results %g, expected %g\n", + i, r, tests[i].expected); + status = 1; + } + } + + return status; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" |