Martin Kraemer wrote:
> On Fri, Jul 06, 2007 at 08:51:38AM -0300, Davi Arnaut wrote:
>>> Also the *INT32_MAX types are from C99 stdint.h which might not be present.
>> Good catch, I guess we could use *INT_MAX. This begs the question: why
>> don't we have APR_*INT32_MIN/MAX?
>
> Good point. Especially for the apr-defined int types, there should
> also be a <type>_MAX define.
>
> I'm +1 for adding them -- as at the moment, on FreeBSD-4.x I cannot compile
> apr:
>
> /usr/local/bin/bash /home/martin/apachen/X/httpd-2.3/srclib/apr/libtool
> --silent --mode=compile gcc -g -O2 -Wall -DHAVE_CONFIG_H -D_THREAD_SAFE
> -D_REENTRANT -I./include
> -I/home/martin/apachen/X/httpd-2.3/srclib/apr/include/arch/unix
> -I./include/arch/unix -I/home/martin/apachen/X/httpd-2.3/srclib/apr/include
> -o strings/apr_snprintf.lo -c strings/apr_snprintf.c && touch
> strings/apr_snprintf.lo
> strings/apr_snprintf.c: In function `conv_10_quad':
> strings/apr_snprintf.c:384: `UINT32_MAX' undeclared (first use in this
> function)
> strings/apr_snprintf.c:384: (Each undeclared identifier is reported only once
> strings/apr_snprintf.c:384: for each function it appears in.)
> strings/apr_snprintf.c:385: `INT32_MAX' undeclared (first use in this
> function)
> strings/apr_snprintf.c:385: `INT32_MIN' undeclared (first use in this
> function)
> strings/apr_snprintf.c: In function `conv_p2_quad':
> strings/apr_snprintf.c:643: `UINT32_MAX' undeclared (first use in this
> function)
> Make[1]: *** [strings/apr_snprintf.lo] Error 1
> Make[1]: Leaving directory `/home/martin/apachen/X/httpd-2.3/srclib/apr'
>
> and there's no <stdint.h>, and neither <inttypes.h> nor <limits.h>
> provide something like *INT32_MAX.
>
Could you try the attached patch? Thanks.
--
Davi Arnaut
Index: apr/include/apr.h.in
===================================================================
--- apr.orig/include/apr.h.in
+++ apr/include/apr.h.in
@@ -269,10 +269,10 @@ typedef unsigned char apr_byt
typedef @short_value@ apr_int16_t;
typedef unsigned @short_value@ apr_uint16_t;
-
+
typedef @int_value@ apr_int32_t;
typedef unsigned @int_value@ apr_uint32_t;
-
+
typedef @long_value@ apr_int64_t;
typedef unsigned @long_value@ apr_uint64_t;
@@ -290,6 +290,60 @@ typedef @socklen_t_value@ apr_soc
@int64_literal@
@uint64_literal@
+#ifdef INT16_MIN
+#define APR_INT16_MIN INT16_MIN
+#else
+#define APR_INT16_MIN (-0x7fff - 1)
+#endif
+
+#ifdef INT16_MAX
+#define APR_INT16_MAX INT16_MAX
+#else
+#define APR_INT16_MAX (0x7fff)
+#endif
+
+#ifdef UINT16_MAX
+#define APR_UINT16_MAX UINT16_MAX
+#else
+#define APR_UINT16_MAX (0xffff)
+#endif
+
+#ifdef INT32_MIN
+#define APR_INT32_MIN INT32_MIN
+#else
+#define APR_INT32_MIN (-0x7fffffff - 1)
+#endif
+
+#ifdef INT32_MAX
+#define APR_INT32_MAX INT32_MAX
+#else
+#define APR_INT32_MAX 0x7fffffff
+#endif
+
+#ifdef UINT32_MAX
+#define APR_UINT32_MAX UINT32_MAX
+#else
+#define APR_UINT32_MAX (0xffffffffU)
+#endif
+
+#ifdef INT64_MIN
+#define APR_INT64_MIN INT64_MIN
+#else
+#define APR_INT64_MIN (APR_INT64_C(-0x7fffffffffffffff) - 1)
+#endif
+
+#ifdef INT64_MAX
+#define APR_INT64_MAX INT64_MAX
+#else
+#define APR_INT64_MAX APR_INT64_C(0x7fffffffffffffff)
+#endif
+
+#ifdef UINT64_MAX
+#define APR_UINT64_MAX UINT64_MAX
+#else
+#define APR_UINT64_MAX APR_UINT64_C(0xffffffffffffffff)
+#endif
+
/* Definitions that APR programs need to work properly. */
/**
Index: apr/include/arch/apr_private_common.h
===================================================================
--- apr.orig/include/arch/apr_private_common.h
+++ apr/include/arch/apr_private_common.h
@@ -37,6 +37,5 @@ apr_status_t apr_filepath_list_merge_imp
/* temporary defines to handle 64bit compile mismatches */
#define APR_INT_TRUNC_CAST int
#define APR_UINT32_TRUNC_CAST apr_uint32_t
-#define APR_UINT32_MAX 0xFFFFFFFFUL
#endif /*APR_PRIVATE_COMMON_H*/
Index: apr/strings/apr_snprintf.c
===================================================================
--- apr.orig/strings/apr_snprintf.c
+++ apr/strings/apr_snprintf.c
@@ -381,9 +381,9 @@ static char *conv_10_quad(apr_int64_t nu
* number against the largest long value it can be. If <=, we
* punt to the quicker version.
*/
- 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 ((magnitude <= APR_UINT32_MAX && is_unsigned)
+ || (num <= APR_INT32_MAX && num >= APR_INT32_MIN && !is_unsigned))
+ return(conv_10((apr_int32_t)num, is_unsigned, is_negative,
buf_end, len));
if (is_unsigned) {
*is_negative = FALSE;
@@ -640,7 +640,7 @@ static char *conv_p2_quad(apr_uint64_t n
static const char upper_digits[] = "0123456789ABCDEF";
register const char *digits = (format == 'X') ? upper_digits : low_digits;
- if (num <= UINT32_MAX)
+ if (num <= APR_UINT32_MAX)
return(conv_p2((apr_uint32_t)num, nbits, format, buf_end, len));
do {
Index: apr/include/apr.hw
===================================================================
--- apr.orig/include/apr.hw
+++ apr/include/apr.hw
@@ -326,10 +326,10 @@ typedef unsigned char apr_byte_t;
typedef short apr_int16_t;
typedef unsigned short apr_uint16_t;
-
+
typedef int apr_int32_t;
typedef unsigned int apr_uint32_t;
-
+
typedef __int64 apr_int64_t;
typedef unsigned __int64 apr_uint64_t;
@@ -375,6 +375,60 @@ typedef int gid_t;
#define APR_UINT64_C(val) (val##ULL)
#endif
+#ifdef INT16_MIN
+#define APR_INT16_MIN INT16_MIN
+#else
+#define APR_INT16_MIN (-0x7fff - 1)
+#endif
+
+#ifdef INT16_MAX
+#define APR_INT16_MAX INT16_MAX
+#else
+#define APR_INT16_MAX (0x7fff)
+#endif
+
+#ifdef UINT16_MAX
+#define APR_UINT16_MAX UINT16_MAX
+#else
+#define APR_UINT16_MAX (0xffff)
+#endif
+
+#ifdef INT32_MIN
+#define APR_INT32_MIN INT32_MIN
+#else
+#define APR_INT32_MIN (-0x7fffffff - 1)
+#endif
+
+#ifdef INT32_MAX
+#define APR_INT32_MAX INT32_MAX
+#else
+#define APR_INT32_MAX 0x7fffffff
+#endif
+
+#ifdef UINT32_MAX
+#define APR_UINT32_MAX UINT32_MAX
+#else
+#define APR_UINT32_MAX (0xffffffffU)
+#endif
+
+#ifdef INT64_MIN
+#define APR_INT64_MIN INT64_MIN
+#else
+#define APR_INT64_MIN (APR_INT64_C(-0x7fffffffffffffff) - 1)
+#endif
+
+#ifdef INT64_MAX
+#define APR_INT64_MAX INT64_MAX
+#else
+#define APR_INT64_MAX APR_INT64_C(0x7fffffffffffffff)
+#endif
+
+#ifdef UINT64_MAX
+#define APR_UINT64_MAX UINT64_MAX
+#else
+#define APR_UINT64_MAX APR_UINT64_C(0xffffffffffffffff)
+#endif
+
#if APR_HAVE_IPV6
/* Appears in later flavors, not the originals. */
Index: apr/include/apr.hnw
===================================================================
--- apr.orig/include/apr.hnw
+++ apr/include/apr.hnw
@@ -236,11 +236,11 @@ typedef unsigned char apr_byte_t;
typedef short apr_int16_t;
typedef unsigned short apr_uint16_t;
-
+
typedef int apr_int32_t;
typedef unsigned int apr_uint32_t;
-
-typedef long long apr_int64_t;
+
+typedef long long apr_int64_t;
typedef unsigned long long apr_uint64_t;
typedef size_t apr_size_t;
@@ -270,6 +270,60 @@ typedef size_t apr_socklen_t
#define APR_INT64_C(val) (val##LL)
#define APR_UINT64_C(val) (val##ULL)
+#ifdef INT16_MIN
+#define APR_INT16_MIN INT16_MIN
+#else
+#define APR_INT16_MIN (-0x7fff - 1)
+#endif
+
+#ifdef INT16_MAX
+#define APR_INT16_MAX INT16_MAX
+#else
+#define APR_INT16_MAX (0x7fff)
+#endif
+
+#ifdef UINT16_MAX
+#define APR_UINT16_MAX UINT16_MAX
+#else
+#define APR_UINT16_MAX (0xffff)
+#endif
+
+#ifdef INT32_MIN
+#define APR_INT32_MIN INT32_MIN
+#else
+#define APR_INT32_MIN (-0x7fffffff - 1)
+#endif
+
+#ifdef INT32_MAX
+#define APR_INT32_MAX INT32_MAX
+#else
+#define APR_INT32_MAX 0x7fffffff
+#endif
+
+#ifdef UINT32_MAX
+#define APR_UINT32_MAX UINT32_MAX
+#else
+#define APR_UINT32_MAX (0xffffffffU)
+#endif
+
+#ifdef INT64_MIN
+#define APR_INT64_MIN INT64_MIN
+#else
+#define APR_INT64_MIN (APR_INT64_C(-0x7fffffffffffffff) - 1)
+#endif
+
+#ifdef INT64_MAX
+#define APR_INT64_MAX INT64_MAX
+#else
+#define APR_INT64_MAX APR_INT64_C(0x7fffffffffffffff)
+#endif
+
+#ifdef UINT64_MAX
+#define APR_UINT64_MAX UINT64_MAX
+#else
+#define APR_UINT64_MAX APR_UINT64_C(0xffffffffffffffff)
+#endif
+
/* PROC mutex is a GLOBAL mutex on Netware */
#define APR_PROC_MUTEX_IS_GLOBAL 1