This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
The attached patch fixes libstdc++/5611 for mainline GCC. It comes in two parts: 1) Libiberty needs support for strtoll() and strtoull(). Supplied by the two .c files and the libiberty patch. 2) libstdc++-v3 may need to link against libiberty to get strtoll and strtoull when the native C library doesn't provide them. The attached libstdc++-v3 patch does this. Tested on FreeBSD 3.4 (no native strtoll/strtoull) and Linux 2.4.17/glibc 2.24 (has native strtoll/strtoull). I also have patches against the GCC 3.0 branch, if desired. On FreeBSD 3.4, libstdc++/5611 is a regression from GCC 2.95.x (does that still matter?). Doug Gregor gregod@cs.rpi.edu
/*
* Copyright (c) 1990 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. [rescinded 22 July 1999]
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include <errno.h>
#ifdef NEED_DECLARATION_ERRNO
extern int errno;
#endif
#if 0
#include <stdlib.h>
#endif
#include "ansidecl.h"
#include "safe-ctype.h"
#ifndef ULONG_LONG_MAX
#define ULONG_LONG_MAX ((unsigned long long)(~0LL))
#endif
/*
* Convert a string to an unsigned long integer.
*
* Ignores `locale' stuff. Assumes that the upper and lower case
* alphabets and digits are each contiguous.
*/
unsigned long long
strtoull(nptr, endptr, base)
const char *nptr;
char **endptr;
register int base;
{
register const char *s = nptr;
register unsigned long long acc;
register int c;
register unsigned long long cutoff;
register int neg = 0, any, cutlim;
/*
* See strtoll for comments as to the logic used.
*/
do {
c = *s++;
} while (ISSPACE(c));
if (c == '-') {
neg = 1;
c = *s++;
} else if (c == '+')
c = *s++;
if ((base == 0 || base == 16) &&
c == '0' && (*s == 'x' || *s == 'X')) {
c = s[1];
s += 2;
base = 16;
}
if (base == 0)
base = c == '0' ? 8 : 10;
cutoff = (unsigned long long)ULONG_LONG_MAX / (unsigned long long)base;
cutlim = (unsigned long long)ULONG_LONG_MAX % (unsigned long long)base;
for (acc = 0, any = 0;; c = *s++) {
if (ISDIGIT(c))
c -= '0';
else if (ISALPHA(c))
c -= ISUPPER(c) ? 'A' - 10 : 'a' - 10;
else
break;
if (c >= base)
break;
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
any = -1;
else {
any = 1;
acc *= base;
acc += c;
}
}
if (any < 0) {
acc = ULONG_LONG_MAX;
errno = ERANGE;
} else if (neg)
acc = -acc;
if (endptr != 0)
*endptr = (char *) (any ? s - 1 : nptr);
return (acc);
}
Attachment:
strtoll.c
Description: Text document
? strtoll.c
? strtoull.c
Index: Makefile.in
===================================================================
RCS file: /cvsroot/gcc/gcc/libiberty/Makefile.in,v
retrieving revision 1.73
diff -c -p -r1.73 Makefile.in
*** Makefile.in 22 Jan 2002 20:03:29 -0000 1.73
--- Makefile.in 19 Feb 2002 16:05:43 -0000
*************** CFILES = alloca.c argv.c asprintf.c atex
*** 137,143 ****
safe-ctype.c setenv.c sigsetmask.c sort.c spaces.c \
splay-tree.c strcasecmp.c strchr.c strdup.c strerror.c \
strncasecmp.c strncmp.c strrchr.c strsignal.c strstr.c \
! strtod.c strtol.c strtoul.c \
ternary.c tmpnam.c \
vasprintf.c vfork.c vfprintf.c vprintf.c vsprintf.c \
waitpid.c \
--- 137,143 ----
safe-ctype.c setenv.c sigsetmask.c sort.c spaces.c \
splay-tree.c strcasecmp.c strchr.c strdup.c strerror.c \
strncasecmp.c strncmp.c strrchr.c strsignal.c strstr.c \
! strtod.c strtol.c strtoll.c strtoul.c strtoull.c \
ternary.c tmpnam.c \
vasprintf.c vfork.c vfprintf.c vprintf.c vsprintf.c \
waitpid.c \
*************** CONFIGURED_OFILES = asprintf.o atexit.o
*** 176,182 ****
random.o rename.o rindex.o \
setenv.o sigsetmask.o strcasecmp.o strchr.o strdup.o \
strncasecmp.o strncmp.o strrchr.o strstr.o strtod.o strtol.o \
! strtoul.o \
tmpnam.o \
vasprintf.o vfork.o vfprintf.o vprintf.o vsprintf.o \
waitpid.o
--- 176,182 ----
random.o rename.o rindex.o \
setenv.o sigsetmask.o strcasecmp.o strchr.o strdup.o \
strncasecmp.o strncmp.o strrchr.o strstr.o strtod.o strtol.o \
! strtoul.o strtoll.o strtoull.o \
tmpnam.o \
vasprintf.o vfork.o vfprintf.o vprintf.o vsprintf.o \
waitpid.o
*************** install_to_tooldir: all
*** 252,258 ****
# to include there. Do not add anything LGPL to this list; libstdc++
# can't use anything encumbering.
NEEDED = atexit calloc memchr memcmp memcpy memmove memset rename strchr \
! strerror strncmp strrchr strstr strtol strtoul tmpnam vfprintf vprintf \
vfork waitpid bcmp bcopy bzero
needed-list: Makefile
rm -f needed-list; touch needed-list; \
--- 252,259 ----
# to include there. Do not add anything LGPL to this list; libstdc++
# can't use anything encumbering.
NEEDED = atexit calloc memchr memcmp memcpy memmove memset rename strchr \
! strerror strncmp strrchr strstr strtol strtoul strtoll strtoull \
! stmpnam vfprintf vprintf \
vfork waitpid bcmp bcopy bzero
needed-list: Makefile
rm -f needed-list; touch needed-list; \
*************** strrchr.o: $(INCDIR)/ansidecl.h
*** 435,441 ****
--- 436,444 ----
strsignal.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h
strtod.o: $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h
strtol.o: config.h $(INCDIR)/safe-ctype.h
+ strtoll.o: config.h $(INCDIR)/safe-ctype.h
strtoul.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h
+ strtoull.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h
ternary.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h \
$(INCDIR)/ternary.h
vasprintf.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h
Index: configure.in
===================================================================
RCS file: /cvsroot/gcc/gcc/libiberty/configure.in,v
retrieving revision 1.46
diff -c -p -r1.46 configure.in
*** configure.in 31 Jan 2002 18:19:39 -0000 1.46
--- configure.in 19 Feb 2002 16:05:43 -0000
*************** funcs="$funcs strstr"
*** 171,176 ****
--- 171,178 ----
funcs="$funcs strtod"
funcs="$funcs strtol"
funcs="$funcs strtoul"
+ funcs="$funcs strtoll"
+ funcs="$funcs strtoull"
funcs="$funcs tmpnam"
funcs="$funcs vasprintf"
funcs="$funcs vfprintf"
*************** if test "x" = "y"; then
*** 191,197 ****
AC_CHECK_FUNCS(getcwd getpagesize index insque mkstemps memchr memcmp memcpy)
AC_CHECK_FUNCS(memmove memset putenv random rename rindex sigsetmask)
AC_CHECK_FUNCS(strcasecmp setenv strchr strdup strncasecmp strrchr strstr)
! AC_CHECK_FUNCS(strtod strtol strtoul tmpnam vasprintf vfprintf vprintf)
AC_CHECK_FUNCS(vsprintf waitpid getrusage on_exit psignal strerror strsignal)
AC_CHECK_FUNCS(sysconf times sbrk gettimeofday ffs)
AC_DEFINE(HAVE_SYS_ERRLIST, 1, [Define if you have the sys_errlist variable.])
--- 193,200 ----
AC_CHECK_FUNCS(getcwd getpagesize index insque mkstemps memchr memcmp memcpy)
AC_CHECK_FUNCS(memmove memset putenv random rename rindex sigsetmask)
AC_CHECK_FUNCS(strcasecmp setenv strchr strdup strncasecmp strrchr strstr)
! AC_CHECK_FUNCS(strtod strtol strtoul strtoll strtoull)
! AC_CHECK_FUNCS(tmpnam vasprintf vfprintf vprintf)
AC_CHECK_FUNCS(vsprintf waitpid getrusage on_exit psignal strerror strsignal)
AC_CHECK_FUNCS(sysconf times sbrk gettimeofday ffs)
AC_DEFINE(HAVE_SYS_ERRLIST, 1, [Define if you have the sys_errlist variable.])
Index: acconfig.h
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/acconfig.h,v
retrieving revision 1.25
diff -c -p -r1.25 acconfig.h
*** acconfig.h 14 Dec 2001 21:06:32 -0000 1.25
--- acconfig.h 19 Feb 2002 16:08:14 -0000
***************
*** 19,24 ****
--- 19,27 ----
// Include I/O support for 'long long' and 'unsigned long long'.
#undef _GLIBCPP_USE_LONG_LONG
+ // Use strtoll and strtoull from libiberty
+ #undef _GLIBCPP_USE_LIBIBERTY_STRTOLL
+
// Define if C99 features such as lldiv_t, llabs, lldiv should be exposed.
#undef _GLIBCPP_USE_C99
Index: acinclude.m4
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/acinclude.m4,v
retrieving revision 1.191
diff -c -p -r1.191 acinclude.m4
*** acinclude.m4 14 Feb 2002 18:24:04 -0000 1.191
--- acinclude.m4 19 Feb 2002 16:08:15 -0000
*************** AC_DEFUN(GLIBCPP_ENABLE_LONG_LONG, [dnl
*** 1552,1569 ****
AC_LANG_SAVE
AC_LANG_CPLUSPLUS
! AC_MSG_CHECKING([for enabled long long I/O support])
! # iostreams require strtoll, strtoull to compile
AC_TRY_COMPILE([#include <stdlib.h>],
! [char* tmp; strtoll("gnu", &tmp, 10);],,[enable_long_long=no])
AC_TRY_COMPILE([#include <stdlib.h>],
! [char* tmp; strtoull("gnu", &tmp, 10);],,[enable_long_long=no])
# Option parsed, now set things appropriately
if test x"$enable_long_long" = xyes; then
AC_DEFINE(_GLIBCPP_USE_LONG_LONG)
fi
! AC_MSG_RESULT($enable_long_long)
AC_LANG_RESTORE
])
--- 1552,1576 ----
AC_LANG_SAVE
AC_LANG_CPLUSPLUS
! AC_MSG_CHECKING([for native long long I/O support])
! # iostreams require strtoll, strtoull to compile. determine if we have
! # native versions, or if we need to use libiberty
! native_long_long=yes ;
AC_TRY_COMPILE([#include <stdlib.h>],
! [char* tmp; strtoll("gnu", &tmp, 10);],,[native_long_long=no])
AC_TRY_COMPILE([#include <stdlib.h>],
! [char* tmp; strtoull("gnu", &tmp, 10);],,[native_long_long=no])
!
! if test x"$native_long_long" = xno; then
! AC_DEFINE(_GLIBCPP_USE_LIBIBERTY_STRTOLL)
! need_libiberty=yes;
! fi
# Option parsed, now set things appropriately
if test x"$enable_long_long" = xyes; then
AC_DEFINE(_GLIBCPP_USE_LONG_LONG)
fi
! AC_MSG_RESULT($native_long_long)
AC_LANG_RESTORE
])
Index: configure.in
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/configure.in,v
retrieving revision 1.81
diff -c -p -r1.81 configure.in
*** configure.in 14 Feb 2002 18:24:10 -0000 1.81
--- configure.in 19 Feb 2002 16:08:15 -0000
*************** AC_SUBST(release_VERSION)
*** 13,18 ****
--- 13,19 ----
libtool_VERSION=4:0:0
AC_SUBST(libtool_VERSION)
+
# Gets build, host, target, *_vendor, *_cpu, *_os, etc.
# AC 2.50 sets target_alias iff the user specified --target, but we use it
# everywhere, so we set it here just to be sure.
*************** AC_SUBST(enable_static)
*** 38,43 ****
--- 39,45 ----
GLIBCPP_CHECK_GNU_MAKE
# Enable all the variable C++ stuff. C_MBCHAR must come early.
+ need_libiberty=no
GLIBCPP_ENABLE_DEBUG($USE_MAINTAINER_MODE)
GLIBCPP_ENABLE_CSTDIO
GLIBCPP_ENABLE_CLOCALE
*************** else
*** 288,293 ****
--- 290,297 ----
LIBSUPCXX_PICFLAGS=
fi
AC_SUBST(LIBSUPCXX_PICFLAGS)
+
+ AM_CONDITIONAL(GLIBCPP_NEED_LIBIBERTY, test "$need_libiberty" = yes)
# Generate the various Makefiles, include files, and scripts.
# NB: Multilibs need MULTISUBDIR defined correctly in src/Makefile.am
Index: config/locale/c_locale_generic.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/config/locale/c_locale_generic.cc,v
retrieving revision 1.9
diff -c -p -r1.9 c_locale_generic.cc
*** config/locale/c_locale_generic.cc 6 Feb 2002 23:11:16 -0000 1.9
--- config/locale/c_locale_generic.cc 19 Feb 2002 16:08:15 -0000
*************** namespace std
*** 77,82 ****
--- 77,87 ----
}
#ifdef _GLIBCPP_USE_LONG_LONG
+ # ifdef _GLIBCPP_USE_LIBIBERTY_STRTOLL
+ extern "C" long long strtoll(const char*, char**, int);
+ extern "C" unsigned long long strtoull(const char*, char**, int);
+ # endif
+
template<>
void
__convert_to_v(const char* __s, long long& __v, ios_base::iostate& __err,
Index: src/Makefile.am
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/src/Makefile.am,v
retrieving revision 1.103
diff -c -p -r1.103 Makefile.am
*** src/Makefile.am 14 Feb 2002 18:24:12 -0000 1.103
--- src/Makefile.am 19 Feb 2002 16:08:16 -0000
*************** LTCXXCOMPILE = $(LIBTOOL) --tag CXX --mo
*** 145,149 ****
--- 145,153 ----
# course is problematic at this point. So, we get the top-level
# directory to configure libstdc++-v3 to use gcc as the C++
# compilation driver.
+ if GLIBCPP_NEED_LIBIBERTY
+ LIBS = -L../../libiberty -liberty
+ endif
+
CXXLINK = $(LIBTOOL) --tag CXX --mode=link $(CXX) \
@OPT_LDFLAGS@ @SECTION_LDFLAGS@ $(AM_CXXFLAGS) $(LDFLAGS) -o $@
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |