[PATCH] Complete (?) code for 'long long'

Chip Salzenberg chip@valinux.com
Sat Apr 1 00:00:00 GMT 2000


2000-02-11  Chip Salzenberg  <chip@valinux.com>

	Improve (complete?) 'long long' support.
	* mknumeric_limits: Call $CXX with $CPPFLAGS.  Define statics
	for {,unsigned} long long if the limits header declares	them.
	* src/gen-num-limits.cc: Include <bits/c++config.h> early.
	(__USE_GNU, _GNU_SOURCE): Define if _GLIBC_USE_LONG_LONG.
	(long long, unsigned long long): Gen limits if _GLIBC_USE_LONG_LONG.
	* bits/locale_facets.h (num_get<>::get(..., long long &)): Define.
	(num_put<>::put(..., long long)): Likewise.
	(num_put<>::put(..., unsigned long long)): Likewise.
	* bits/locale_facets.tcc (_S_format): Rename from _S_format_long.
	Templatize last parameter to support 'long long'.
	(num_put<>::put(...)): Call _S_format with new name.
	(num_put<>::put(..., long long)): Define.
	(num_put<>::put(..., unsigned long long)): Likewise.
	* src/locale-inst.cc (_S_format): Instantiate under new name.

Index: mknumeric_limits
===================================================================
RCS file: /cvs/libstdc++/libstdc++/mknumeric_limits,v
retrieving revision 1.20
diff -u -2 -r1.20 mknumeric_limits
--- mknumeric_limits	2000/02/09 18:06:34	1.20
+++ mknumeric_limits	2000/02/11 22:19:10
@@ -164,5 +164,5 @@
 EOF
 
-$CXX -I$BUILD_DIR \
+$CXX $CPPFLAGS -I$BUILD_DIR \
     -o "$BUILD_DIR/src/gen-num-limits" "$SRC_DIR/src/gen-num-limits.cc" \
      $LDFLAGS
@@ -225,7 +225,9 @@
 
 for type_name in bool char 'signed char' 'unsigned char' \
-	    short 'unsigned short' int 'unsigned int' \
-	    long 'unsigned long' float double 'long double'
+	    short 'unsigned short' int 'unsigned int' long 'unsigned long' \
+	    'long long' 'unsigned long long' \
+	    float double 'long double'
     do
+     grep "<$type_name>" $OUT_H >/dev/null 2>&1 || continue
      cat <<EOF >> $OUT_C
 

Index: src/gen-num-limits.cc
===================================================================
RCS file: /cvs/libstdc++/libstdc++/src/gen-num-limits.cc,v
retrieving revision 1.9
diff -u -2 -r1.9 gen-num-limits.cc
--- gen-num-limits.cc	2000/02/04 23:16:03	1.9
+++ gen-num-limits.cc	2000/02/11 22:19:19
@@ -1,3 +1,3 @@
-// Copyright (C) 1999 Cygnus Solutions
+// Copyright (C) 1999, 2000 Cygnus Solutions
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -34,4 +34,18 @@
 //
 
+#include <bits/c++config.h>
+
+//
+// Force Linux <limits.h> to define the *LONG_LONG*
+//
+#if __linux__ && _GLIBCPP_USE_LONG_LONG
+# ifndef __USE_GNU
+#  define __USE_GNU 1
+# endif
+# ifndef _GNU_SOURCE
+#  define _GNU_SOURCE 1
+# endif
+#endif
+
 #include <limits.h>
 #include <float.h>
@@ -40,5 +54,4 @@
 #include <setjmp.h>
 #include <math.h>
-#include <bits/c++config.h>
 #ifdef _GLIBCPP_USE_WCHAR_T
 #include <wchar.h>
@@ -64,5 +77,6 @@
 //
 // Integer types: bool, char, signed char, unsigned char, wchar_t,
-// short, unsigned short, int, unsigned, long, unsigned long
+// short, unsigned short, int, unsigned, long, unsigned long,
+// and possibly long long and unsigned long long
 //
 // Here ISO 14882 disagrees with LIA-1 in stating bool to be an
@@ -144,4 +158,7 @@
 SPECIALIZE_TRAPPING(unsigned int);
 SPECIALIZE_TRAPPING(unsigned long);
+#if _GLIBCPP_USE_LONG_LONG
+SPECIALIZE_TRAPPING(unsigned long long);
+#endif
 
 #undef SPECIALIZE_TRAPPING
