Bug 634793: Add OpenBSD and Android to the list of exceptions to how NSPR NSPR_4_9_5_BETA1
authorwtc%google.com
Fri, 07 Dec 2012 21:13:41 +0000
changeset 4429 f2c09c2b9db0514f7eda97d8881bd1c93ab4ab70
parent 4428 ff1098348fdec44206812af0ddc45b1c21284ac7
child 4430 83f95f5f5aad94d50893201d3e3a399eed7db171
push idunknown
push userunknown
push dateunknown
bugs634793
Bug 634793: Add OpenBSD and Android to the list of exceptions to how NSPR normally defines PRInt64 and PRUint64. From now on, NSPR's exact-width integer types will match the exact-width integer types defined in <stdint.h>. r=ehsan. Modified Files: prdepend.h prlong.h prtypes.h
config/prdepend.h
pr/include/prlong.h
pr/include/prtypes.h
--- a/config/prdepend.h
+++ b/config/prdepend.h
@@ -5,8 +5,9 @@
 
 /*
  * A dummy header file that is a dependency for all the object files.
  * Used to force a full recompilation of NSPR in Mozilla's Tinderbox
  * depend builds.  See comments in rules.mk.
  */
 
 #error "Do not include this header file."
+
--- a/pr/include/prlong.h
+++ b/pr/include/prlong.h
@@ -30,17 +30,17 @@ PR_BEGIN_EXTERN_C
 NSPR_API(PRInt64) LL_MaxInt(void);
 NSPR_API(PRInt64) LL_MinInt(void);
 NSPR_API(PRInt64) LL_Zero(void);
 NSPR_API(PRUint64) LL_MaxUint(void);
 
 #if defined(HAVE_LONG_LONG)
 
 /* Keep this in sync with prtypes.h. */
-#if PR_BYTES_PER_LONG == 8 && !defined(__APPLE__)
+#if PR_BYTES_PER_LONG == 8 && !defined(PR_ALTERNATE_INT64_TYPEDEF)
 #define LL_MAXINT   9223372036854775807L
 #define LL_MININT   (-LL_MAXINT - 1L)
 #define LL_ZERO     0L
 #define LL_MAXUINT  18446744073709551615UL
 #define LL_INIT(hi, lo)  ((hi ## L << 32) + lo ## L)
 #elif defined(WIN32) && !defined(__GNUC__)
 #define LL_MAXINT   9223372036854775807i64
 #define LL_MININT   (-LL_MAXINT - 1i64)
--- a/pr/include/prtypes.h
+++ b/pr/include/prtypes.h
@@ -200,16 +200,46 @@
 ** MACROS:      PR_ARRAY_SIZE
 ** DESCRIPTION:
 **  The number of elements in an array.
 ***********************************************************************/
 #define PR_ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
 
 PR_BEGIN_EXTERN_C
 
+/*
+** Starting in NSPR 4.9.5, NSPR's exact-width integer types should match
+** the exact-width integer types defined in <stdint.h>. This allows sloppy
+** code to use PRInt{N} and int{N}_t interchangeably.
+**
+** The 8-bit and 16-bit integer types can only be defined using char and
+** short. All platforms define the 32-bit integer types using int. So only
+** the 64-bit integer types could be defined differently.
+**
+** NSPR's original strategy was to use the "shortest" 64-bit integer type:
+** if long is 64-bit, then prefer it over long long. This strategy is also
+** used by Linux/glibc, FreeBSD, and NetBSD.
+**
+** Other platforms use a different strategy: simply define the 64-bit
+** integer types using long long. We define the PR_ALTERNATE_INT64_TYPEDEF
+** macro on these platforms. Note that PR_ALTERNATE_INT64_TYPEDEF is for
+** internal use by NSPR headers only. Do not define or test this macro in
+** your code.
+**
+** NOTE: NSPR can't use <stdint.h> because C99 requires C++ code to define
+** __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS to make all the macros
+** defined in <stdint.h> available. This strange requirement is gone in
+** C11. When most platforms ignore this C99 requirement, NSPR will be able
+** to use <stdint.h>. A patch to do that is in NSPR bug 634793.
+*/
+
+#if defined(__APPLE__) || defined(__ANDROID__) || defined(__OpenBSD__)
+#define PR_ALTERNATE_INT64_TYPEDEF
+#endif
+
 /************************************************************************
 ** TYPES:       PRUint8
 **              PRInt8
 ** DESCRIPTION:
 **  The int8 types are known to be 8 bits each. There is no type that
 **      is equivalent to a plain "char".
 ************************************************************************/
 #if PR_BYTES_PER_BYTE == 1
@@ -326,22 +356,17 @@ typedef long PRInt32;
 ** MACROS:      PR_INT64_MAX
 **              PR_INT64_MIN
 **              PR_UINT64_MAX
 ** DESCRIPTION:
 **  The maximum and minimum values of a PRInt64 or PRUint64.
 ************************************************************************/
 #ifdef HAVE_LONG_LONG
 /* Keep this in sync with prlong.h. */
-/*
- * On 64-bit Mac OS X, uint64 needs to be defined as unsigned long long to
- * match uint64_t, otherwise our uint64 typedef conflicts with the uint64
- * typedef in cssmconfig.h, which CoreServices.h includes indirectly.
- */
-#if PR_BYTES_PER_LONG == 8 && !defined(__APPLE__)
+#if PR_BYTES_PER_LONG == 8 && !defined(PR_ALTERNATE_INT64_TYPEDEF)
 typedef long PRInt64;
 typedef unsigned long PRUint64;
 #define PR_INT64(x)  x ## L
 #define PR_UINT64(x) x ## UL
 #elif defined(WIN32) && !defined(__GNUC__)
 typedef __int64  PRInt64;
 typedef unsigned __int64 PRUint64;
 #define PR_INT64(x)  x ## i64