This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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: Use long long in _itoa and _itowa if PREFER_LONG_LONG is defined


On Tue, Mar 20, 2012 at 3:48 PM, Roland McGrath <roland@hack.frob.com> wrote:
> This is probably fine, but maximal paranoia dictates that the first change
> should be just moving the file and changing the #include's. ?Then a second
> change can go in adding the macro stuff. ?So please do just the renaming
> change first (go ahead and commit it, no need to post again), and then post

Done.

> the (much smaller) patch that changes the substance.
>
>

Here is the smaller change.  OK to install?

Thanks.

-- 
H.J.
2012-03-20  H.J. Lu  <hongjiu.lu@intel.com>

	* stdio-common/_itoa.c: Check _ITOA_NEEDED instead of
	LLONG_MAX != LONG_MAX.
	(_itoa_word): Use _ITOA_WORD_TYPE on value.
	(_fitoa_word): Likewise.

	* stdio-common/_itowa.c: Check _ITOWA_NEEDED instead of
	LLONG_MAX != LONG_MAX.

	* stdio-common/_itowa.h: Include <limits.h>.
	(_ITOWA_NEEDED): New macro.  Defined only if not defined.
	(_ITOWA_WORD_TYPE): Likewise.
	(_itowa_word): Use _ITOA_WORD_TYPE on value.
	(_itowa): New macro.  Defined only if _ITOWA_NEEDED is false.

	* sysdeps/generic/_itoa.h (_ITOA_NEEDED): New macro.  Defined
	only if not defined.
	(_ITOA_WORD_TYPE): Likewise.
	(_itoa_word): Use _ITOA_WORD_TYPE on value.
	Check !_ITOA_NEEDED instead of LONG_MAX == LLONG_MAX.

diff --git a/stdio-common/_itoa.c b/stdio-common/_itoa.c
index 3dfff8f..12d6954 100644
--- a/stdio-common/_itoa.c
+++ b/stdio-common/_itoa.c
@@ -79,7 +79,7 @@ struct base_table_t
 
 
 /* We do not compile _itoa if we always can use _itoa_word.  */
