apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Davi Arnaut <d...@haxent.com.br>
Subject [patch 4/9] replace wide types
Date Fri, 27 Apr 2007 14:29:22 GMT
Convert wide* types to the portable apr types. Passes testfmt.

---
 srclib/apr/strings/apr_snprintf.c |   93 ++++++++++++++++----------------------
 1 file changed, 41 insertions(+), 52 deletions(-)

Index: 2.2.x/srclib/apr/strings/apr_snprintf.c
===================================================================
--- 2.2.x.orig/srclib/apr/strings/apr_snprintf.c	2007-04-27 11:09:50.000000000 -0300
+++ 2.2.x/srclib/apr/strings/apr_snprintf.c	2007-04-27 11:09:50.000000000 -0300
@@ -53,17 +53,7 @@
 #define TRUE 1
 #endif
 #define NUL '\0'
-#define WIDE_INT long
 
-typedef WIDE_INT wide_int;
-typedef unsigned WIDE_INT u_wide_int;
-typedef apr_int64_t widest_int;
-#ifdef __TANDEM
-/* Although Tandem supports "long long" there is no unsigned variant. */
-typedef unsigned long       u_widest_int;
-#else
-typedef apr_uint64_t u_widest_int;
-#endif
 typedef int bool_int;
 
 #define S_NULL "(null)"
@@ -338,12 +328,12 @@
  * (conv_10_quad), the other when we don't (conv_10). We're assuming the
  * latter is faster.
  */
