fixup commit for branch 'GECKO190_20090824_RELBRANCH' GECKO190_20090824_RELBRANCH
authorcvs2hg
Sat, 13 Jun 2009 13:53:59 +0000
branchGECKO190_20090824_RELBRANCH
changeset 4134 20bdd860b54bd271637b6479cd6a4c8d1d479d9e
parent 4019 cf3860d376be8c0c25e767c727020dd85fed9a20
push idunknown
push userunknown
push dateunknown
fixup commit for branch 'GECKO190_20090824_RELBRANCH'
admin/repackage.sh
config/rules.mk
configure
configure.in
lib/libc/include/plbase64.h
lib/libc/src/base64.c
lib/libc/src/strlen.c
pr/include/md/_darwin.h
pr/include/md/_linux.cfg
pr/include/md/_netbsd.cfg
pr/include/md/_netbsd.h
pr/include/prinit.h
pr/include/prlong.h
pr/include/prtypes.h
pr/src/linking/prlink.c
pr/src/md/windows/ntinrval.c
pr/src/misc/Makefile.in
pr/src/misc/prdtoa.c
pr/src/misc/prtime.c
pr/src/pthreads/ptio.c
pr/src/pthreads/ptsynch.c
pr/tests/Makefile.in
pr/tests/parsetm.c
pr/tests/runtests.pl
pr/tests/runtests.sh
pr/tests/vercheck.c
--- a/admin/repackage.sh
+++ b/admin/repackage.sh
@@ -59,20 +59,20 @@
 # Note! Files written with Gnu tar are not readable by some non-Gnu
 # versions. Sun, in particular.
 # 
 # 
 # 
 # 
 # ------------------------------------------------------------------
 
-FROMTOP=/share/builds/components/nspr20/v4.7.4
-TOTOP=./v4.7.4
-NSPRDIR=nspr-4.7.4
-SOURCETAG=NSPR_4_7_4_RTM
+FROMTOP=/share/builds/components/nspr20/v4.7.5
+TOTOP=./v4.7.5
+NSPRDIR=nspr-4.7.5
+SOURCETAG=NSPR_4_7_5_RTM
 
 #
 # enumerate Unix object directories on /s/b/c
 UNIX_OBJDIRS="
 HP-UXB.11.11_64_DBG.OBJ
 HP-UXB.11.11_64_OPT.OBJ
 HP-UXB.11.11_DBG.OBJ
 HP-UXB.11.11_OPT.OBJ
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -396,41 +396,42 @@ NEED_ABSOLUTE_PATH = 1
 endif
 
 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
 NEED_ABSOLUTE_PATH = 1
 endif
 
 ifdef NEED_ABSOLUTE_PATH
 PWD := $(shell pwd)
-abspath = $(if $(findstring :,$(1)),$(1),$(if $(filter /%,$(1)),$(1),$(PWD)/$(1)))
+# The quotes allow absolute paths to contain spaces.
+pr_abspath = "$(if $(findstring :,$(1)),$(1),$(if $(filter /%,$(1)),$(1),$(PWD)/$(1)))"
 endif
 
 $(OBJDIR)/%.$(OBJ_SUFFIX): %.cpp
 	@$(MAKE_OBJDIR)
 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
-	$(CCC) -Fo$@ -c $(CCCFLAGS) $(call abspath,$<)
+	$(CCC) -Fo$@ -c $(CCCFLAGS) $(call pr_abspath,$<)
 else
 ifdef NEED_ABSOLUTE_PATH
-	$(CCC) -o $@ -c $(CCCFLAGS) $(call abspath,$<)
+	$(CCC) -o $@ -c $(CCCFLAGS) $(call pr_abspath,$<)
 else
 	$(CCC) -o $@ -c $(CCCFLAGS) $<
 endif
 endif
 
 WCCFLAGS1 = $(subst /,\\,$(CFLAGS))
 WCCFLAGS2 = $(subst -I,-i=,$(WCCFLAGS1))
 WCCFLAGS3 = $(subst -D,-d,$(WCCFLAGS2))
 $(OBJDIR)/%.$(OBJ_SUFFIX): %.c
 	@$(MAKE_OBJDIR)
 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
-	$(CC) -Fo$@ -c $(CFLAGS) $(call abspath,$<)
+	$(CC) -Fo$@ -c $(CFLAGS) $(call pr_abspath,$<)
 else
 ifdef NEED_ABSOLUTE_PATH
-	$(CC) -o $@ -c $(CFLAGS) $(call abspath,$<)
+	$(CC) -o $@ -c $(CFLAGS) $(call pr_abspath,$<)
 else
 	$(CC) -o $@ -c $(CFLAGS) $<
 endif
 endif
 
 
 $(OBJDIR)/%.$(OBJ_SUFFIX): %.s
 	@$(MAKE_OBJDIR)
--- a/configure
+++ b/configure
@@ -684,17 +684,17 @@ echo "$ac_t""$build" 1>&6
 test "$host_alias" != "$target_alias" &&
   test "$program_prefix$program_suffix$program_transform_name" = \
     NONENONEs,x,x, &&
   program_prefix=${target_alias}-
 
 
 MOD_MAJOR_VERSION=4
 MOD_MINOR_VERSION=7
-MOD_PATCH_VERSION=4
+MOD_PATCH_VERSION=5
 NSPR_MODNAME=nspr20
 _HAVE_PTHREADS=
 USE_PTHREADS=
 USE_USER_PTHREADS=
 USE_NSPR_THREADS=
 USE_N32=
 USE_64=
 USE_CPLUS=
--- a/configure.in
+++ b/configure.in
@@ -45,17 +45,17 @@ AC_INIT(config/libc_r.h)
 AC_CONFIG_AUX_DIR(${srcdir}/build/autoconf)
 AC_CANONICAL_SYSTEM
 
 dnl ========================================================
 dnl = Defaults
 dnl ========================================================
 MOD_MAJOR_VERSION=4
 MOD_MINOR_VERSION=7
-MOD_PATCH_VERSION=4
+MOD_PATCH_VERSION=5
 NSPR_MODNAME=nspr20
 _HAVE_PTHREADS=
 USE_PTHREADS=
 USE_USER_PTHREADS=
 USE_NSPR_THREADS=
 USE_N32=
 USE_64=
 USE_CPLUS=
--- a/lib/libc/include/plbase64.h
+++ b/lib/libc/include/plbase64.h
@@ -52,16 +52,20 @@ PR_BEGIN_EXTERN_C
  * is used to determine the source length.  If the "dest" parameter is not
  * null, it is assumed to point to a buffer of sufficient size (which may be
  * calculated: ((srclen + 2)/3)*4) into which the encoded data is placed 
  * (without any termination).  If the "dest" parameter is null, a buffer is
  * allocated from the heap to hold the encoded data, and the result *will*
  * be terminated with an extra null character.  It is the caller's 
  * responsibility to free the result when it is allocated.  A null is returned 
  * if the allocation fails.