@@ -167,4 +184,8 @@
 DEFINED_TYPE_NAME(long);
 DEFINED_TYPE_NAME(unsigned long);
+#ifdef _GLIBCPP_USE_LONG_LONG
+DEFINED_TYPE_NAME(long long);
+DEFINED_TYPE_NAME(unsigned long long);
+#endif
 DEFINED_TYPE_NAME(float);
 DEFINED_TYPE_NAME(double);
@@ -260,4 +281,8 @@
 SPECIALIZE_IEC559(long);
 SPECIALIZE_IEC559(unsigned long);
+#ifdef _GLIBCPP_USE_LONG_LONG
+SPECIALIZE_IEC559(long long);
+SPECIALIZE_IEC559(unsigned long long);
+#endif
 
 #undef SPECIALIZE_IEC559
@@ -302,4 +327,8 @@
 DEFINE_EXTREMA(long, LONG_MIN, LONG_MAX);
 DEFINE_EXTREMA(unsigned long, 0, ULONG_MAX);
+#ifdef _GLIBCPP_USE_LONG_LONG
+DEFINE_EXTREMA(long long, LONG_LONG_MIN, LONG_LONG_MAX);
+DEFINE_EXTREMA(unsigned long long, 0, ULONG_LONG_MAX);
+#endif
 DEFINE_EXTREMA(float, FLT_MIN, FLT_MAX);
 DEFINE_EXTREMA(double, DBL_MIN, DBL_MAX);
@@ -660,4 +689,9 @@
     type_trait<long>();
     type_trait<unsigned long>();
+
+#ifdef _GLIBCPP_USE_LONG_LONG
+    type_trait<long long>();
+    type_trait<unsigned long long>();
+#endif
 
     type_trait<float>();

Index: bits/locale_facets.h
===================================================================
RCS file: /cvs/libstdc++/libstdc++/bits/locale_facets.h,v
retrieving revision 1.13
diff -u -2 -r1.13 locale_facets.h
--- locale_facets.h	1999/12/20 20:05:38	1.13
+++ locale_facets.h	2000/02/11 22:19:14
@@ -1,5 +1,5 @@
 // Locale support -*- C++ -*-
 
-// Copyright (C) 1997-1999 Cygnus Solutions
+// Copyright (C) 1997-2000 Cygnus Solutions
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -910,5 +910,6 @@
       iter_type 
       get(iter_type __in, iter_type __end, ios_base& __io,
-	  ios_base::iostate& __err, long long& __v) const;
+	  ios_base::iostate& __err, long long& __v) const
+      { return do_get(__in, __end, __io, __err, __v); }
 #endif
 
@@ -1067,5 +1068,12 @@
       { return do_put(__s, __f, __fill, __v); }
 
+#ifdef _GLIBCPP_USE_LONG_LONG 
       iter_type 
+      put(iter_type __s, ios_base& __f, char_type __fill, 
+	  unsigned long long __v) const
+      { return do_put(__s, __f, __fill, __v); }
+#endif
+
+      iter_type 
       put(iter_type __s, ios_base& __f, char_type __fill, double __v) const
       { return do_put(__s, __f, __fill, __v); }
@@ -1100,4 +1108,9 @@
       virtual iter_type 
       do_put(iter_type, ios_base&, char_type __fill, unsigned long) const;
+
+#ifdef _GLIBCPP_USE_LONG_LONG 
+      virtual iter_type 
+      do_put(iter_type, ios_base&, char_type __fill, unsigned long long) const;
+#endif
 
       virtual iter_type 

Index: bits/locale_facets.tcc
===================================================================
RCS file: /cvs/libstdc++/libstdc++/bits/locale_facets.tcc,v
retrieving revision 1.29
diff -u -2 -r1.29 locale_facets.tcc
--- locale_facets.tcc	2000/02/02 08:48:05	1.29
+++ locale_facets.tcc	2000/02/11 22:19:16
@@ -934,5 +934,5 @@
 	{
 	  unsigned long __uv = __v;
-	  return _S_format_long(__s, __io, __fill, false, __uv);
+	  return _S_format(__s, __io, __fill, false, __uv);
 	}
       else
@@ -981,11 +981,11 @@
     }
 
-  template <typename _CharT, typename _OutIter>
+  template <typename _CharT, typename _OutIter, typename _ValueT>
     _OutIter