-#if LLONG_MAX != LONG_MAX
+#if _ITOA_NEEDED
 /* Local variables.  */
 const struct base_table_t _itoa_base_table[] attribute_hidden =
 {
@@ -169,7 +169,7 @@ extern const char _itoa_upper_digits_internal[] attribute_hidden;
 
 
 char *
-_itoa_word (unsigned long value, char *buflim,
+_itoa_word (_ITOA_WORD_TYPE value, char *buflim,
 	    unsigned int base, int upper_case)
 {
   const char *digits = (upper_case
@@ -204,7 +204,7 @@ _itoa_word (unsigned long value, char *buflim,
 #undef SPECIAL
 
 
-#if LLONG_MAX != LONG_MAX
+#if _ITOA_NEEDED
 char *
 _itoa (value, buflim, base, upper_case)
      unsigned long long int value;
@@ -470,7 +470,8 @@ _itoa (value, buflim, base, upper_case)
 #endif
 
 char *
-_fitoa_word (unsigned long value, char *buf, unsigned int base, int upper_case)
+_fitoa_word (_ITOA_WORD_TYPE value, char *buf, unsigned int base,
+	     int upper_case)
 {
   char tmpbuf[sizeof (value) * 4];	      /* Worst case length: base 2.  */
   char *cp = _itoa_word (value, tmpbuf + sizeof (value) * 4, base, upper_case);
@@ -479,7 +480,7 @@ _fitoa_word (unsigned long value, char *buf, unsigned int base, int upper_case)
   return buf;
 }
 
-#if LLONG_MAX != LONG_MAX
+#if _ITOA_NEEDED
 char *
 _fitoa (unsigned long long value, char *buf, unsigned int base, int upper_case)
 {
diff --git a/stdio-common/_itowa.c b/stdio-common/_itowa.c
index 1ebc712..99ac3a3 100644
--- a/stdio-common/_itowa.c
+++ b/stdio-common/_itowa.c
@@ -85,7 +85,7 @@ extern const wchar_t _itowa_lower_digits[] attribute_hidden;
 extern const wchar_t _itowa_upper_digits[] attribute_hidden;
 
 
-#if LLONG_MAX != LONG_MAX
+#if _ITOWA_NEEDED
 wchar_t *
 _itowa (value, buflim, base, upper_case)
      unsigned long long int value;
diff --git a/stdio-common/_itowa.h b/stdio-common/_itowa.h
index 0f33311..c077430 100644
--- a/stdio-common/_itowa.h
+++ b/stdio-common/_itowa.h
@@ -20,6 +20,14 @@
 #define _ITOWA_H	1
 #include <features.h>
 #include <wchar.h>
+#include <limits.h>
+
+#ifndef _ITOWA_NEEDED
+# define _ITOWA_NEEDED		(LONG_MAX != LLONG_MAX)
+#endif
+#ifndef _ITOWA_WORD_TYPE
+# define _ITOWA_WORD_TYPE	unsigned long int
+#endif
 
 /* Convert VALUE into ASCII in base BASE (2..36).
    Write backwards starting the character just before BUFLIM.
@@ -31,7 +39,7 @@ extern wchar_t *_itowa (unsigned long long int value, wchar_t *buflim,
 
 static inline wchar_t *
 __attribute__ ((unused, always_inline))
-_itowa_word (unsigned long value, wchar_t *buflim,
+_itowa_word (_ITOWA_WORD_TYPE value, wchar_t *buflim,
 	     unsigned int base, int upper_case)
 {
   extern const wchar_t _itowa_upper_digits[] attribute_hidden;
@@ -61,4 +69,10 @@ _itowa_word (unsigned long value, wchar_t *buflim,
 }
 #undef SPECIAL
 
+#if !_ITOWA_NEEDED
+/* No need for special long long versions.  */
+# define _itowa(value, buf, base, upper_case) \
+  _itowa_word (value, buf, base, upper_case)
+#endif
+
 #endif	/* itowa.h */
diff --git a/sysdeps/generic/_itoa.h b/sysdeps/generic/_itoa.h
index 8870ee0..274af1b 100644
--- a/sysdeps/generic/_itoa.h
+++ b/sysdeps/generic/_itoa.h
@@ -21,6 +21,13 @@
 
 #include <limits.h>
 
+#ifndef _ITOA_NEEDED
+# define _ITOA_NEEDED		(LONG_MAX != LLONG_MAX)
+#endif
+#ifndef _ITOA_WORD_TYPE
+# define _ITOA_WORD_TYPE	unsigned long int
+#endif
+
 /* Convert VALUE into ASCII in base BASE (2..36).
    Write backwards starting the character just before BUFLIM.
    Return the address of the first (left-to-right) character in the number.
@@ -35,11 +42,11 @@ extern const char _itoa_lower_digits[];
 extern const char _itoa_lower_digits_internal[] attribute_hidden;
 
 #ifndef NOT_IN_libc
-extern char *_itoa_word (unsigned long value, char *buflim,
+extern char *_itoa_word (_ITOA_WORD_TYPE value, char *buflim,
 			 unsigned int base, int upper_case);
 #else
 static inline char * __attribute__ ((unused, always_inline))
-_itoa_word (unsigned long value, char *buflim,
+_itoa_word (_ITOA_WORD_TYPE value, char *buflim,
 	    unsigned int base, int upper_case)
 {
   const char *digits = (upper_case
@@ -76,12 +83,13 @@ _itoa_word (unsigned long value, char *buflim,
 
 /* Similar to the _itoa functions, but output starts at buf and pointer
    after the last written character is returned.  */
-extern char *_fitoa_word (unsigned long value, char *buf, unsigned int base,
+extern char *_fitoa_word (_ITOA_WORD_TYPE value, char *buf,
+			  unsigned int base,
 			  int upper_case) attribute_hidden;
 extern char *_fitoa (unsigned long long value, char *buf, unsigned int base,
 		     int upper_case) attribute_hidden;
 
-#if LONG_MAX == LLONG_MAX
+#if !_ITOA_NEEDED
 /* No need for special long long versions.  */
 # define _itoa(value, buf, base, upper_case) \
   _itoa_word (value, buf, base, upper_case)

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