-static char *conv_10(register wide_int num, register bool_int is_unsigned,
+static char *conv_10(register apr_int32_t num, register bool_int is_unsigned,
                      register bool_int *is_negative, char *buf_end,
                      register apr_size_t *len)
 {
     register char *p = buf_end;
-    register u_wide_int magnitude = num;
+    register apr_uint32_t magnitude = num;
 
     if (is_unsigned) {
         *is_negative = FALSE;
@@ -361,8 +351,8 @@
          *      d. add 1
          */
         if (*is_negative) {
-            wide_int t = num + 1;
-            magnitude = ((u_wide_int) -t) + 1;
+            apr_int32_t t = num + 1;
+            magnitude = ((apr_uint32_t) -t) + 1;
         }
     }
 
@@ -377,22 +367,21 @@
     return (p);
 }
 
-static char *conv_10_quad(widest_int num, register bool_int is_unsigned,
+static char *conv_10_quad(apr_int64_t num, register bool_int is_unsigned,
                      register bool_int *is_negative, char *buf_end,
                      register apr_size_t *len)
 {
     register char *p = buf_end;
-    u_widest_int magnitude = num;
+    apr_uint64_t magnitude = num;
 
     /*
      * We see if we can use the faster non-quad version by checking the
      * number against the largest long value it can be. If <=, we
      * punt to the quicker version.
      */
-    if ((magnitude <= ULONG_MAX && is_unsigned)
-        || (num <= LONG_MAX && num >= LONG_MIN && !is_unsigned))
-            return(conv_10( (wide_int)num, is_unsigned, is_negative,
-               buf_end, len));
+    if ((magnitude <= UINT32_MAX && is_unsigned)
+        || (num <= INT32_MAX && num >= INT32_MIN && !is_unsigned))
+            return(conv_10(num, is_unsigned, is_negative, buf_end, len));
 
     if (is_unsigned) {
         *is_negative = FALSE;
@@ -410,8 +399,8 @@
          *      d. add 1
          */
         if (*is_negative) {
-            widest_int t = num + 1;
-            magnitude = ((u_widest_int) -t) + 1;
+            apr_int64_t t = num + 1;
+            magnitude = ((apr_uint64_t) -t) + 1;
         }
     }
 
@@ -582,7 +571,7 @@
         *s++ = format;                /* either e or E */
         decimal_point--;
         if (decimal_point != 0) {
-            p = conv_10((wide_int) decimal_point, FALSE, &exponent_is_negative,
+            p = conv_10((apr_int32_t) decimal_point, FALSE, &exponent_is_negative,
                         &temp[EXPONENT_LENGTH], &t_len);
             *s++ = exponent_is_negative ? '-' : '+';
 
@@ -619,7 +608,7 @@
  * As with conv_10, we have a faster version which is used when
  * the number isn't quad size.
  */
-static char *conv_p2(register u_wide_int num, register int nbits,
+static char *conv_p2(register apr_uint32_t num, register int nbits,
                      char format, char *buf_end, register apr_size_t *len)
 {
     register int mask = (1 << nbits) - 1;
@@ -638,7 +627,7 @@
     return (p);
 }
 
-static char *conv_p2_quad(u_widest_int num, register int nbits,
+static char *conv_p2_quad(apr_uint64_t num, register int nbits,
                      char format, char *buf_end, register apr_size_t *len)
 {
     register int mask = (1 << nbits) - 1;
@@ -647,8 +636,8 @@
     static const char upper_digits[] = "0123456789ABCDEF";
     register const char *digits = (format == 'X') ? upper_digits : low_digits;
 
-    if (num <= ULONG_MAX)
-        return(conv_p2((u_wide_int)num, nbits, format, buf_end, len));
+    if (num <= UINT32_MAX)
+        return(conv_p2((apr_uint32_t)num, nbits, format, buf_end, len));
 
     do {
         *--p = digits[num & mask];
@@ -707,10 +696,10 @@
     char prefix_char;
 
     double fp_num;
-    widest_int i_quad = (widest_int) 0;
-    u_widest_int ui_quad;
-    wide_int i_num = (wide_int) 0;
-    u_wide_int ui_num;
+    apr_int64_t i_quad = 0;
+    apr_uint64_t ui_quad;
+    apr_int32_t i_num = 0;
+    apr_uint32_t ui_num;
 
     char num_buf[NUM_BUF_SIZE];
     char char_buf[2];                /* for printing %% and %<unknown> */
@@ -861,17 +850,17 @@
             switch (*fmt) {
             case 'u':
                 if (var_type == IS_QUAD) {
-                    i_quad = va_arg(ap, u_widest_int);
+                    i_quad = va_arg(ap, apr_uint64_t);
                     s = conv_10_quad(i_quad, 1, &is_negative,
                             &num_buf[NUM_BUF_SIZE], &s_len);
                 }
                 else {
                     if (var_type == IS_LONG)
-                        i_num = (wide_int) va_arg(ap, u_wide_int);
+                        i_num = (apr_int32_t) va_arg(ap, apr_uint32_t);
                     else if (var_type == IS_SHORT)
-                        i_num = (wide_int) (unsigned short) va_arg(ap, unsigned int);
+                        i_num = (apr_int32_t) (unsigned short) va_arg(ap, unsigned int);
                     else
-                        i_num = (wide_int) va_arg(ap, unsigned int);
+                        i_num = (apr_int32_t) va_arg(ap, unsigned int);
                     s = conv_10(i_num, 1, &is_negative,
                             &num_buf[NUM_BUF_SIZE], &s_len);
                 }
@@ -881,17 +870,17 @@
             case 'd':
             case 'i':
                 if (var_type == IS_QUAD) {
-                    i_quad = va_arg(ap, widest_int);
+                    i_quad = va_arg(ap, apr_int64_t);
                     s = conv_10_quad(i_quad, 0, &is_negative,
                             &num_buf[NUM_BUF_SIZE], &s_len);
                 }
                 else {
                     if (var_type == IS_LONG)
-                        i_num = (wide_int) va_arg(ap, wide_int);
+                        i_num = va_arg(ap, apr_int32_t);
                     else if (var_type == IS_SHORT)
-                        i_num = (wide_int) (short) va_arg(ap, int);
+                        i_num = (short) va_arg(ap, int);
                     else
-                        i_num = (wide_int) va_arg(ap, int);
+                        i_num = va_arg(ap, int);
                     s = conv_10(i_num, 0, &is_negative,
                             &num_buf[NUM_BUF_SIZE], &s_len);
                 }
@@ -908,17 +897,17 @@
 
             case 'o':
                 if (var_type == IS_QUAD) {
-                    ui_quad = va_arg(ap, u_widest_int);
+                    ui_quad = va_arg(ap, apr_uint64_t);
                     s = conv_p2_quad(ui_quad, 3, *fmt,
                             &num_buf[NUM_BUF_SIZE], &s_len);
                 }
                 else {
                     if (var_type == IS_LONG)
-                        ui_num = (u_wide_int) va_arg(ap, u_wide_int);
+                        ui_num = va_arg(ap, apr_uint32_t);
                     else if (var_type == IS_SHORT)
-                        ui_num = (u_wide_int) (unsigned short) va_arg(ap, unsigned int);
+                        ui_num = (unsigned short) va_arg(ap, unsigned int);
                     else
-                        ui_num = (u_wide_int) va_arg(ap, unsigned int);
+                        ui_num = va_arg(ap, unsigned int);
                     s = conv_p2(ui_num, 3, *fmt,
                             &num_buf[NUM_BUF_SIZE], &s_len);
                 }
@@ -933,17 +922,17 @@
             case 'x':
             case 'X':
                 if (var_type == IS_QUAD) {
-                    ui_quad = va_arg(ap, u_widest_int);
+                    ui_quad = va_arg(ap, apr_uint64_t);
                     s = conv_p2_quad(ui_quad, 4, *fmt,
                             &num_buf[NUM_BUF_SIZE], &s_len);
                 }
                 else {
                     if (var_type == IS_LONG)
-                        ui_num = (u_wide_int) va_arg(ap, u_wide_int);
+                        ui_num = va_arg(ap, apr_uint32_t);
                     else if (var_type == IS_SHORT)
-                        ui_num = (u_wide_int) (unsigned short) va_arg(ap, unsigned int);
+                        ui_num = (unsigned short) va_arg(ap, unsigned int);
                     else
-                        ui_num = (u_wide_int) va_arg(ap, unsigned int);
+                        ui_num = va_arg(ap, unsigned int);
                     s = conv_p2(ui_num, 4, *fmt,
                             &num_buf[NUM_BUF_SIZE], &s_len);
                 }
@@ -1081,7 +1070,7 @@
 
             case 'n':
                 if (var_type == IS_QUAD)
-                    *(va_arg(ap, widest_int *)) = cc;
+                    *(va_arg(ap, apr_int64_t *)) = cc;
                 else if (var_type == IS_LONG)
                     *(va_arg(ap, long *)) = cc;
                 else if (var_type == IS_SHORT)
@@ -1105,14 +1094,14 @@
                  */
                 case 'p':
 #if APR_SIZEOF_VOIDP == 8
-                    if (sizeof(void *) <= sizeof(u_widest_int)) {
-                        ui_quad = (u_widest_int) va_arg(ap, void *);
+                    if (sizeof(void *) <= sizeof(apr_uint64_t)) {
+                        ui_quad = (apr_uint64_t) va_arg(ap, void *);
                         s = conv_p2_quad(ui_quad, 4, 'x',
                                 &num_buf[NUM_BUF_SIZE], &s_len);
                     }
 #else
-                    if (sizeof(void *) <= sizeof(u_wide_int)) {
-                        ui_num = (u_wide_int) va_arg(ap, void *);
+                    if (sizeof(void *) <= sizeof(apr_uint32_t)) {
+                        ui_num = (apr_uint32_t) va_arg(ap, void *);
                         s = conv_p2(ui_num, 4, 'x',
                                 &num_buf[NUM_BUF_SIZE], &s_len);
                     }

--

Mime
View raw message