-    _S_format_long(_OutIter __s, ios_base& __io, _CharT __fill, bool __neg,
-		   unsigned long __v)
+    _S_format(_OutIter __s, ios_base& __io, _CharT __fill, bool __neg,
+	      _ValueT __v)
     {
       // Leave room for "+/-," "0x," and commas.
-      const long _M_room = numeric_limits<unsigned long>::digits10 * 2 + 4;
+      const long _M_room = numeric_limits<_ValueT>::digits10 * 2 + 4;
       _CharT __digits[_M_room];
       _CharT* __front = __digits + _M_room;
@@ -1062,8 +1062,16 @@
 	  __uv = -__uv; 
 	}
-      return _S_format_long(__s, __io, __fill, __neg, __uv);
+      return _S_format(__s, __io, __fill, __neg, __uv);
     }
 
+  template <typename _CharT, typename _OutIter>
+    _OutIter 
+    num_put<_CharT, _OutIter>::
+    do_put(iter_type __s, ios_base& __io, char_type __fill, 
+	   unsigned long __v) const
+    { return _S_format(__s, __io, __fill, false, __v); }
+
 #ifdef _GLIBCPP_USE_LONG_LONG 
+
   template <typename _CharT, typename _OutIter>
     _OutIter 
@@ -1078,7 +1086,6 @@
 	  __uv = -__uv; 
 	}
-      return _S_format_long(__s, __b, __fill, __neg, __uv);
+      return _S_format(__s, __b, __fill, __neg, __uv);
     }
-#endif
 
   template <typename _CharT, typename _OutIter>
@@ -1086,6 +1093,8 @@
     num_put<_CharT, _OutIter>::
     do_put(iter_type __s, ios_base& __io, char_type __fill, 
-	   unsigned long __v) const
-    { return _S_format_long(__s, __io, __fill, false, __v); }
+	   unsigned long long __v) const
+    { return _S_format(__s, __io, __fill, false, __v); }
+
+#endif /* _GLIBCPP_USE_LONG_LONG */
 
   // The following code uses sprintf() to convert floating point
@@ -1242,6 +1251,7 @@
       __io.flags(__fmt & __fmtmask | (ios_base::hex | ios_base::showbase));
       try {
-	_OutIter __s2 = _S_format_long(__s, __io, __fill, false, 
-				       reinterpret_cast<unsigned long>(__v));
+	// XXX: Some places, this should be "unsigned long long"
+	_OutIter __s2 = _S_format(__s, __io, __fill, false, 
+				  reinterpret_cast<unsigned long>(__v));
 	__io.flags(__fmt);
 	return __s2;

Index: src/locale-inst.cc
===================================================================
RCS file: /cvs/libstdc++/libstdc++/src/locale-inst.cc,v
retrieving revision 1.18
diff -u -2 -r1.18 locale-inst.cc
--- locale-inst.cc	1999/12/18 10:16:41	1.18
+++ locale-inst.cc	2000/02/11 22:19:19
@@ -1,5 +1,5 @@
 // Locale support -*- C++ -*-
 
-// Copyright (C) 1999 Cygnus Solutions
+// Copyright (C) 1999, 2000 Cygnus Solutions
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -252,7 +252,14 @@
   template 
     ostreambuf_iter
-    _S_format_long<char, ostreambuf_iter>
+    _S_format<char, ostreambuf_iter, unsigned long>
     (ostreambuf_iter, ios_base &, char, bool, unsigned long);
 
+#ifdef _GLIBCPP_USE_LONG_LONG
+  template 
+    ostreambuf_iter
+    _S_format<char, ostreambuf_iter, unsigned long long>
+    (ostreambuf_iter, ios_base &, char, bool, unsigned long long);
+#endif
+
 #ifdef _GLIBCPP_USE_WCHAR_T
   template 
@@ -280,7 +287,14 @@
   template 
     wostreambuf_iter
-    _S_format_long<wchar_t, wostreambuf_iter>
+    _S_format<wchar_t, wostreambuf_iter, unsigned long>
     (wostreambuf_iter, ios_base &, wchar_t, bool, unsigned long);
+
+#ifdef _GLIBCPP_USE_LONG_LONG
+  template 
+    wostreambuf_iter
+    _S_format<wchar_t, wostreambuf_iter, unsigned long long>
+    (wostreambuf_iter, ios_base &, wchar_t, bool, unsigned long long);
 #endif
+#endif // _GLIBCPP_USE_WCHAR_T
 
   template 


More information about the Libstdc++ mailing list