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 for 64-bit HP-UX libstdc++-v3


> > 
> > Thanks for the patch. I think the idea for a general solution, outlined 
> > in the link below, is a better way to solve this for everybody:
> > 
> > http://gcc.gnu.org/ml/libstdc++/2002-02/msg00169.html
> > 
> > I'd appreciate it if you could test this patch, and let the list know 
> > your results. If it works, then all the HPUX-specific hackery can get 
> > removed. Sound good?
> Yes, that sounds like a better solution.
>
> One thing that needs to happen tough -- the code for libiberty needs to be
> updated to conform to the GNU coding standards -- a run through gnu-indent
> and a one-over by a human ought to take care of the conversion from KNF to
> GNU form.

The libiberty bits were copied directly from libiberty's strtol.c and 
strtoul.c, with only a glorified s/long/long long to get the types right.
I've regenerated the patch against the trunk and brought the libiberty bits 
up to GNU coding standards AFAICT.

	Doug Gregor
/*
 * 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);
}
? gettext
? stamp-h.in
Index: acconfig.h
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/acconfig.h,v
retrieving revision 1.25
diff -c -3 -p -r1.25 acconfig.h
*** acconfig.h	14 Dec 2001 21:06:32 -0000	1.25
--- acconfig.h	14 Mar 2002 01:55:21 -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.198
diff -c -3 -p -r1.198 acinclude.m4
*** acinclude.m4	12 Mar 2002 02:41:58 -0000	1.198
--- acinclude.m4	14 Mar 2002 01:55:21 -0000
*************** AC_DEFUN(GLIBCPP_ENABLE_LONG_LONG, [dnl
*** 1578,1595 ****
    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
  ])
--- 1578,1602 ----
    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: config.h.in
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/config.h.in,v
retrieving revision 1.51
diff -c -3 -p -r1.51 config.h.in
*** config.h.in	12 Mar 2002 02:41:59 -0000	1.51
--- config.h.in	14 Mar 2002 01:55:21 -0000
***************
*** 12,17 ****
--- 12,20 ----
  // 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
  
***************
*** 699,707 ****
  /* Define if you have the <nan.h> header file.  */
  #undef HAVE_NAN_H
  
- /* Define if you have the <stdlib.h> header file.  */
- #undef HAVE_STDLIB_H
- 
  /* Define if you have the <sys/isa_defs.h> header file.  */
  #undef HAVE_SYS_ISA_DEFS_H
  
--- 702,707 ----
***************
*** 710,718 ****
  
  /* Define if you have the <sys/resource.h> header file.  */
  #undef HAVE_SYS_RESOURCE_H
- 
- /* Define if you have the <sys/stat.h> header file.  */
- #undef HAVE_SYS_STAT_H
  
  /* Define if you have the <sys/types.h> header file.  */
  #undef HAVE_SYS_TYPES_H
--- 710,715 ----
Index: configure.in
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/configure.in,v
retrieving revision 1.84
diff -c -3 -p -r1.84 configure.in
*** configure.in	10 Mar 2002 19:28:05 -0000	1.84
--- configure.in	14 Mar 2002 01:55:21 -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
*** 303,308 ****
--- 305,312 ----
    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/Attic/c_locale_generic.cc,v
retrieving revision 1.9
diff -c -3 -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	14 Mar 2002 01:55:21 -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.104
diff -c -3 -p -r1.104 Makefile.am
*** src/Makefile.am	9 Mar 2002 02:16:36 -0000	1.104
--- src/Makefile.am	14 Mar 2002 01:55:21 -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 $@

Attachment: strtoll.c
Description: Text document

? strtoull.c
? strtoll.c
Index: Makefile.in
===================================================================
RCS file: /cvsroot/gcc/gcc/libiberty/Makefile.in,v
retrieving revision 1.74
diff -c -3 -p -r1.74 Makefile.in
*** Makefile.in	4 Mar 2002 21:41:06 -0000	1.74
--- Makefile.in	14 Mar 2002 03:04:07 -0000
*************** CFILES = alloca.c argv.c asprintf.c atex
*** 140,146 ****
  	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							\
--- 140,146 ----
  	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	
*** 179,185 ****
  	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
--- 179,185 ----
  	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
*** 281,287 ****
  # 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; \
--- 281,288 ----
  # 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
*** 464,470 ****
--- 465,473 ----
  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.47
diff -c -3 -p -r1.47 configure.in
*** configure.in	4 Mar 2002 21:41:06 -0000	1.47
--- configure.in	14 Mar 2002 03:04:07 -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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]