+ *
+ * NOTE: when calculating ((srclen + 2)/3)*4), first ensure that
+ *     srclen <= (PR_UINT32_MAX/4) * 3
+ * to avoid PRUint32 overflow.
  */
 
 PR_EXTERN(char *)
 PL_Base64Encode
 (
     const char *src,
     PRUint32    srclen,
     char       *dest
@@ -78,16 +82,22 @@ PL_Base64Encode
  * length.  If the "dest" parameter is not null, it is assumed to point to
  * a buffer of sufficient size (which may be calculated: (srclen * 3)/4
  * when srclen includes the '=' characters) into which the decoded data
  * is placed (without any termination).  If the "dest" parameter is null,
  * a buffer is allocated from the heap to hold the decoded data, and the
  * result *will* be terminated with an extra null character.  It is the
  * caller's responsibility to free the result when it is allocated.  A null
  * is retuned if the allocation fails, or if the source is not well-coded.
+ *
+ * NOTE: when calculating (srclen * 3)/4, first ensure that 
+ *     srclen <= PR_UINT32_MAX/3
+ * to avoid PRUint32 overflow.  Alternatively, calculate
+ *     (srclen/4) * 3 + ((srclen%4) * 3)/4
+ * which is equivalent but doesn't overflow for any value of srclen.
  */
 
 PR_EXTERN(char *)
 PL_Base64Decode
 (
     const char *src,
     PRUint32    srclen,
     char       *dest
--- a/lib/libc/src/base64.c
+++ b/lib/libc/src/base64.c
@@ -33,17 +33,18 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "plbase64.h"
 #include "prlog.h" /* For PR_NOT_REACHED */
 #include "prmem.h" /* for malloc / PR_MALLOC */
-#include "plstr.h" /* for PL_strlen */
+
+#include <string.h> /* for strlen */
 
 static unsigned char *base = (unsigned char *)"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
 static void
 encode3to4
 (
     const unsigned char    *src,
     unsigned char          *dest
@@ -145,22 +146,34 @@ PL_Base64Encode
 (
     const char *src,
     PRUint32    srclen,
     char       *dest
 )
 {
     if( 0 == srclen )
     {
-        srclen = PL_strlen(src);
+        size_t len = strlen(src);
+        srclen = len;
+        /* Detect truncation. */
+        if( srclen != len )
+        {
+            return (char *)0;
+        }
     }
 
     if( (char *)0 == dest )
     {
-        PRUint32 destlen = ((srclen + 2)/3) * 4;
+        PRUint32 destlen;
+        /* Ensure all PRUint32 values stay within range. */
+        if( srclen > (PR_UINT32_MAX/4) * 3 )
+        {
+            return (char *)0;
+        }
+        destlen = ((srclen + 2)/3) * 4;
         dest = (char *)PR_MALLOC(destlen + 1);
         if( (char *)0 == dest )
         {
             return (char *)0;
         }
         dest[ destlen ] = (char)0; /* null terminate */
     }
 
@@ -378,17 +391,23 @@ PL_Base64Decode
 
     if( (char *)0 == src )
     {
         return (char *)0;
     }
 
     if( 0 == srclen )
     {
-        srclen = PL_strlen(src);
+        size_t len = strlen(src);
+        srclen = len;
+        /* Detect truncation. */
+        if( srclen != len )
+        {
+            return (char *)0;
+        }
     }
 
     if( srclen && (0 == (srclen & 3)) )
     {
         if( (char)'=' == src[ srclen-1 ] )
         {
             if( (char)'=' == src[ srclen-2 ] )
             {
@@ -398,17 +417,18 @@ PL_Base64Decode
             {
                 srclen -= 1;
             }
         }
     }
 
     if( (char *)0 == dest )
     {
-        PRUint32 destlen = ((srclen * 3) / 4);
+        /* The following computes ((srclen * 3) / 4) without overflow. */
+        PRUint32 destlen = (srclen / 4) * 3 + ((srclen % 4) * 3) / 4;
         dest = (char *)PR_MALLOC(destlen + 1);
         if( (char *)0 == dest )
         {
             return (char *)0;
         }
         dest[ destlen ] = (char)0; /* null terminate */
         allocated = PR_TRUE;
     }
--- a/lib/libc/src/strlen.c
+++ b/lib/libc/src/strlen.c
@@ -48,17 +48,20 @@ PL_strlen(const char *str)
     if( (const char *)0 == str ) return 0;
 
     l = strlen(str);
 
     /* error checking in case we have a 64-bit platform -- make sure
      * we don't have ultra long strings that overflow an int32
      */ 
     if( sizeof(PRUint32) < sizeof(size_t) )
-        PR_ASSERT(l < 2147483647);
+    {
+        if( l > PR_INT32_MAX )
+            PR_Assert("l <= PR_INT32_MAX", __FILE__, __LINE__);
+    }
 
     return (PRUint32)l;
 }
 
 PR_IMPLEMENT(PRUint32)
 PL_strnlen(const char *str, PRUint32 max)
 {
     register const char *s;
--- a/pr/include/md/_darwin.h
+++ b/pr/include/md/_darwin.h
@@ -67,16 +67,17 @@
 #ifdef __x86_64__
 #define USE_DLFCN
 #else
 #define USE_MACH_DYLD
 #endif
 #define _PR_HAVE_SOCKADDR_LEN  
 #define _PR_STAT_HAS_ST_ATIMESPEC
 #define _PR_HAVE_LARGE_OFF_T
+#define _PR_HAVE_SYSV_SEMAPHORES
 #define PR_HAVE_SYSV_NAMED_SHARED_MEMORY
 
 #define _PR_INET6
 /*
  * I'd prefer to use getipnodebyname and getipnodebyaddr but the
  * getipnodebyname(3) man page on Mac OS X 10.2 says they are not
  * thread-safe.  AI_V4MAPPED|AI_ADDRCONFIG doesn't work either.
  */
--- a/pr/include/md/_linux.cfg
+++ b/pr/include/md/_linux.cfg
@@ -516,18 +516,25 @@
 #define PR_ALIGN_OF_POINTER 4
 #define PR_ALIGN_OF_WORD    4
 
 #define PR_BYTES_PER_WORD_LOG2   2
 #define PR_BYTES_PER_DWORD_LOG2  3
 
 #elif defined(__arm__)
 
+#ifdef __ARMEB__
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+#elif defined(__ARMEL__)
 #define IS_LITTLE_ENDIAN 1
 #undef  IS_BIG_ENDIAN
+#else
+#error "Unknown ARM endianness."
+#endif
 
 #define PR_BYTES_PER_BYTE   1
 #define PR_BYTES_PER_SHORT  2
 #define PR_BYTES_PER_INT    4
 #define PR_BYTES_PER_INT64  8
 #define PR_BYTES_PER_LONG   4
 #define PR_BYTES_PER_FLOAT  4
 #define PR_BYTES_PER_DOUBLE 8
--- a/pr/include/md/_netbsd.cfg
+++ b/pr/include/md/_netbsd.cfg
@@ -47,17 +47,18 @@
 #endif
 
 #define PR_AF_INET6 24  /* same as AF_INET6 */
 
 #ifndef HAVE_LONG_LONG
 #define HAVE_LONG_LONG
 #endif
 
-#if defined(__i386__) || defined(__arm32__) || defined(__MIPSEL__)
+#if defined(__i386__) || defined(__arm32__) || defined(__ARMEL__) || \
+	defined(__MIPSEL__)
 
 #define IS_LITTLE_ENDIAN 1
 #undef  IS_BIG_ENDIAN
 #undef	HAVE_ALIGNED_DOUBLES
 #undef	HAVE_ALIGNED_LONGLONGS
 
 #define PR_BYTES_PER_BYTE   1
 #define PR_BYTES_PER_SHORT  2
@@ -92,22 +93,68 @@
 #define PR_ALIGN_OF_SHORT   2
 #define PR_ALIGN_OF_INT     4
 #define PR_ALIGN_OF_LONG    4
 #define PR_ALIGN_OF_INT64   4
 #define PR_ALIGN_OF_FLOAT   4
 #define PR_ALIGN_OF_DOUBLE  4
 #define PR_ALIGN_OF_POINTER 4
 
-#elif defined(__sparc__) || defined(__MIPSEB__)
+#elif defined(__sparc_v9__)
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+#define HAVE_ALIGNED_DOUBLES
+#define HAVE_ALIGNED_LONGLONGS
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+#define PR_BYTES_PER_WORD_LOG2   3
+#define PR_BYTES_PER_DWORD_LOG2  3
 
-#undef IS_LITTLE_ENDIAN
-#define  IS_BIG_ENDIAN 1
-#define  HAVE_ALIGNED_DOUBLES
-#define  HAVE_ALIGNED_LONGLONGS
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8 
+#define PR_ALIGN_OF_FLOAT   4 
+#define PR_ALIGN_OF_DOUBLE  8 
+#define PR_ALIGN_OF_POINTER 8 
+
+#elif defined(__sparc__) || defined(__MIPSEB__) || defined(__ARMEB__)
+
+#undef  IS_LITTLE_ENDIAN
+#define IS_BIG_ENDIAN 1
+#define HAVE_ALIGNED_DOUBLES
+#define HAVE_ALIGNED_LONGLONGS
 
 #define PR_BYTES_PER_BYTE   1
 #define PR_BYTES_PER_SHORT  2
 #define PR_BYTES_PER_INT    4
 #define PR_BYTES_PER_INT64  8
 #define PR_BYTES_PER_LONG   4
 #define PR_BYTES_PER_FLOAT  4
 #define PR_BYTES_PER_DOUBLE 8
@@ -183,16 +230,63 @@
 #define PR_ALIGN_OF_INT64   8
 #define PR_ALIGN_OF_FLOAT   4
 #define PR_ALIGN_OF_DOUBLE  8
 #define PR_ALIGN_OF_POINTER 8
 
 #define PR_BYTES_PER_WORD_LOG2  3
 #define PR_BYTES_PER_DWORD_LOG2 3
 
+#elif defined(__amd64__)
+#define IS_LITTLE_ENDIAN 1
+#undef  IS_BIG_ENDIAN
+#define HAVE_ALIGNED_DOUBLES
+#define HAVE_ALIGNED_LONGLONGS
+#define IS_64
+
+#define PR_BYTES_PER_BYTE   1
+#define PR_BYTES_PER_SHORT  2
+#define PR_BYTES_PER_INT    4
+#define PR_BYTES_PER_INT64  8
+#define PR_BYTES_PER_LONG   8
+#define PR_BYTES_PER_FLOAT  4
+#define PR_BYTES_PER_DOUBLE 8
+#define PR_BYTES_PER_WORD   8
+#define PR_BYTES_PER_DWORD  8
+
+#define PR_BITS_PER_BYTE    8
+#define PR_BITS_PER_SHORT   16
+#define PR_BITS_PER_INT     32
+#define PR_BITS_PER_INT64   64
+#define PR_BITS_PER_LONG    64
+#define PR_BITS_PER_FLOAT   32
+#define PR_BITS_PER_DOUBLE  64
+#define PR_BITS_PER_WORD    64
+
+#define PR_BITS_PER_BYTE_LOG2   3
+#define PR_BITS_PER_SHORT_LOG2  4
+#define PR_BITS_PER_INT_LOG2    5
+#define PR_BITS_PER_INT64_LOG2  6
+#define PR_BITS_PER_LONG_LOG2   6
+#define PR_BITS_PER_FLOAT_LOG2  5
+#define PR_BITS_PER_DOUBLE_LOG2 6
+#define PR_BITS_PER_WORD_LOG2   6
+
+#define PR_ALIGN_OF_SHORT   2
+#define PR_ALIGN_OF_INT     4
+#define PR_ALIGN_OF_LONG    8
+#define PR_ALIGN_OF_INT64   8
+#define PR_ALIGN_OF_FLOAT   4
+#define PR_ALIGN_OF_DOUBLE  8
+#define PR_ALIGN_OF_POINTER 8
+#define PR_ALIGN_OF_WORD    8
+
+#define PR_BYTES_PER_WORD_LOG2  3
+#define PR_BYTES_PER_DWORD_LOG2 3
+
 #elif defined(__powerpc__) || defined(__m68k__)
 
 #undef  IS_LITTLE_ENDIAN
 #define IS_BIG_ENDIAN    1
 #undef	HAVE_ALIGNED_DOUBLES
 #undef	HAVE_ALIGNED_LONGLONGS
 
 #define PR_BYTES_PER_BYTE   1
--- a/pr/include/md/_netbsd.h
+++ b/pr/include/md/_netbsd.h
@@ -42,16 +42,18 @@
 #include <sys/param.h>  /* for __NetBSD_Version__ */
 
 #define PR_LINKER_ARCH	"netbsd"
 #define _PR_SI_SYSNAME  "NetBSD"
 #if defined(__i386__)
 #define _PR_SI_ARCHITECTURE "x86"
 #elif defined(__alpha__)
 #define _PR_SI_ARCHITECTURE "alpha"
+#elif defined(__amd64__)
+#define _PR_SI_ARCHITECTURE "amd64"
 #elif defined(__m68k__)
 #define _PR_SI_ARCHITECTURE "m68k"
 #elif defined(__powerpc__)
 #define _PR_SI_ARCHITECTURE "powerpc"
 #elif defined(__sparc_v9__)
 #define _PR_SI_ARCHITECTURE "sparc64"
 #elif defined(__sparc__)
 #define _PR_SI_ARCHITECTURE "sparc"
@@ -87,22 +89,16 @@
 #if __NetBSD_Version__ >= 105000000
 #define _PR_INET6
 #define _PR_HAVE_INET_NTOP
 #define _PR_HAVE_GETHOSTBYNAME2
 #define _PR_HAVE_GETADDRINFO
 #define _PR_INET6_PROBE
 #endif
 
-#if __NetBSD_Version__ >= 106370000
-/* NetBSD 1.6ZK */
-#define _PR_HAVE_GETPROTO_R
-#define _PR_HAVE_GETPROTO_R_INT
-#endif
-
 #define USE_SETJMP
 
 #ifndef _PR_PTHREADS
 #include <setjmp.h>
 
 #define PR_CONTEXT_TYPE	sigjmp_buf
 
 #define CONTEXT(_th) ((_th)->md.context)
@@ -238,16 +234,20 @@ struct _MDCPU {
 #define _MD_INIT_THREAD                 _MD_InitializeThread
 #define _MD_EXIT_THREAD(thread)
 #define _MD_SUSPEND_THREAD(thread)      _MD_suspend_thread
 #define _MD_RESUME_THREAD(thread)       _MD_resume_thread
 #define _MD_CLEAN_THREAD(_thread)
 
 #endif /* ! _PR_PTHREADS */
 
+extern void _MD_EarlyInit(void);
+extern PRIntervalTime _PR_UNIX_GetInterval(void);
+extern PRIntervalTime _PR_UNIX_TicksPerSecond(void);
+
 #define _MD_EARLY_INIT                  _MD_EarlyInit
 #define _MD_FINAL_INIT			_PR_UnixInit
 #define _MD_GET_INTERVAL                  _PR_UNIX_GetInterval
 #define _MD_INTERVAL_PER_SEC              _PR_UNIX_TicksPerSecond
 
 /*
  * We wrapped the select() call.  _MD_SELECT refers to the built-in,
  * unwrapped version.
--- a/pr/include/prinit.h
+++ b/pr/include/prinit.h
@@ -58,21 +58,21 @@ PR_BEGIN_EXTERN_C
 /*
 ** NSPR's version is used to determine the likelihood that the version you
 ** used to build your component is anywhere close to being compatible with
 ** what is in the underlying library.
 **
 ** The format of the version string is
 **     "<major version>.<minor version>[.<patch level>] [<Beta>]"
 */
-#define PR_VERSION  "4.7.4 Beta"
+#define PR_VERSION  "4.7.5"
 #define PR_VMAJOR   4
 #define PR_VMINOR   7
-#define PR_VPATCH   4
-#define PR_BETA     PR_TRUE
+#define PR_VPATCH   5
+#define PR_BETA     PR_FALSE
 
 /*
 ** PRVersionCheck
 **
 ** The basic signature of the function that is called to provide version
 ** checking. The result will be a boolean that indicates the likelihood
 ** that the underling library will perform as the caller expects.
 **
--- a/pr/include/prlong.h
+++ b/pr/include/prlong.h
@@ -72,17 +72,18 @@ PRUint64 __pascal __loadds __export
 NSPR_API(PRInt64) LL_MaxInt(void);
 NSPR_API(PRInt64) LL_MinInt(void);
 NSPR_API(PRInt64) LL_Zero(void);
 NSPR_API(PRUint64) LL_MaxUint(void);
 #endif
 
 #if defined(HAVE_LONG_LONG)
 
-#if PR_BYTES_PER_LONG == 8
+/* Keep this in sync with prtypes.h. */
+#if PR_BYTES_PER_LONG == 8 && !defined(__APPLE__)
 #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(WIN16)) && !defined(__GNUC__)
 #define LL_MAXINT   9223372036854775807i64
 #define LL_MININT   (-LL_MAXINT - 1i64)
--- a/pr/include/prtypes.h
+++ b/pr/include/prtypes.h
@@ -382,17 +382,23 @@ typedef long PRInt32;
 ** DESCRIPTION:
 **  The int64 types are known to be 64 bits each. Care must be used when
 **      declaring variables of type PRUint64 or PRInt64. Different hardware
 **      architectures and even different compilers have varying support for
 **      64 bit values. The only guaranteed portability requires the use of
 **      the LL_ macros (see prlong.h).
 ************************************************************************/
 #ifdef HAVE_LONG_LONG
-#if PR_BYTES_PER_LONG == 8
+/* 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__)
 typedef long PRInt64;
 typedef unsigned long PRUint64;
 #elif defined(WIN16)
 typedef __int64 PRInt64;
 typedef unsigned __int64 PRUint64;
 #elif defined(WIN32) && !defined(__GNUC__)
 typedef __int64  PRInt64;
 typedef unsigned __int64 PRUint64;
--- a/pr/src/linking/prlink.c
+++ b/pr/src/linking/prlink.c
@@ -218,41 +218,35 @@ static LoadLibraryWFn loadLibraryW = Loa
 
 #ifdef WIN32
 static int pr_ConvertUTF16toUTF8(LPCWSTR wname, LPSTR name, int len);
 #endif
 
 /************************************************************************/
 
 #if !defined(USE_DLFCN) && !defined(HAVE_STRERROR)
-static char* errStrBuf = NULL;
 #define ERR_STR_BUF_LENGTH    20
-static char* errno_string(PRIntn oserr)
-{
-    if (errStrBuf == NULL)
-        errStrBuf = PR_MALLOC(ERR_STR_BUF_LENGTH);
-    PR_snprintf(errStrBuf, ERR_STR_BUF_LENGTH, "error %d", oserr);
-    return errStrBuf;
-}
 #endif
 
 static void DLLErrorInternal(PRIntn oserr)
 /*
 ** This whole function, and most of the code in this file, are run
 ** with a big hairy lock wrapped around it. Not the best of situations,
 ** but will eventually come up with the right answer.
 */
 {
     const char *error = NULL;
 #ifdef USE_DLFCN
     error = dlerror();  /* $$$ That'll be wrong some of the time - AOF */
 #elif defined(HAVE_STRERROR)
     error = strerror(oserr);  /* this should be okay */
 #else
-    error = errno_string(oserr);
+    char errStrBuf[ERR_STR_BUF_LENGTH];
+    PR_snprintf(errStrBuf, sizeof(errStrBuf), "error %d", oserr);
+    error = errStrBuf;
 #endif
     if (NULL != error)
         PR_SetErrorText(strlen(error), error);
 }  /* DLLErrorInternal */
 
 void _PR_InitLinker(void)
 {
     PRLibrary *lm = NULL;
@@ -377,20 +371,16 @@ void _PR_ShutdownLinker(void)
     
     PR_DestroyMonitor(pr_linker_lock);
     pr_linker_lock = NULL;
 
     if (_pr_currentLibPath) {
         free(_pr_currentLibPath);
         _pr_currentLibPath = NULL;
     }
-
-#if !defined(USE_DLFCN) && !defined(HAVE_STRERROR)
-    PR_DELETE(errStrBuf);
-#endif
 }
 #endif
 
 /******************************************************************************/
 
 PR_IMPLEMENT(PRStatus) PR_SetLibraryPath(const char *path)
 {
     PRStatus rv = PR_SUCCESS;
--- a/pr/src/md/windows/ntinrval.c
+++ b/pr/src/md/windows/ntinrval.c
@@ -37,43 +37,24 @@
 
 /*
  * NT interval timers
  *
  */
 
 #include "primpl.h"
 
-#ifdef WINCE
-typedef DWORD (*IntervalFuncType)(void);
-static IntervalFuncType intervalFunc;
-#endif
-
 void
 _PR_MD_INTERVAL_INIT()
 {
-#ifdef WINCE
-    HMODULE mmtimerlib = LoadLibraryW(L"mmtimer.dll");  /* XXX leaked! */
-    if (mmtimerlib) {
-        intervalFunc = (IntervalFuncType)GetProcAddress(mmtimerlib,
-                                                        "timeGetTime");
-    } else {
-        intervalFunc = &GetTickCount;
-    }
-#endif
 }
 
 PRIntervalTime 
 _PR_MD_GET_INTERVAL()
 {
-    /* milliseconds since system start */
-#ifdef WINCE
-    return (*intervalFunc)();
-#else
-    return timeGetTime();
-#endif
+    return timeGetTime();  /* milliseconds since system start */
 }
 
 PRIntervalTime 
 _PR_MD_INTERVAL_PER_SEC()
 {
     return 1000;
 }
--- a/pr/src/misc/Makefile.in
+++ b/pr/src/misc/Makefile.in
@@ -89,19 +89,19 @@ include $(topsrcdir)/config/rules.mk
 # Prevent floating point errors caused by MSVC 6.0 Processor Pack
 # optimizations (bug 207421).  This disables optimizations that
 # could change the precision of floating-point calculations for
 # this single compilation unit.
 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
 $(OBJDIR)/prdtoa.$(OBJ_SUFFIX): prdtoa.c
 	@$(MAKE_OBJDIR)
 ifeq (,$(filter-out 1100 1200 1300 1310,$(MSC_VER)))
-	$(CC) -Fo$@ -c $(CFLAGS) -Op $(call abspath,$<)
+	$(CC) -Fo$@ -c $(CFLAGS) -Op $(call pr_abspath,$<)
 else
-	$(CC) -Fo$@ -c $(CFLAGS) -fp:precise $(call abspath,$<)
+	$(CC) -Fo$@ -c $(CFLAGS) -fp:precise $(call pr_abspath,$<)
 endif
 endif
 
 #
 # Generate prerr.h, prerr.c, and prerr.properties from prerr.et.
 #
 build_prerr:
 	cd $(srcdir); $(PERL) compile-et.pl prerr.et
--- a/pr/src/misc/prdtoa.c
+++ b/pr/src/misc/prdtoa.c
@@ -212,21 +212,16 @@ void _PR_CleanupDtoa(void)
  *	You must also invoke freedtoa(s) to free the value s returned by
  *	dtoa.  You may do so whether or not MULTIPLE_THREADS is #defined.
  * #define NO_IEEE_Scale to disable new (Feb. 1997) logic in strtod that
  *	avoids underflows on inputs whose result does not underflow.
  *	If you #define NO_IEEE_Scale on a machine that uses IEEE-format
  *	floating-point numbers and flushes underflows to zero rather
  *	than implementing gradual underflow, then you must also #define
  *	Sudden_Underflow.
- * #define YES_ALIAS to permit aliasing certain double values with
- *	arrays of ULongs.  This leads to slightly better code with
- *	some compilers and was always used prior to 19990916, but it
- *	is not strictly legal and can cause trouble with aggressively
- *	optimizing compilers (e.g., gcc 2.95.1 under -O2).
  * #define USE_LOCALE to use the current locale's decimal_point value.
  * #define SET_INEXACT if IEEE arithmetic is being used and extra
  *	computation should be done to set the inexact flag when the
  *	result is inexact and avoid setting inexact when the result
  *	is exact.  In this case, dtoa.c must be compiled in
  *	an environment, perhaps provided by #include "dtoa.c" in a
  *	suitable wrapper, that defines two functions,
  *		int get_inexact(void);
@@ -353,34 +348,23 @@ extern "C" {
 #endif
 
 #if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(IEEE_ARM) + defined(VAX) + defined(IBM) != 1
 Exactly one of IEEE_8087, IEEE_MC68k, IEEE_ARM, VAX, or IBM should be defined.
 #endif
 
 typedef union { double d; ULong L[2]; } U;
 
-#ifdef YES_ALIAS
-#define dval(x) x
+#define dval(x) (x).d
 #ifdef IEEE_8087
-#define word0(x) ((ULong *)&x)[1]
-#define word1(x) ((ULong *)&x)[0]
+#define word0(x) (x).L[1]
+#define word1(x) (x).L[0]
 #else
-#define word0(x) ((ULong *)&x)[0]
-#define word1(x) ((ULong *)&x)[1]
-#endif
-#else
-#ifdef IEEE_8087
-#define word0(x) ((U*)&x)->L[1]
-#define word1(x) ((U*)&x)->L[0]
-#else
-#define word0(x) ((U*)&x)->L[0]
-#define word1(x) ((U*)&x)->L[1]
-#endif
-#define dval(x) ((U*)&x)->d
+#define word0(x) (x).L[0]
+#define word1(x) (x).L[1]
 #endif
 
 /* The following definition of Storeinc is appropriate for MIPS processors.
  * An alternative that might be better on some machines is
  * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff)
  */
 #if defined(IEEE_8087) + defined(IEEE_ARM) + defined(VAX)
 #define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \
@@ -1179,24 +1163,25 @@ diff
 		wa--;
 	c->wds = wa;
 	return c;
 	}
 
  static double
 ulp
 #ifdef KR_headers
-	(x) double x;
+	(dx) double dx;
 #else
-	(double x)
+	(double dx)
 #endif
 {
 	register Long L;
-	double a;
+	U x, a;
 
+	dval(x) = dx;
 	L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1;
 #ifndef Avoid_Underflow
 #ifndef Sudden_Underflow
 	if (L > 0) {
 #endif
 #endif
 #ifdef IBM
 		L |= Exp_msk1 >> 4;
@@ -1228,17 +1213,17 @@ b2d
 #ifdef KR_headers
 	(a, e) Bigint *a; int *e;
 #else
 	(Bigint *a, int *e)
 #endif
 {
 	ULong *xa, *xa0, w, y, z;
 	int k;
-	double d;
+	U d;
 #ifdef VAX
 	ULong d0, d1;
 #else
 #define d0 word0(d)
 #define d1 word1(d)
 #endif
 
 	xa0 = a->x;
@@ -1291,29 +1276,34 @@ b2d
 #undef d1
 #endif
 	return dval(d);
 	}
 
  static Bigint *
 d2b
 #ifdef KR_headers
-	(d, e, bits) double d; int *e, *bits;
+	(dd, e, bits) double dd; int *e, *bits;
 #else
-	(double d, int *e, int *bits)
+	(double dd, int *e, int *bits)
 #endif
 {
+	U d;
 	Bigint *b;
 	int de, k;
 	ULong *x, y, z;
 #ifndef Sudden_Underflow
 	int i;
 #endif
 #ifdef VAX
 	ULong d0, d1;
+#endif
+
+	dval(d) = dd;
+#ifdef VAX
 	d0 = word0(d) >> 16 | word0(d) << 16;
 	d1 = word1(d) >> 16 | word1(d) << 16;
 #else
 #define d0 word0(d)
 #define d1 word1(d)
 #endif
 
 #ifdef Pack_32
@@ -1434,17 +1424,17 @@ d2b
  static double
 ratio
 #ifdef KR_headers
 	(a, b) Bigint *a, *b;
 #else
 	(Bigint *a, Bigint *b)
 #endif
 {
-	double da, db;
+	U da, db;
 	int k, ka, kb;
 
 	dval(da) = b2d(a, &ka);
 	dval(db) = b2d(b, &kb);
 #ifdef Pack_32
 	k = ka - kb + 32*(a->wds - b->wds);
 #else
 	k = ka - kb + 16*(a->wds - b->wds);
@@ -1608,17 +1598,18 @@ PR_strtod
 #endif
 {
 #ifdef Avoid_Underflow
 	int scale;
 #endif
 	int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign,
 		 e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign;
 	CONST char *s, *s0, *s1;
-	double aadj, aadj1, adj, rv, rv0;
+	double aadj, aadj1, adj;
+	U aadj2, rv, rv0;
 	Long L;
 	ULong y, z;
 	Bigint *bb, *bb1, *bd, *bd0, *bs, *delta;
 #ifdef SET_INEXACT
 	int inexact, oldinexact;
 #endif
 #ifdef Honor_FLT_ROUNDS
 	int rounding;
@@ -2371,17 +2362,19 @@ PR_strtod
 #ifdef Avoid_Underflow
 			if (scale && y <= 2*P*Exp_msk1) {
 				if (aadj <= 0x7fffffff) {
 					if ((z = aadj) <= 0)
 						z = 1;
 					aadj = z;
 					aadj1 = dsign ? aadj : -aadj;
 					}
-				word0(aadj1) += (2*P+1)*Exp_msk1 - y;
+				dval(aadj2) = aadj1;
+				word0(aadj2) += (2*P+1)*Exp_msk1 - y;
+				aadj1 = dval(aadj2);
 				}
 			adj = aadj1 * ulp(dval(rv));
 			dval(rv) += adj;
 #else
 #ifdef Sudden_Underflow
 			if ((word0(rv) & Exp_mask) <= P*Exp_msk1) {
 				dval(rv0) = dval(rv);
 				word0(rv) += P*Exp_msk1;
@@ -2706,20 +2699,20 @@ freedtoa(char *s)
  *	   "uniformly" distributed input, the probability is
  *	   something like 10^(k-15) that we must resort to the Long
  *	   calculation.
  */
 
  static char *
 dtoa
 #ifdef KR_headers
-	(d, mode, ndigits, decpt, sign, rve)
-	double d; int mode, ndigits, *decpt, *sign; char **rve;
+	(dd, mode, ndigits, decpt, sign, rve)
+	double dd; int mode, ndigits, *decpt, *sign; char **rve;
 #else
-	(double d, int mode, int ndigits, int *decpt, int *sign, char **rve)
+	(double dd, int mode, int ndigits, int *decpt, int *sign, char **rve)
 #endif
 {
  /*	Arguments ndigits, decpt, sign are similar to those
 	of ecvt and fcvt; trailing zeros are suppressed from
 	the returned string.  If not null, *rve is set to point
 	to the end of the return value.  If d is +-Infinity or NaN,
 	then *decpt is set to 9999.
 
@@ -2755,32 +2748,34 @@ dtoa
 		j, j1, k, k0, k_check, leftright, m2, m5, s2, s5,
 		spec_case, try_quick;
 	Long L;
 #ifndef Sudden_Underflow
 	int denorm;
 	ULong x;
 #endif
 	Bigint *b, *b1, *delta, *mlo, *mhi, *S;
-	double d2, ds, eps;
+	U d, d2, eps;
+	double ds;
 	char *s, *s0;
 #ifdef Honor_FLT_ROUNDS
 	int rounding;
 #endif
 #ifdef SET_INEXACT
 	int inexact, oldinexact;
 #endif
 
 #ifndef MULTIPLE_THREADS
 	if (dtoa_result) {
 		freedtoa(dtoa_result);
 		dtoa_result = 0;
 		}
 #endif
 
+	dval(d) = dd;
 	if (word0(d) & Sign_bit) {
 		/* set sign for everything, including 0's and NaNs */
 		*sign = 1;
 		word0(d) &= ~Sign_bit;	/* clear sign bit */
 		}
 	else
 		*sign = 0;
 
@@ -3430,23 +3425,25 @@ PR_dtoa(PRFloat64 d, PRIntn mode, PRIntn
 ** This should be reparameterized so that you can send in a
 **   prcn for the positive and negative ranges.  For now, 
 **   conform to the ECMA JavaScript spec which says numbers
 **   less than 1e-6 are in scientific notation.
 ** Also, the ECMA spec says that there should always be a
 **   '+' or '-' after the 'e' in scientific notation
 */
 PR_IMPLEMENT(void)
-PR_cnvtf(char *buf,int bufsz, int prcsn,double fval)
+PR_cnvtf(char *buf, int bufsz, int prcsn, double dfval)
 {
     PRIntn decpt, sign, numdigits;
     char *num, *nump;
     char *bufp = buf;
     char *endnum;
+    U fval;
 
+    dval(fval) = dfval;
     /* If anything fails, we store an empty string in 'buf' */
     num = (char*)PR_MALLOC(bufsz);
     if (num == NULL) {
         buf[0] = '\0';
         return;
     }
     /* XXX Why use mode 1? */
     if (PR_dtoa(dval(fval),1,prcsn,&decpt,&sign,&endnum,num,bufsz)
--- a/pr/src/misc/prtime.c
+++ b/pr/src/misc/prtime.c
@@ -45,20 +45,18 @@
 #include "prinit.h"
 #include "prtime.h"
 #include "prlock.h"
 #include "prprf.h"
 #include "prlog.h"
 
 #include <string.h>
 #include <ctype.h>
-
-#ifdef XP_MAC
+#include <errno.h>  /* for EINVAL */
 #include <time.h>
-#endif
 
 /* 
  * The COUNT_LEAPS macro counts the number of leap years passed by
  * till the start of the given year Y.  At the start of the year 4
  * A.D. the number of leap years passed by is 0, while at the start of
  * the year 5 A.D. this count is 1. The number of years divisible by
  * 100 but not divisible by 400 (the non-leap years) is deducted from
  * the count to get the correct number of leap years.
@@ -514,18 +512,16 @@ PR_NormalizeTime(PRExplodedTime *time, P
  *     The following uses localtime() from the standard C library.
  *     (time.h)  This is our fallback implementation.  Unix and PC
  *     use this version.  Mac has its own machine-dependent
  *     implementation of this function.
  *
  *-------------------------------------------------------------------------
  */
 
-#include <time.h>
-
 #if defined(HAVE_INT_LOCALTIME_R)
 
 /*
  * In this case we could define the macro as
  *     #define MT_safe_localtime(timer, result) \
  *             (localtime_r(timer, result) == 0 ? result : NULL)
  * I chose to compare the return value of localtime_r with -1 so 
  * that I can catch the cases where localtime_r returns a pointer
@@ -1568,16 +1564,22 @@ PR_ParseTimeStringToExplodedTime(
   if (date != -1)
         result->tm_mday = date;
   if (month != TT_UNKNOWN)
         result->tm_month = (((int)month) - ((int)TT_JAN));
   if (year != -1)
         result->tm_year = year;
   if (dotw != TT_UNKNOWN)
         result->tm_wday = (((int)dotw) - ((int)TT_SUN));
+  /*
+   * Mainly to compute wday and yday, but normalized time is also required
+   * by the check below that works around a Visual C++ 2005 mktime problem.
+   */
+  PR_NormalizeTime(result, PR_GMTParameters);
+  /* The remaining work is to set the gmt and dst offsets in tm_params. */
 
   if (zone == TT_UNKNOWN && default_to_gmt)
         {
           /* No zone was specified, so pretend the zone was GMT. */
           zone = TT_GMT;
           zone_offset = 0;
         }
 
@@ -1617,17 +1619,42 @@ PR_ParseTimeStringToExplodedTime(
                   localTime.tm_mday = result->tm_mday;
                   localTime.tm_mon = result->tm_month;
                   localTime.tm_year = result->tm_year - 1900;
                   /* Set this to -1 to tell mktime "I don't care".  If you set
                      it to 0 or 1, you are making assertions about whether the
                      date you are handing it is in daylight savings mode or not;
                      and if you're wrong, it will "fix" it for you. */
                   localTime.tm_isdst = -1;
+
+#if _MSC_VER == 1400  /* 1400 = Visual C++ 2005 (8.0) */
+                  /*
+                   * mktime will return (time_t) -1 if the input is a date
+                   * after 23:59:59, December 31, 3000, US Pacific Time (not
+                   * UTC as documented): 
+                   * http://msdn.microsoft.com/en-us/library/d1y53h2a(VS.80).aspx
+                   * But if the year is 3001, mktime also invokes the invalid
+                   * parameter handler, causing the application to crash.  This
+                   * problem has been reported in
+                   * http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=266036.
+                   * We avoid this crash by not calling mktime if the date is
+                   * out of range.  To use a simple test that works in any time
+                   * zone, we consider year 3000 out of range as well.  (See
+                   * bug 480740.)
+                   */
+                  if (result->tm_year >= 3000) {
+                      /* Emulate what mktime would have done. */
+                      errno = EINVAL;
+                      secs = (time_t) -1;
+                  } else {
+                      secs = mktime(&localTime);
+                  }
+#else
                   secs = mktime(&localTime);
+#endif
                   if (secs != (time_t) -1)
                     {
                       PRTime usecs64;
                       LL_I2L(usecs64, secs);
                       LL_I2L(usec_per_sec, PR_USEC_PER_SEC);
                       LL_MUL(usecs64, usecs64, usec_per_sec);
                       PR_ExplodeTime(usecs64, PR_LocalTimeParameters, result);
                       return PR_SUCCESS;
@@ -1639,18 +1666,16 @@ PR_ParseTimeStringToExplodedTime(
                    the zone offset on 00:00:00 2 Jan 1970 GMT. */
                 secs = 86400;
                 (void) MT_safe_localtime(&secs, &localTime);
                 zone_offset = localTime.tm_min
                               + 60 * localTime.tm_hour
                               + 1440 * (localTime.tm_mday - 2);
         }
 
-  /* mainly to compute wday and yday */
-  PR_NormalizeTime(result, PR_GMTParameters);
   result->tm_params.tp_gmt_offset = zone_offset * 60;
   result->tm_params.tp_dst_offset = dst_offset * 60;
 
   return PR_SUCCESS;
 }
 
 PR_IMPLEMENT(PRStatus)
 PR_ParseTimeString(
--- a/pr/src/pthreads/ptio.c
+++ b/pr/src/pthreads/ptio.c
@@ -1013,17 +1013,17 @@ static PRBool pt_hpux_sendfile_cont(pt_C
         op->result.code = -1;
     } else {
         return PR_FALSE;
     }
     if (count != -1 && count < op->nbytes_to_send) {
         if (count < hdtrl[0].iov_len) {
 			/* header not sent */
 
-            hdtrl[0].iov_base = ((char *) hdtrl[0].iov_len) + count;
+            hdtrl[0].iov_base = ((char *) hdtrl[0].iov_base) + count;
             hdtrl[0].iov_len -= count;
 
         } else if (count < (hdtrl[0].iov_len + op->arg3.file_spec.nbytes)) {
 			/* header sent, file not sent */
             PRUint32 file_nbytes_sent = count - hdtrl[0].iov_len;
 
             hdtrl[0].iov_base = NULL;
             hdtrl[0].iov_len = 0;
--- a/pr/src/pthreads/ptsynch.c
+++ b/pr/src/pthreads/ptsynch.c
@@ -807,17 +807,17 @@ PR_IMPLEMENT(PRStatus) PR_DeleteSemaphor
 #include <fcntl.h>
 #include <sys/sem.h>
 
 /*
  * From the semctl(2) man page in glibc 2.0
  */
 #if (defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)) \
     || defined(FREEBSD) || defined(OPENBSD) || defined(BSDI) \
-    || defined(SYMBIAN)
+    || defined(DARWIN) || defined(SYMBIAN)
 /* union semun is defined by including <sys/sem.h> */
 #else
 /* according to X/OPEN we have to define it ourselves */
 union semun {
     int val;
     struct semid_ds *buf;
     unsigned short  *array;
 };
--- a/pr/tests/Makefile.in
+++ b/pr/tests/Makefile.in
@@ -120,16 +120,17 @@ CSRCS =             \
 	op_2long.c      \
 	op_excl.c		\
 	op_filnf.c		\
 	op_filok.c		\
 	op_noacc.c		\
 	op_nofil.c		\
 	openfile.c		\
 	parent.c    	\
+	parsetm.c    	\
 	peek.c    		\
 	perf.c    		\
 	pipeping.c		\
 	pipeping2.c		\
 	pipepong.c		\
 	pipepong2.c		\
 	pipeself.c		\
 	poll_er.c		\
new file mode 100644
--- /dev/null
+++ b/pr/tests/parsetm.c
@@ -0,0 +1,116 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is the Netscape Portable Runtime (NSPR).
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998-2000
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/*
+ * This test program should eventually become a full-blown test for
+ * PR_ParseTimeString.  Right now it just verifies that PR_ParseTimeString
+ * doesn't crash on an out-of-range time string (bug 480740).
+ */
+
+#include "prtime.h"
+
+#include <time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+PRBool debug_mode = PR_TRUE;
+
+static char *dayOfWeek[] =
+	{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???" };
+static char *month[] =
+	{ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+	  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???" };
+
+static void PrintExplodedTime(const PRExplodedTime *et) {
+    PRInt32 totalOffset;
+    PRInt32 hourOffset, minOffset;
+    const char *sign;
+
+    /* Print day of the week, month, day, hour, minute, and second */
+    if (debug_mode) printf("%s %s %ld %02ld:%02ld:%02ld ",
+	    dayOfWeek[et->tm_wday], month[et->tm_month], et->tm_mday,
+	    et->tm_hour, et->tm_min, et->tm_sec);
+
+    /* Print time zone */
+    totalOffset = et->tm_params.tp_gmt_offset + et->tm_params.tp_dst_offset;
+    if (totalOffset == 0) {
+	if (debug_mode) printf("UTC ");
+    } else {
+        sign = "+";
+        if (totalOffset < 0) {
+	    totalOffset = -totalOffset;
+	    sign = "-";
+        }
+        hourOffset = totalOffset / 3600;
+        minOffset = (totalOffset % 3600) / 60;
+        if (debug_mode) 
+            printf("%s%02ld%02ld ", sign, hourOffset, minOffset);
+    }
+
+    /* Print year */
+    if (debug_mode) printf("%hd", et->tm_year);
+}
+
+int main(int argc, char **argv)
+{
+    PRTime ct;
+    PRExplodedTime et;
+    PRStatus rv;
+    char *sp1 = "Sat, 1 Jan 3001 00:00:00";  /* no time zone */
+    char *sp2 = "Fri, 31 Dec 3000 23:59:60";  /* no time zone, not normalized */
+
+#if _MSC_VER >= 1400
+    /* Run this test in the US Pacific Time timezone. */
+    _putenv_s("TZ", "PST8PDT");
+    _tzset();
+#endif
+
+    rv = PR_ParseTimeString(sp1, PR_FALSE, &ct);
+    printf("rv = %d\n", rv);
+    PR_ExplodeTime(ct, PR_GMTParameters, &et);
+    PrintExplodedTime(&et);
+    printf("\n");
+
+    rv = PR_ParseTimeString(sp2, PR_FALSE, &ct);
+    printf("rv = %d\n", rv);
+    PR_ExplodeTime(ct, PR_GMTParameters, &et);
+    PrintExplodedTime(&et);
+    printf("\n");
+
+    return 0;
+}
--- a/pr/tests/runtests.pl
+++ b/pr/tests/runtests.pl
@@ -328,16 +328,17 @@ sub win_test_prog {
 "ntioto",
 "ntoh",
 "op_2long",
 "op_excl",
 "op_filnf",
 "op_filok",
 "op_nofil",
 "parent",
+"parsetm",
 "peek",
 "perf",
 "pipeping",
 "pipeping2",
 "pipeself",
 "poll_nm",
 "poll_to",
 "pollable",
--- a/pr/tests/runtests.sh
+++ b/pr/tests/runtests.sh
@@ -156,16 +156,17 @@ nonblock
 ntioto
 ntoh
 op_2long
 op_excl
 op_filnf
 op_filok
 op_nofil
 parent
+parsetm
 peek
 perf
 pipeping
 pipeping2
 pipeself
 poll_nm
 poll_to
 pollable
--- a/pr/tests/vercheck.c
+++ b/pr/tests/vercheck.c
@@ -58,17 +58,17 @@
  * compatible with itself.
  */
 static char *compatible_version[] = {
     "4.0", "4.0.1", "4.1", "4.1.1", "4.1.2", "4.1.3",
     "4.2", "4.2.1", "4.2.2", "4.3", "4.4", "4.4.1",
     "4.5", "4.5.1",
     "4.6", "4.6.1", "4.6.2", "4.6.3", "4.6.4", "4.6.5",
     "4.6.6", "4.6.7", "4.6.8",
-    "4.7", "4.7.1", "4.7.2", "4.7.3", PR_VERSION
+    "4.7", "4.7.1", "4.7.2", "4.7.3", "4.7.4", PR_VERSION
 };
 
 /*
  * This release is not backward compatible with the old
  * NSPR 2.1 and 3.x releases.
  *
  * Any release is incompatible with future releases and
  * patches.