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]

Re: [PATCH] fix libstdc++/5611


On Monday 18 February 2002 02:14 pm, Benjamin Kosnik wrote:
> Can you please re-submit this patch, only this time:
>
> 1) don't include regenerated files (Makefile.in's, configure, etc.)
> 2) use diff -cp

My apologies. Please see attached files for the updated patch.

	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

Index: acconfig.h
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/acconfig.h,v
retrieving revision 1.15.4.5
diff -c -p -r1.15.4.5 acconfig.h
*** acconfig.h	2 Nov 2001 22:39:01 -0000	1.15.4.5
--- acconfig.h	18 Feb 2002 19:27:48 -0000
***************
*** 9,14 ****
--- 9,17 ----
  // 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.129.2.32
diff -c -p -r1.129.2.32 acinclude.m4
*** acinclude.m4	18 Jan 2002 22:58:24 -0000	1.129.2.32
--- acinclude.m4	18 Feb 2002 19:27:49 -0000
*************** AC_DEFUN(GLIBCPP_ENABLE_LONG_LONG, [dnl
*** 1381,1398 ****
    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
  ])
--- 1381,1404 ----
    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)
!   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: include/bits/locale_facets.tcc
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/include/bits/locale_facets.tcc,v
retrieving revision 1.8.2.5
diff -c -p -r1.8.2.5 locale_facets.tcc
*** include/bits/locale_facets.tcc	11 Dec 2001 08:01:23 -0000	1.8.2.5
--- include/bits/locale_facets.tcc	18 Feb 2002 19:27:50 -0000
*************** namespace std
*** 420,425 ****
--- 420,429 ----
      }
  
  #ifdef _GLIBCPP_USE_LONG_LONG
+ #  ifdef _GLIBCPP_USE_LIBIBERTY_STRTOLL
+   extern "C" long long strtoll(const char*, char**, int);
+ #  endif
+ 
    template<typename _CharT, typename _InIter>
      _InIter
      num_get<_CharT, _InIter>::
*************** namespace std
*** 528,533 ****
--- 532,541 ----
      }
  
  #ifdef _GLIBCPP_USE_LONG_LONG
+ #  ifdef _GLIBCPP_USE_LIBIBERTY_STRTOLL
+   extern "C" unsigned long long strtoull(const char*, char**, int);
+ #  endif
+ 
    template<typename _CharT, typename _InIter>
      _InIter
      num_get<_CharT, _InIter>::
Index: src/Makefile.am
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/src/Makefile.am,v
retrieving revision 1.71.2.14
diff -c -p -r1.71.2.14 Makefile.am
*** src/Makefile.am	14 Jan 2002 18:29:56 -0000	1.71.2.14
--- src/Makefile.am	18 Feb 2002 19:27:50 -0000
*************** LTCXXCOMPILE = $(LIBTOOL) --tag CXX --mo
*** 135,139 ****
--- 135,140 ----
  # 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.
+ LIBS = -L../../libiberty -liberty
  CXXLINK = $(LIBTOOL) --tag CXX --mode=link $(CXX) \
  	  @OPT_LDFLAGS@ @SECTION_LDFLAGS@ $(AM_CXXFLAGS) $(LDFLAGS) -o $@
? strtoll.c
? strtoull.c
Index: Makefile.in
===================================================================
RCS file: /cvsroot/gcc/gcc/libiberty/Makefile.in,v
retrieving revision 1.57.4.2
diff -c -p -r1.57.4.2 Makefile.in
*** Makefile.in	7 Dec 2001 03:39:16 -0000	1.57.4.2
--- Makefile.in	18 Feb 2002 19:20:52 -0000
*************** CFILES = asprintf.c alloca.c argv.c atex
*** 134,140 ****
  	partition.c pexecute.c putenv.c random.c rename.c rindex.c setenv.c   \
  	sigsetmask.c safe-ctype.c sort.c spaces.c splay-tree.c strcasecmp.c   \
  	strncasecmp.c strchr.c strdup.c strerror.c strncmp.c strrchr.c        \
! 	strsignal.c strstr.c strtod.c strtol.c strtoul.c tmpnam.c vasprintf.c \
  	vfork.c vfprintf.c vprintf.c vsprintf.c waitpid.c xatexit.c xexit.c   \
  	xmalloc.c xmemdup.c xstrdup.c xstrerror.c
  
--- 134,141 ----
  	partition.c pexecute.c putenv.c random.c rename.c rindex.c setenv.c   \
  	sigsetmask.c safe-ctype.c sort.c spaces.c splay-tree.c strcasecmp.c   \
  	strncasecmp.c strchr.c strdup.c strerror.c strncmp.c strrchr.c        \
! 	strsignal.c strstr.c strtod.c strtol.c strtoul.c strtoll.c strtoull.c \
!         tmpnam.c vasprintf.c \
  	vfork.c vfprintf.c vprintf.c vsprintf.c waitpid.c xatexit.c xexit.c   \
  	xmalloc.c xmemdup.c xstrdup.c xstrerror.c
  
*************** install_to_tooldir: all
*** 172,178 ****
  # 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; \
--- 173,180 ----
  # 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; \
*************** strerror.o: config.h $(INCDIR)/libiberty
*** 299,304 ****
--- 301,308 ----
  strsignal.o: config.h $(INCDIR)/libiberty.h
  strtol.o: config.h
  strtoul.o: config.h
+ strtoll.o: config.h
+ strtoull.o: config.h
  vasprintf.o: config.h
  xatexit.o: $(INCDIR)/libiberty.h
  xexit.o: config.h $(INCDIR)/libiberty.h
Index: configure.in
===================================================================
RCS file: /cvsroot/gcc/gcc/libiberty/configure.in,v
retrieving revision 1.31.4.2
diff -c -p -r1.31.4.2 configure.in
*** configure.in	22 Jan 2002 22:29:04 -0000	1.31.4.2
--- configure.in	18 Feb 2002 19:20:52 -0000
*************** funcs="$funcs strstr"
*** 112,117 ****
--- 112,119 ----
  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
*** 132,138 ****
    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)
    AC_DEFINE(HAVE_SYS_ERRLIST, 1, [Define if you have the sys_errlist variable.])
--- 134,141 ----
    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)
    AC_DEFINE(HAVE_SYS_ERRLIST, 1, [Define if you have the sys_errlist variable.])

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]