Sync with NSPR 4.6 NSPRPUB_PRE_4_2_CLIENT_BRANCH
authorcls%seawood.org
Wed, 01 Jun 2005 14:10:53 +0000
branchNSPRPUB_PRE_4_2_CLIENT_BRANCH
changeset 3398 765c8d8ce731853c73abf28710c2d0a7b4095805
parent 3396 edd1234127ce1247e31f3d8c57a37d95379b7016
child 3399 0d0f14c8216a2c6ba7361c21ec673f7e38b52fb6
push idunknown
push userunknown
push dateunknown
bugs295761
Sync with NSPR 4.6 Bug #295761 a=shaver
admin/repackage.sh
configure
configure.in
pr/include/md/_unix_errors.h
pr/include/prinit.h
pr/src/md/unix/uxwrap.c
pr/src/pthreads/ptthread.c
pr/tests/bigfile3.c
pr/tests/env.c
pr/tests/initclk.c
pr/tests/layer.c
pr/tests/nbconn.c
pr/tests/ntioto.c
pr/tests/op_filnf.c
pr/tests/prpoll.c
pr/tests/randseed.c
pr/tests/sel_spd.c
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.5
-TOTOP=./v4.5
-NSPRDIR=nspr-4.5
-SOURCETAG=NSPR_4_5_RTM
+FROMTOP=/share/builds/components/nspr20/v4.6
+TOTOP=./v4.6
+NSPRDIR=nspr-4.6
+SOURCETAG=NSPR_4_6_RTM
 
 #
 # enumerate Unix object directories on /s/b/c
 UNIX_OBJDIRS="
 AIX4.3_64_DBG.OBJ
 AIX4.3_64_OPT.OBJ
 AIX4.3_DBG.OBJ
 AIX4.3_OPT.OBJ
--- a/configure
+++ b/configure
@@ -2677,94 +2677,95 @@ rm -f conftest*
     fi
     rm -f dummy-hello.c dummy-hello.s dummy-hello.S dummy-hello a.out
     echo "$ac_t""$_res" 1>&6
 else
     echo "$ac_t""no" 1>&6
 fi
 
 if test "$GNU_CC"; then
-  echo $ac_n "checking for visibility(hidden) attribute""... $ac_c" 1>&6
+    echo $ac_n "checking for visibility(hidden) attribute""... $ac_c" 1>&6
 echo "configure:2687: checking for visibility(hidden) attribute" >&5
 if eval "test \"`echo '$''{'ac_cv_visibility_hidden'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.c <<EOF
-                  int foo __attribute__ ((visibility ("hidden"))) = 1;
-EOF
-                  ac_cv_visibility_attribute=no
-                  if ${CC-cc} -Werror -S conftest.c -o conftest.s >/dev/null 2>&1; then
-                    if grep '\.hidden.*foo' conftest.s >/dev/null; then
-                      ac_cv_visibility_hidden=yes
-                    fi
-                  fi
-                  rm -f conftest.cs
-                 
+        int foo __attribute__ ((visibility ("hidden"))) = 1;
+EOF
+        ac_cv_visibility_hidden=no
+        if ${CC-cc} -Werror -S conftest.c -o conftest.s >/dev/null 2>&1; then
+            if grep '\.hidden.*foo' conftest.s >/dev/null; then
+                ac_cv_visibility_hidden=yes
+            fi
+        fi
+        rm -f conftest.cs
+        
 fi
 
 echo "$ac_t""$ac_cv_visibility_hidden" 1>&6
-   if test "$ac_cv_visibility_hidden" = "yes"; then
-      cat >> confdefs.h <<\EOF
+    if test "$ac_cv_visibility_hidden" = "yes"; then
+        cat >> confdefs.h <<\EOF
 #define HAVE_VISIBILITY_HIDDEN_ATTRIBUTE 1
 EOF
 
-      echo $ac_n "checking for visibility pragma support""... $ac_c" 1>&6
+        echo $ac_n "checking for visibility pragma support""... $ac_c" 1>&6
 echo "configure:2711: checking for visibility pragma support" >&5
 if eval "test \"`echo '$''{'ac_cv_visibility_pragma'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.c <<EOF
 #pragma GCC visibility push(hidden)
-                      int foo_hidden = 1;
+            int foo_hidden = 1;
 #pragma GCC visibility push(default)
-                      int foo_default = 1;
-EOF
-                      ac_cv_visibility_pragma=no
-                      if ${CC-cc} -Werror -S conftest.c -o conftest.s >/dev/null 2>&1; then
-                        if grep '\.hidden.*foo_hidden' conftest.s >/dev/null; then
-                          if ! grep '\.hidden.*foo_default' conftest.s > /dev/null; then
-                            ac_cv_visibility_pragma=yes
-                          fi
-                        fi
-                      fi
-                      rm -f conftest.cs
-                    
+            int foo_default = 1;
+EOF
+            ac_cv_visibility_pragma=no
+            if ${CC-cc} -Werror -S conftest.c -o conftest.s >/dev/null 2>&1; then
+                if grep '\.hidden.*foo_hidden' conftest.s >/dev/null; then
+                    if ! grep '\.hidden.*foo_default' conftest.s > /dev/null; then
+                        ac_cv_visibility_pragma=yes
+                    fi
+                fi
+            fi
+            rm -f conftest.cs
+            
 fi
 
 echo "$ac_t""$ac_cv_visibility_pragma" 1>&6
-     if test "$ac_cv_visibility_pragma" = "yes"; then
-       cat >> confdefs.h <<\EOF
+        if test "$ac_cv_visibility_pragma" = "yes"; then
+            cat >> confdefs.h <<\EOF
 #define HAVE_VISIBILITY_PRAGMA 1
 EOF
 
-       # To work around a build problem on Linux x86-64 (Bugzilla bug
-       # 293438), we use the -fvisibility=hidden flag.  This flag is less
-       # optimal than #pragma GCC visibility push(hidden) because the flag
-       # assumes that symbols defined outside the current source file have
-       # the default visibility.  This has the advantage that we don't need
-       # to wrap system header files, but has the disadvantage that calls
-       # to hidden symbols defined in other source files cannot be
-       # optimized by the compiler.  The -fvisibility=hidden flag does
-       # hide and export symbols correctly.
-       #VISIBILITY_FLAGS='-I$(dist_includedir)/system_wrappers -include $(topsrcdir)/config/gcc_hidden.h'
-       #WRAP_SYSTEM_INCLUDES=1
-       VISIBILITY_FLAGS="-fvisibility=hidden"
-       WRAP_SYSTEM_INCLUDES=
-     fi
-   fi
-fi     # GNU_CC
+            # To work around a build problem on Linux x86-64 (Bugzilla bug
+            # 293438), we use the -fvisibility=hidden flag.  This flag is less
+            # optimal than #pragma GCC visibility push(hidden) because the flag
+            # assumes that symbols defined outside the current source file have
+            # the default visibility.  This has the advantage that we don't need
+            # to wrap system header files, but has the disadvantage that calls
+            # to hidden symbols defined in other source files cannot be
+            # optimized by the compiler.  The -fvisibility=hidden flag does
+            # hide and export symbols correctly.
+            #VISIBILITY_FLAGS='-I$(dist_includedir)/system_wrappers -include $(topsrcdir)/config/gcc_hidden.h'
+            #WRAP_SYSTEM_INCLUDES=1
+            VISIBILITY_FLAGS="-fvisibility=hidden"
+            WRAP_SYSTEM_INCLUDES=
+        fi
+    fi
+fi # GNU_CC
+
 fi # SKIP_COMPILER_CHECKS
 
 if test -z "$SKIP_PATH_CHECKS"; then
     for ac_prog in perl5 perl
 do
 # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2763: checking for $ac_word" >&5
+echo "configure:2764: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_path_PERL'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   case "$PERL" in
   /*)
   ac_cv_path_PERL="$PERL" # Let the user override the test with a path.
   ;;
   ?:/*)			 
@@ -2999,27 +3000,27 @@ EOF
 
     cat >> confdefs.h <<\EOF
 #define SYSV 1
 EOF
 
     DSO_LDOPTS='-brtl -bnortllib -bM:SRE -bnoentry -bexpall -blibpath:/usr/lib:/lib'
     ac_safe=`echo "sys/atomic_op.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for sys/atomic_op.h""... $ac_c" 1>&6
-echo "configure:3008: checking for sys/atomic_op.h" >&5
+echo "configure:3009: checking for sys/atomic_op.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 3013 "configure"
+#line 3014 "configure"
 #include "confdefs.h"
 #include <sys/atomic_op.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:3018: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:3019: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
   eval "ac_cv_header_$ac_safe=yes"
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
@@ -3166,36 +3167,36 @@ EOF
     PR_MD_ARCH_DIR=beos
     RESOLVE_LINK_SYMBOLS=1
     case "${target_cpu}" in
     i*86)
         _OPTIMIZE_FLAGS=-O2
         _DEBUG_FLAGS='-gdwarf-2 -O0'
         MKSHLIB='$(CCC) $(DSO_LDOPTS) -o $@'
         echo $ac_n "checking for gethostbyaddr in -lbind""... $ac_c" 1>&6
-echo "configure:3175: checking for gethostbyaddr in -lbind" >&5
+echo "configure:3176: checking for gethostbyaddr in -lbind" >&5
 ac_lib_var=`echo bind'_'gethostbyaddr | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   ac_save_LIBS="$LIBS"
 LIBS="-lbind  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 3183 "configure"
+#line 3184 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char gethostbyaddr();
 
 int main() {
 gethostbyaddr()
 ; return 0; }
 EOF
-if { (eval echo configure:3194: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3195: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=no"
 fi
@@ -4025,16 +4026,21 @@ EOF
                 LDFLAGS="$LDFLAGS -DEBUG -OPT:REF"
             fi
         fi
 
         if test -n "$MOZ_DEBUG"; then
             DLLFLAGS="$DLLFLAGS -DEBUG"
             LDFLAGS="$LDFLAGS -DEBUG"
         fi
+
+        OS_DLLFLAGS="-nologo -DLL -SUBSYSTEM:WINDOWS"
+        if test "$MSC_VER" -le "1200" -a -z "$MOZ_DEBUG_SYMBOLS"; then
+            OS_DLLFLAGS="$OS_DLLFLAGS -PDB:NONE"
+        fi
         
         if test "$OS_TARGET" = "WINNT"; then
             CFLAGS="$CFLAGS -GT"
             if test "$CPU_ARCH" = "x86"; then
                 CFLAGS="$CFLAGS -G5"
             fi
             LIBNSPR='$(dist_libdir)/libnspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
             LIBPLC='$(dist_libdir)/libplc$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
@@ -4074,21 +4080,16 @@ EOF
     else
         CPU_ARCH_TAG=$CPU_ARCH
     fi
 
     if test -n "$USE_DEBUG_RTL"; then
         OBJDIR_SUFFIX=OBJD
     fi
 
-    OS_DLLFLAGS="-nologo -DLL -SUBSYSTEM:WINDOWS"
-    if test "$MSC_VER" -le "1200" -a -z "$MOZ_DEBUG_SYMBOLS"; then
-        OS_DLLFLAGS="$OS_DLLFLAGS -PDB:NONE"
-    fi
-
     case "$OS_TARGET" in
     WINNT)
 	    MDCPUCFG_H=_winnt.cfg
 	    ;;
     WIN95)
 	    MDCPUCFG_H=_win95.cfg
 	    ;;
     WIN16)
@@ -4416,27 +4417,27 @@ EOF
     if test -z "$GNU_CC"; then
         CC="$CC -std1 -ieee_with_inexact"
         if test "$OS_RELEASE" != "V2.0"; then
             CC="$CC -readonly_strings"
         fi
         _OPTIMIZE_FLAGS="$_OPTIMIZE_FLAGS -Olimit 4000"
         ac_safe=`echo "machine/builtins.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for machine/builtins.h""... $ac_c" 1>&6
-echo "configure:4425: checking for machine/builtins.h" >&5
+echo "configure:4426: checking for machine/builtins.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 4430 "configure"
+#line 4431 "configure"
 #include "confdefs.h"
 #include <machine/builtins.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:4435: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:4436: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
   eval "ac_cv_header_$ac_safe=yes"
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
@@ -4968,63 +4969,63 @@ if test -z "$SKIP_LIBRARY_CHECKS"; then
 
 
 
 case $target in
 *-darwin*)
     ;;
 *)
     echo $ac_n "checking for dlopen in -ldl""... $ac_c" 1>&6
-echo "configure:4977: checking for dlopen in -ldl" >&5
+echo "configure:4978: checking for dlopen in -ldl" >&5
 ac_lib_var=`echo dl'_'dlopen | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   ac_save_LIBS="$LIBS"
 LIBS="-ldl  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 4985 "configure"
+#line 4986 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char dlopen();
 
 int main() {
 dlopen()
 ; return 0; }
 EOF
-if { (eval echo configure:4996: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4997: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=no"
 fi
 rm -f conftest*
 LIBS="$ac_save_LIBS"
 
 fi
 if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
   echo "$ac_t""yes" 1>&6
   ac_safe=`echo "dlfcn.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for dlfcn.h""... $ac_c" 1>&6
-echo "configure:5013: checking for dlfcn.h" >&5
+echo "configure:5014: checking for dlfcn.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 5018 "configure"
+#line 5019 "configure"
 #include "confdefs.h"
 #include <dlfcn.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:5023: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:5024: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
   eval "ac_cv_header_$ac_safe=yes"
 else
   echo "$ac_err" >&5
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
@@ -5047,23 +5048,23 @@ fi
     ;;
 esac
 
 
 
 
 if test $ac_cv_prog_gcc = yes; then
     echo $ac_n "checking whether ${CC-cc} needs -traditional""... $ac_c" 1>&6
-echo "configure:5056: checking whether ${CC-cc} needs -traditional" >&5
+echo "configure:5057: checking whether ${CC-cc} needs -traditional" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gcc_traditional'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
     ac_pattern="Autoconf.*'x'"
   cat > conftest.$ac_ext <<EOF
-#line 5062 "configure"
+#line 5063 "configure"
 #include "confdefs.h"
 #include <sgtty.h>
 Autoconf TIOCGETP
 EOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
   egrep "$ac_pattern" >/dev/null 2>&1; then
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=yes
@@ -5071,17 +5072,17 @@ else
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=no
 fi
 rm -f conftest*
 
 
   if test $ac_cv_prog_gcc_traditional = no; then
     cat > conftest.$ac_ext <<EOF
-#line 5080 "configure"
+#line 5081 "configure"
 #include "confdefs.h"
 #include <termio.h>
 Autoconf TCGETA
 EOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
   egrep "$ac_pattern" >/dev/null 2>&1; then
   rm -rf conftest*
   ac_cv_prog_gcc_traditional=yes
@@ -5095,22 +5096,22 @@ echo "$ac_t""$ac_cv_prog_gcc_traditional
   if test $ac_cv_prog_gcc_traditional = yes; then
     CC="$CC -traditional"
   fi
 fi
 
 for ac_func in lchown strerror
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:5104: checking for $ac_func" >&5
+echo "configure:5105: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 5109 "configure"
+#line 5110 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
 #include <assert.h>
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
 char $ac_func();
@@ -5123,17 +5124,17 @@ int main() {
 #if defined (__stub_$ac_func) || defined (__stub___$ac_func)
 choke me
 #else
 $ac_func();
 #endif
 
 ; return 0; }
 EOF
-if { (eval echo configure:5132: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:5133: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=no"
 fi
@@ -5164,17 +5165,17 @@ if test "${enable_strip+set}" = set; the
 fi
 
 
 case "${target_os}" in
 hpux*)
 if test -z "$GNU_CC"; then
 
     echo $ac_n "checking for +Olit support""... $ac_c" 1>&6
-echo "configure:5173: checking for +Olit support" >&5
+echo "configure:5174: checking for +Olit support" >&5
 if eval "test \"`echo '$''{'ac_cv_hpux_usable_olit_option'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
                   ac_cv_hpux_usable_olit_option=no
         rm -f conftest*
         echo 'int main() { return 0; }' | cat > conftest.c
         ${CC-cc} ${CFLAGS} +Olit=all -o conftest conftest.c > conftest.out 2>&1
         if test $? -eq 0; then
@@ -5198,17 +5199,17 @@ echo "$ac_t""$ac_cv_hpux_usable_olit_opt
 fi
 ;;
 esac
 
 
 
 
 echo $ac_n "checking for pthread_create in -lpthreads""... $ac_c" 1>&6
-echo "configure:5207: checking for pthread_create in -lpthreads" >&5
+echo "configure:5208: checking for pthread_create in -lpthreads" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5220,17 +5221,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthreads"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lpthread""... $ac_c" 1>&6
-echo "configure:5229: checking for pthread_create in -lpthread" >&5
+echo "configure:5230: checking for pthread_create in -lpthread" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5242,17 +5243,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lpthread"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lc_r""... $ac_c" 1>&6
-echo "configure:5251: checking for pthread_create in -lc_r" >&5
+echo "configure:5252: checking for pthread_create in -lc_r" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5264,17 +5265,17 @@ echo "
     rm -f dummy.c dummy${ac_exeext} ;
     if test "$_res" = "0"; then
         echo "$ac_t""yes" 1>&6
         _HAVE_PTHREADS=1 _PTHREAD_LDFLAGS="-lc_r"
     else
         echo "$ac_t""no" 1>&6
         
 echo $ac_n "checking for pthread_create in -lc""... $ac_c" 1>&6
-echo "configure:5273: checking for pthread_create in -lc" >&5
+echo "configure:5274: checking for pthread_create in -lc" >&5
 echo "
     #include <pthread.h> 
     void *foo(void *v) { return v; } 
     int main() { 
         pthread_t t;
         if (!pthread_create(&t, 0, &foo, 0)) {
             pthread_join(t, 0);
         }
@@ -5416,17 +5417,17 @@ EOF
     fi
 fi
 
 
 if test -n "$USE_PTHREADS"; then
       rm -f conftest*
    ac_cv_have_dash_pthread=no
    echo $ac_n "checking whether ${CC-cc} accepts -pthread""... $ac_c" 1>&6
-echo "configure:5425: checking whether ${CC-cc} accepts -pthread" >&5
+echo "configure:5426: checking whether ${CC-cc} accepts -pthread" >&5
    echo 'int main() { return 0; }' | cat > conftest.c
    ${CC-cc} -pthread -o conftest conftest.c > conftest.out 2>&1
    if test $? -eq 0; then
 	if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthread`" && test -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
 	    ac_cv_have_dash_pthread=yes
 		case "$target_os" in
 	    freebsd*)
 # Freebsd doesn't use -pthread for compiles, it uses them for linking
@@ -5439,17 +5440,17 @@ echo "configure:5425: checking whether $
 	fi
     fi
     rm -f conftest*
     echo "$ac_t""$ac_cv_have_dash_pthread" 1>&6
 
 			    ac_cv_have_dash_pthreads=no
     if test "$ac_cv_have_dash_pthread" = "no"; then
 	    echo $ac_n "checking whether ${CC-cc} accepts -pthreads""... $ac_c" 1>&6
-echo "configure:5448: checking whether ${CC-cc} accepts -pthreads" >&5
+echo "configure:5449: checking whether ${CC-cc} accepts -pthreads" >&5
     	echo 'int main() { return 0; }' | cat > conftest.c
 	    ${CC-cc} -pthreads -o conftest conftest.c > conftest.out 2>&1
     	if test $? -eq 0; then
 	    	if test -z "`egrep -i '(unrecognize|unknown)' conftest.out | grep pthreads`" && test -z "`egrep -i '(error|incorrect)' conftest.out`" ; then
 			    ac_cv_have_dash_pthreads=yes
 			    CFLAGS="$CFLAGS -pthreads"
 			    CXXFLAGS="$CXXFLAGS -pthreads"
 		    fi
--- a/configure.in
+++ b/configure.in
@@ -484,74 +484,73 @@ if test -n "$GNU_CC" && test -n "$GNU_CX
         _res="no"
     fi
     rm -f dummy-hello.c dummy-hello.s dummy-hello.S dummy-hello a.out
     AC_MSG_RESULT([$_res])
 else
     AC_MSG_RESULT([no])
 fi
 
-dnl Check for .hidden assembler directive and visibility attribute.
-dnl Borrowed from glibc configure.in
 dnl ===============================================================
 dnl Check for .hidden assembler directive and visibility attribute.
 dnl Borrowed from glibc configure.in
 dnl ===============================================================
 if test "$GNU_CC"; then
-  AC_CACHE_CHECK(for visibility(hidden) attribute,
-                 ac_cv_visibility_hidden,
-                 [cat > conftest.c <<EOF
-                  int foo __attribute__ ((visibility ("hidden"))) = 1;
+    AC_CACHE_CHECK(for visibility(hidden) attribute,
+        ac_cv_visibility_hidden,
+        [cat > conftest.c <<EOF
+        int foo __attribute__ ((visibility ("hidden"))) = 1;
 EOF
-                  ac_cv_visibility_attribute=no
-                  if ${CC-cc} -Werror -S conftest.c -o conftest.s >/dev/null 2>&1; then
-                    if grep '\.hidden.*foo' conftest.s >/dev/null; then
-                      ac_cv_visibility_hidden=yes
-                    fi
-                  fi
-                  rm -f conftest.[cs]
-                 ])
-   if test "$ac_cv_visibility_hidden" = "yes"; then
-      AC_DEFINE(HAVE_VISIBILITY_HIDDEN_ATTRIBUTE)
-      AC_CACHE_CHECK(for visibility pragma support,
-                     ac_cv_visibility_pragma,
-                     [cat > conftest.c <<EOF
+        ac_cv_visibility_hidden=no
+        if ${CC-cc} -Werror -S conftest.c -o conftest.s >/dev/null 2>&1; then
+            if grep '\.hidden.*foo' conftest.s >/dev/null; then
+                ac_cv_visibility_hidden=yes
+            fi
+        fi
+        rm -f conftest.[cs]
+        ])
+    if test "$ac_cv_visibility_hidden" = "yes"; then
+        AC_DEFINE(HAVE_VISIBILITY_HIDDEN_ATTRIBUTE)
+        AC_CACHE_CHECK(for visibility pragma support,
+            ac_cv_visibility_pragma,
+            [cat > conftest.c <<EOF
 #pragma GCC visibility push(hidden)
-                      int foo_hidden = 1;
+            int foo_hidden = 1;
 #pragma GCC visibility push(default)
-                      int foo_default = 1;
+            int foo_default = 1;
 EOF
-                      ac_cv_visibility_pragma=no
-                      if ${CC-cc} -Werror -S conftest.c -o conftest.s >/dev/null 2>&1; then
-                        if grep '\.hidden.*foo_hidden' conftest.s >/dev/null; then
-                          if ! grep '\.hidden.*foo_default' conftest.s > /dev/null; then
-                            ac_cv_visibility_pragma=yes
-                          fi
-                        fi
-                      fi
-                      rm -f conftest.[cs]
-                    ])
-     if test "$ac_cv_visibility_pragma" = "yes"; then
-       AC_DEFINE(HAVE_VISIBILITY_PRAGMA)
-       # To work around a build problem on Linux x86-64 (Bugzilla bug
-       # 293438), we use the -fvisibility=hidden flag.  This flag is less
-       # optimal than #pragma GCC visibility push(hidden) because the flag
-       # assumes that symbols defined outside the current source file have
-       # the default visibility.  This has the advantage that we don't need
-       # to wrap system header files, but has the disadvantage that calls
-       # to hidden symbols defined in other source files cannot be
-       # optimized by the compiler.  The -fvisibility=hidden flag does
-       # hide and export symbols correctly.
-       #VISIBILITY_FLAGS='-I$(dist_includedir)/system_wrappers -include $(topsrcdir)/config/gcc_hidden.h'
-       #WRAP_SYSTEM_INCLUDES=1
-       VISIBILITY_FLAGS="-fvisibility=hidden"
-       WRAP_SYSTEM_INCLUDES=
-     fi
-   fi
-fi     # GNU_CC
+            ac_cv_visibility_pragma=no
+            if ${CC-cc} -Werror -S conftest.c -o conftest.s >/dev/null 2>&1; then
+                if grep '\.hidden.*foo_hidden' conftest.s >/dev/null; then
+                    if ! grep '\.hidden.*foo_default' conftest.s > /dev/null; then
+                        ac_cv_visibility_pragma=yes
+                    fi
+                fi
+            fi
+            rm -f conftest.[cs]
+            ])
+        if test "$ac_cv_visibility_pragma" = "yes"; then
+            AC_DEFINE(HAVE_VISIBILITY_PRAGMA)
+            # To work around a build problem on Linux x86-64 (Bugzilla bug
+            # 293438), we use the -fvisibility=hidden flag.  This flag is less
+            # optimal than #pragma GCC visibility push(hidden) because the flag
+            # assumes that symbols defined outside the current source file have
+            # the default visibility.  This has the advantage that we don't need
+            # to wrap system header files, but has the disadvantage that calls
+            # to hidden symbols defined in other source files cannot be
+            # optimized by the compiler.  The -fvisibility=hidden flag does
+            # hide and export symbols correctly.
+            #VISIBILITY_FLAGS='-I$(dist_includedir)/system_wrappers -include $(topsrcdir)/config/gcc_hidden.h'
+            #WRAP_SYSTEM_INCLUDES=1
+            VISIBILITY_FLAGS="-fvisibility=hidden"
+            WRAP_SYSTEM_INCLUDES=
+        fi
+    fi
+fi # GNU_CC
+
 fi # SKIP_COMPILER_CHECKS
 
 dnl ========================================================
 dnl Checks for programs.
 dnl ========================================================
 if test -z "$SKIP_PATH_CHECKS"; then
     AC_PATH_PROGS(PERL, perl5 perl, echo not_perl)
 elif test -z "$PERL"; then
@@ -1401,16 +1400,21 @@ case "$target" in
                 LDFLAGS="$LDFLAGS -DEBUG -OPT:REF"
             fi
         fi
 
         if test -n "$MOZ_DEBUG"; then
             DLLFLAGS="$DLLFLAGS -DEBUG"
             LDFLAGS="$LDFLAGS -DEBUG"
         fi
+
+        OS_DLLFLAGS="-nologo -DLL -SUBSYSTEM:WINDOWS"
+        if test "$MSC_VER" -le "1200" -a -z "$MOZ_DEBUG_SYMBOLS"; then
+            OS_DLLFLAGS="$OS_DLLFLAGS -PDB:NONE"
+        fi
         
         if test "$OS_TARGET" = "WINNT"; then
             CFLAGS="$CFLAGS -GT"
             if test "$CPU_ARCH" = "x86"; then
                 CFLAGS="$CFLAGS -G5"
             fi
             LIBNSPR='$(dist_libdir)/libnspr$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
             LIBPLC='$(dist_libdir)/libplc$(MOD_MAJOR_VERSION).$(LIB_SUFFIX)'
@@ -1438,21 +1442,16 @@ case "$target" in
     else
         CPU_ARCH_TAG=$CPU_ARCH
     fi
 
     if test -n "$USE_DEBUG_RTL"; then
         OBJDIR_SUFFIX=OBJD
     fi
 
-    OS_DLLFLAGS="-nologo -DLL -SUBSYSTEM:WINDOWS"
-    if test "$MSC_VER" -le "1200" -a -z "$MOZ_DEBUG_SYMBOLS"; then
-        OS_DLLFLAGS="$OS_DLLFLAGS -PDB:NONE"
-    fi
-
     case "$OS_TARGET" in
     WINNT)
 	    MDCPUCFG_H=_winnt.cfg
 	    ;;
     WIN95)
 	    MDCPUCFG_H=_win95.cfg
 	    ;;
     WIN16)
--- a/pr/include/md/_unix_errors.h
+++ b/pr/include/md/_unix_errors.h
@@ -38,134 +38,134 @@
 #ifndef prunixerrors_h___
 #define prunixerrors_h___
 
 #include <unistd.h>
 #include <stddef.h>
 
 PR_BEGIN_EXTERN_C
 
-NSPR_API(void) _MD_unix_map_default_error(int err);
+extern void _MD_unix_map_default_error(int err);
 #define	_PR_MD_MAP_DEFAULT_ERROR	_MD_unix_map_default_error
 
-NSPR_API(void) _MD_unix_map_opendir_error(int err);
+extern void _MD_unix_map_opendir_error(int err);
 #define	_PR_MD_MAP_OPENDIR_ERROR	_MD_unix_map_opendir_error
 
-NSPR_API(void) _MD_unix_map_closedir_error(int err);
+extern void _MD_unix_map_closedir_error(int err);
 #define	_PR_MD_MAP_CLOSEDIR_ERROR	_MD_unix_map_closedir_error
 
-NSPR_API(void) _MD_unix_readdir_error(int err);
+extern void _MD_unix_readdir_error(int err);
 #define	_PR_MD_MAP_READDIR_ERROR	_MD_unix_readdir_error
 
-NSPR_API(void) _MD_unix_map_unlink_error(int err);
+extern void _MD_unix_map_unlink_error(int err);
 #define	_PR_MD_MAP_UNLINK_ERROR	_MD_unix_map_unlink_error
 
-NSPR_API(void) _MD_unix_map_stat_error(int err);
+extern void _MD_unix_map_stat_error(int err);
 #define	_PR_MD_MAP_STAT_ERROR	_MD_unix_map_stat_error
 
-NSPR_API(void) _MD_unix_map_fstat_error(int err);
+extern void _MD_unix_map_fstat_error(int err);
 #define	_PR_MD_MAP_FSTAT_ERROR	_MD_unix_map_fstat_error
 
-NSPR_API(void) _MD_unix_map_rename_error(int err);
+extern void _MD_unix_map_rename_error(int err);
 #define	_PR_MD_MAP_RENAME_ERROR	_MD_unix_map_rename_error
 
-NSPR_API(void) _MD_unix_map_access_error(int err);
+extern void _MD_unix_map_access_error(int err);
 #define	_PR_MD_MAP_ACCESS_ERROR	_MD_unix_map_access_error
 
-NSPR_API(void) _MD_unix_map_mkdir_error(int err);
+extern void _MD_unix_map_mkdir_error(int err);
 #define	_PR_MD_MAP_MKDIR_ERROR	_MD_unix_map_mkdir_error
 
-NSPR_API(void) _MD_unix_map_rmdir_error(int err);
+extern void _MD_unix_map_rmdir_error(int err);
 #define	_PR_MD_MAP_RMDIR_ERROR	_MD_unix_map_rmdir_error
 
-NSPR_API(void) _MD_unix_map_read_error(int err);
+extern void _MD_unix_map_read_error(int err);
 #define	_PR_MD_MAP_READ_ERROR	_MD_unix_map_read_error
 
-NSPR_API(void) _MD_unix_map_write_error(int err);
+extern void _MD_unix_map_write_error(int err);
 #define	_PR_MD_MAP_WRITE_ERROR	_MD_unix_map_write_error
 
-NSPR_API(void) _MD_unix_map_lseek_error(int err);
+extern void _MD_unix_map_lseek_error(int err);
 #define	_PR_MD_MAP_LSEEK_ERROR	_MD_unix_map_lseek_error
 
-NSPR_API(void) _MD_unix_map_fsync_error(int err);
+extern void _MD_unix_map_fsync_error(int err);
 #define	_PR_MD_MAP_FSYNC_ERROR	_MD_unix_map_fsync_error
 
-NSPR_API(void) _MD_unix_map_close_error(int err);
+extern void _MD_unix_map_close_error(int err);
 #define	_PR_MD_MAP_CLOSE_ERROR	_MD_unix_map_close_error
 
-NSPR_API(void) _MD_unix_map_socket_error(int err);
+extern void _MD_unix_map_socket_error(int err);
 #define	_PR_MD_MAP_SOCKET_ERROR	_MD_unix_map_socket_error
 
-NSPR_API(void) _MD_unix_map_socketavailable_error(int err);
+extern void _MD_unix_map_socketavailable_error(int err);
 #define	_PR_MD_MAP_SOCKETAVAILABLE_ERROR	_MD_unix_map_socketavailable_error
 
-NSPR_API(void) _MD_unix_map_recv_error(int err);
+extern void _MD_unix_map_recv_error(int err);
 #define	_PR_MD_MAP_RECV_ERROR	_MD_unix_map_recv_error
 
-NSPR_API(void) _MD_unix_map_recvfrom_error(int err);
+extern void _MD_unix_map_recvfrom_error(int err);
 #define	_PR_MD_MAP_RECVFROM_ERROR	_MD_unix_map_recvfrom_error
 
-NSPR_API(void) _MD_unix_map_send_error(int err);
+extern void _MD_unix_map_send_error(int err);
 #define	_PR_MD_MAP_SEND_ERROR	_MD_unix_map_send_error
 
-NSPR_API(void) _MD_unix_map_sendto_error(int err);
+extern void _MD_unix_map_sendto_error(int err);
 #define	_PR_MD_MAP_SENDTO_ERROR	_MD_unix_map_sendto_error
 
-NSPR_API(void) _MD_unix_map_writev_error(int err);
+extern void _MD_unix_map_writev_error(int err);
 #define	_PR_MD_MAP_WRITEV_ERROR	_MD_unix_map_writev_error
 
-NSPR_API(void) _MD_unix_map_accept_error(int err);
+extern void _MD_unix_map_accept_error(int err);
 #define	_PR_MD_MAP_ACCEPT_ERROR	_MD_unix_map_accept_error
 
-NSPR_API(void) _MD_unix_map_connect_error(int err);
+extern void _MD_unix_map_connect_error(int err);
 #define	_PR_MD_MAP_CONNECT_ERROR	_MD_unix_map_connect_error
 
-NSPR_API(void) _MD_unix_map_bind_error(int err);
+extern void _MD_unix_map_bind_error(int err);
 #define	_PR_MD_MAP_BIND_ERROR	_MD_unix_map_bind_error
 
-NSPR_API(void) _MD_unix_map_listen_error(int err);
+extern void _MD_unix_map_listen_error(int err);
 #define	_PR_MD_MAP_LISTEN_ERROR	_MD_unix_map_listen_error
 
-NSPR_API(void) _MD_unix_map_shutdown_error(int err);
+extern void _MD_unix_map_shutdown_error(int err);
 #define	_PR_MD_MAP_SHUTDOWN_ERROR	_MD_unix_map_shutdown_error
 
-NSPR_API(void) _MD_unix_map_socketpair_error(int err);
+extern void _MD_unix_map_socketpair_error(int err);
 #define	_PR_MD_MAP_SOCKETPAIR_ERROR	_MD_unix_map_socketpair_error
 
-NSPR_API(void) _MD_unix_map_getsockname_error(int err);
+extern void _MD_unix_map_getsockname_error(int err);
 #define	_PR_MD_MAP_GETSOCKNAME_ERROR	_MD_unix_map_getsockname_error
 
-NSPR_API(void) _MD_unix_map_getpeername_error(int err);
+extern void _MD_unix_map_getpeername_error(int err);
 #define	_PR_MD_MAP_GETPEERNAME_ERROR	_MD_unix_map_getpeername_error
 
-NSPR_API(void) _MD_unix_map_getsockopt_error(int err);
+extern void _MD_unix_map_getsockopt_error(int err);
 #define	_PR_MD_MAP_GETSOCKOPT_ERROR	_MD_unix_map_getsockopt_error
 
-NSPR_API(void) _MD_unix_map_setsockopt_error(int err);
+extern void _MD_unix_map_setsockopt_error(int err);
 #define	_PR_MD_MAP_SETSOCKOPT_ERROR	_MD_unix_map_setsockopt_error
 
-NSPR_API(void) _MD_unix_map_open_error(int err);
+extern void _MD_unix_map_open_error(int err);
 #define	_PR_MD_MAP_OPEN_ERROR	_MD_unix_map_open_error
 
-NSPR_API(void) _MD_unix_map_mmap_error(int err);
+extern void _MD_unix_map_mmap_error(int err);
 #define	_PR_MD_MAP_MMAP_ERROR	_MD_unix_map_mmap_error
 
-NSPR_API(void) _MD_unix_map_gethostname_error(int err);
+extern void _MD_unix_map_gethostname_error(int err);
 #define	_PR_MD_MAP_GETHOSTNAME_ERROR	_MD_unix_map_gethostname_error
 
-NSPR_API(void) _MD_unix_map_select_error(int err);
+extern void _MD_unix_map_select_error(int err);
 #define	_PR_MD_MAP_SELECT_ERROR	_MD_unix_map_select_error
 
-NSPR_API(void) _MD_unix_map_poll_error(int err);
+extern void _MD_unix_map_poll_error(int err);
 #define _PR_MD_MAP_POLL_ERROR _MD_unix_map_poll_error
 
-NSPR_API(void) _MD_unix_map_poll_revents_error(int err);
+extern void _MD_unix_map_poll_revents_error(int err);
 #define _PR_MD_MAP_POLL_REVENTS_ERROR _MD_unix_map_poll_revents_error
 
-NSPR_API(void) _MD_unix_map_flock_error(int err);
+extern void _MD_unix_map_flock_error(int err);
 #define	_PR_MD_MAP_FLOCK_ERROR	_MD_unix_map_flock_error
 
-NSPR_API(void) _MD_unix_map_lockf_error(int err);
+extern void _MD_unix_map_lockf_error(int err);
 #define	_PR_MD_MAP_LOCKF_ERROR	_MD_unix_map_lockf_error
 
 PR_END_EXTERN_C
 
 #endif /* prunixerrors_h___ */
--- 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.6 Beta"
+#define PR_VERSION  "4.6"
 #define PR_VMAJOR   4
 #define PR_VMINOR   6
 #define PR_VPATCH   0
-#define PR_BETA     PR_TRUE
+#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/src/md/unix/uxwrap.c
+++ b/pr/src/md/unix/uxwrap.c
@@ -340,17 +340,17 @@ int wrap_poll(void *listptr, unsigned lo
 int poll(void *listptr, unsigned long nfds, long timeout)
 #elif defined(OSF1) || (defined(HPUX) && !defined(HPUX9))
 int poll(struct pollfd filedes[], unsigned int nfds, int timeout)
 #elif defined(HPUX9)
 int poll(struct pollfd filedes[], int nfds, int timeout)
 #elif defined(NETBSD)
 int poll(struct pollfd *filedes, nfds_t nfds, int timeout)
 #elif defined(OPENBSD)
-int poll(struct pollfd *filedes, int nfds, int timeout)
+int poll(struct pollfd filedes[], nfds_t nfds, int timeout)
 #elif defined(FREEBSD)
 int poll(struct pollfd *filedes, unsigned nfds, int timeout)
 #else
 int poll(struct pollfd *filedes, unsigned long nfds, int timeout)
 #endif
 {
 #ifdef AIX
     struct pollfd *filedes = (struct pollfd *) listptr;
--- a/pr/src/pthreads/ptthread.c
+++ b/pr/src/pthreads/ptthread.c
@@ -204,17 +204,20 @@ static void *_pt_root(void *arg)
     PR_Lock(pt_book.ml);
 
     /* If this is a GCABLE thread, set its state appropriately */
     if (thred->suspend & PT_THREAD_SETGCABLE)
 	    thred->state |= PT_THREAD_GCABLE;
     thred->suspend = 0;
 
     thred->prev = pt_book.last;
-    pt_book.last->next = thred;
+    if (pt_book.last)
+        pt_book.last->next = thred;
+    else
+        pt_book.first = thred;
     thred->next = NULL;
     pt_book.last = thred;
     PR_Unlock(pt_book.ml);
 
     thred->startFunc(thred->arg);  /* make visible to the client */
 
     /* unhook the thread from the runtime */
     PR_Lock(pt_book.ml);
@@ -228,17 +231,20 @@ static void *_pt_root(void *arg)
         while (!thred->okToDelete)
             PR_WaitCondVar(pt_book.cv, PR_INTERVAL_NO_TIMEOUT);
     }
 
     if (thred->state & PT_THREAD_SYSTEM)
         pt_book.system -= 1;
     else if (--pt_book.user == pt_book.this_many)
         PR_NotifyAllCondVar(pt_book.cv);
-    thred->prev->next = thred->next;
+    if (NULL == thred->prev)
+        pt_book.first = thred->next;
+    else
+        thred->prev->next = thred->next;
     if (NULL == thred->next)
         pt_book.last = thred->prev;
     else
         thred->next->prev = thred->prev;
     PR_Unlock(pt_book.ml);
 
     /*
     * Here we set the pthread's backpointer to the PRThread to NULL.
@@ -283,17 +289,20 @@ static PRThread* pt_AttachThread(void)
         rv = pthread_setspecific(pt_book.key, thred);
         PR_ASSERT(0 == rv);
 
         thred->state = PT_THREAD_GLOBAL | PT_THREAD_FOREIGN;
         PR_Lock(pt_book.ml);
 
         /* then put it into the list */
         thred->prev = pt_book.last;
-	    pt_book.last->next = thred;
+        if (pt_book.last)
+            pt_book.last->next = thred;
+        else
+            pt_book.first = thred;
         thred->next = NULL;
         pt_book.last = thred;
         PR_Unlock(pt_book.ml);
 
     }
     return thred;  /* may be NULL */
 }  /* pt_AttachThread */
 
@@ -785,20 +794,23 @@ PR_IMPLEMENT(PRStatus) PR_Sleep(PRInterv
     }
     return rv;
 }  /* PR_Sleep */
 
 static void _pt_thread_death(void *arg)
 {
     PRThread *thred = (PRThread*)arg;
 
-    if (thred->state & PT_THREAD_FOREIGN)
+    if (thred->state & (PT_THREAD_FOREIGN|PT_THREAD_PRIMORD))
     {
         PR_Lock(pt_book.ml);
-        thred->prev->next = thred->next;
+        if (NULL == thred->prev)
+            pt_book.first = thred->next;
+        else
+            thred->prev->next = thred->next;
         if (NULL == thred->next)
             pt_book.last = thred->prev;
         else
             thred->next->prev = thred->prev;
         PR_Unlock(pt_book.ml);
     }
     _PR_DestroyThreadPrivate(thred);
     PR_Free(thred->privateData);
@@ -910,16 +922,17 @@ void _PR_InitThreads(
     rv = pthread_setspecific(pt_book.key, thred);
     PR_ASSERT(0 == rv);    
     PR_SetThreadPriority(thred, priority);
 }  /* _PR_InitThreads */
 
 PR_IMPLEMENT(PRStatus) PR_Cleanup(void)
 {
     PRThread *me = PR_CurrentThread();
+    int rv;
     PR_LOG(_pr_thread_lm, PR_LOG_MIN, ("PR_Cleanup: shutting down NSPR"));
     PR_ASSERT(me->state & PT_THREAD_PRIMORD);
     if (me->state & PT_THREAD_PRIMORD)
     {
         PR_Lock(pt_book.ml);
         while (pt_book.user > pt_book.this_many)
             PR_WaitCondVar(pt_book.cv, PR_INTERVAL_NO_TIMEOUT);
         PR_Unlock(pt_book.ml);
@@ -928,28 +941,30 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup(void)
         _PR_CleanupDtoa();
         _PR_CleanupCallOnce();
         _PR_ShutdownLinker();
         _PR_LogCleanup();
         _PR_CleanupNet();
         /* Close all the fd's before calling _PR_CleanupIO */
         _PR_CleanupIO();
 
+        _pt_thread_death(me);
+        rv = pthread_setspecific(pt_book.key, NULL);
+        PR_ASSERT(0 == rv);
         /*
          * I am not sure if it's safe to delete the cv and lock here,
          * since there may still be "system" threads around. If this
          * call isn't immediately prior to exiting, then there's a
          * problem.
          */
         if (0 == pt_book.system)
         {
             PR_DestroyCondVar(pt_book.cv); pt_book.cv = NULL;
             PR_DestroyLock(pt_book.ml); pt_book.ml = NULL;
         }
-        _pt_thread_death(me);
         PR_DestroyLock(_pr_sleeplock);
         _pr_sleeplock = NULL;
         _PR_CleanupLayerCache();
         _PR_CleanupEnv();
 #ifdef _PR_ZONE_ALLOCATOR
         _PR_DestroyZones();
 #endif
         _pr_initialized = PR_FALSE;
--- a/pr/tests/bigfile3.c
+++ b/pr/tests/bigfile3.c
@@ -34,16 +34,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nspr.h"
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #ifdef _WIN32
 #include <windows.h>
 #endif
 
 #define TEST_FILE_NAME "bigfile3.txt"
 
 #define MESSAGE "Hello world!"
 #define MESSAGE_SIZE 13
--- a/pr/tests/env.c
+++ b/pr/tests/env.c
@@ -40,16 +40,17 @@
 ** Description: Testing environment variable operations
 **
 */
 #include "prenv.h"
 #include "plgetopt.h"
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 PRIntn  debug = 0;
 PRIntn  verbose = 0;
 PRBool  failedAlready = PR_FALSE;
 
 #define  ENVNAME    "NSPR_ENVIRONMENT_TEST_VARIABLE"
 #define  ENVVALUE   "The expected result"
 #define  ENVBUFSIZE 256
--- a/pr/tests/initclk.c
+++ b/pr/tests/initclk.c
@@ -44,16 +44,17 @@
  */
 
 #include "prlock.h"
 #include "prcvar.h"
 #include "prthread.h"
 #include "prinrval.h"
 #include "prlog.h"
 #include <stdio.h>
+#include <stdlib.h>
 
 /* The timeouts, in milliseconds */
 #define SHORT_TIMEOUT 1000
 #define LONG_TIMEOUT 3000
 
 PRLock *lock1, *lock2;
 PRCondVar *cv1, *cv2;
 
--- a/pr/tests/layer.c
+++ b/pr/tests/layer.c
@@ -41,16 +41,17 @@
 #include "prnetdb.h"
 #include "prthread.h"
 
 #include "plerror.h"
 #include "plgetopt.h"
 #include "prwin16.h"
 
 #include <stdlib.h>
+#include <string.h>
 
 /*
 ** Testing layering of I/O
 **
 **      The layered server
 ** A thread that acts as a server. It creates a TCP listener with a dummy
 ** layer pushed on top. Then listens for incoming connections. Each connection
 ** request for connection will be layered as well, accept one request, echo
--- a/pr/tests/nbconn.c
+++ b/pr/tests/nbconn.c
@@ -54,16 +54,17 @@
  *    The test should fail after the connect times out.  Ideally the
  *    error code should be PR_IO_TIMEOUT_ERROR, but it is possible to
  *    return PR_UNKNOWN_ERROR on certain platforms.
  */
 
 #include "nspr.h"
 #include "plgetopt.h"
 #include <stdio.h>
+#include <string.h>
 
 #ifdef XP_MAC
 #define printf PR_LogPrint
 extern void SetupMacPrintfLog(char *logFile);
 static char *hosts[4] = {"cynic", "warp", "gandalf", "neon"};
 #endif
 
 #define SERVER_MAX_BIND_COUNT        100
--- a/pr/tests/ntioto.c
+++ b/pr/tests/ntioto.c
@@ -131,20 +131,21 @@ static void AcceptThread(void *arg)
 
     bytesRead = PR_AcceptRead( listenSock, 
         &arSock,
         &arAddr,
         dataBuf,
         ACCEPT_READ_DATASIZE,
         PR_SecondsToInterval(1));
 
-    if ( bytesRead == -1 && PR_GetError() == PR_IO_TIMEOUT_ERROR )
+    if ( bytesRead == -1 && PR_GetError() == PR_IO_TIMEOUT_ERROR ) {
         if ( debug ) printf("AcceptRead timed out\n");
-    else
+    } else {
         if ( debug ) printf("Oops! read: %d, error: %d\n", bytesRead, PR_GetError());
+    }
 
     while( state != AllDone )  {
         PR_Lock( ml );
         while( state != RunAcceptRead )
             PR_WaitCondVar( cv, PR_INTERVAL_NO_TIMEOUT );
         if ( ++iCounter >= jitter )
             state = AllDone;
         else
--- a/pr/tests/op_filnf.c
+++ b/pr/tests/op_filnf.c
@@ -72,20 +72,25 @@ int main(int argc, char **argv)
 
 #ifdef XP_MAC
 	SetupMacPrintfLog("pr_open_re.log");
 #endif
 	
 
     PR_STDIO_INIT();
 	t1 = PR_Open("/usr/tmp/ttools/err03.tmp", PR_TRUNCATE | PR_RDWR, 0666);
-	if (t1 == NULL) 
+	if (t1 == NULL) {
 		if (PR_GetError() == PR_FILE_NOT_FOUND_ERROR) {
 				printf ("error code is %d \n", PR_GetError());
 				printf ("PASS\n");
 				return 0;
 		}
 		else {
 				printf ("error code is %d \n", PR_GetError());
 				printf ("FAIL\n");
 			return 1;
 		}
+	}
+	PR_Close(t1);
+	printf ("opened a file that should not exist\n");
+	printf ("FAIL\n");
+	return 1;
 }			
--- a/pr/tests/prpoll.c
+++ b/pr/tests/prpoll.c
@@ -38,16 +38,20 @@
 #ifdef WIN32
 #include <windows.h>
 #endif
 
 #ifdef XP_OS2_VACPP
 #include <io.h>      /* for close() */
 #endif
 
+#ifdef XP_UNIX
+#include <unistd.h>  /* for close() */
+#endif
+
 #include "prinit.h"
 #include "prio.h"
 #include "prlog.h"
 #include "prprf.h"
 #include "prnetdb.h"
 
 #ifndef XP_MAC
 #include "private/pprio.h"
--- a/pr/tests/randseed.c
+++ b/pr/tests/randseed.c
@@ -41,21 +41,22 @@
 ** Test NSPR's Random Number Seed generator
 **
 ** Initial test: Just make sure it outputs some data.
 ** 
 ** ... more? ... check some iterations to ensure it is random (no dupes)
 ** ... more? ... histogram distribution of random numbers
 */
 
-#include <plgetopt.h> 
-#include <nspr.h> 
-#include <prrng.h> 
+#include "plgetopt.h"
+#include "nspr.h" 
+#include "prrng.h"
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 /*
 ** Test harness infrastructure
 */
 PRLogModuleInfo *lm;
 PRLogModuleLevel msgLevel = PR_LOG_NONE;
 PRIntn  debug = 0;
 PRUint32  failed_already = 0;
--- a/pr/tests/sel_spd.c
+++ b/pr/tests/sel_spd.c
@@ -450,17 +450,17 @@ static void Measure(void (*func)(void), 
     printf("%40s: %6.2f usec\n", msg, d / _iterations);
 }
 
 
 int main(int argc, char **argv)
 {
 #if defined(XP_UNIX) || defined(XP_OS2_EMX)
 	int opt;
-	extern char *optarg;
+	PR_IMPORT_DATA(char *) optarg;
 #endif
 
 #if defined(XP_UNIX) || defined(XP_OS2_EMX)
 	while ( (opt = getopt(argc, argv, "c:s:i:t:v")) != EOF) {
 		switch(opt) {
 			case 'i':
 				_iterations = atoi(optarg);
 				break;
--- a/pr/tests/vercheck.c
+++ b/pr/tests/vercheck.c
@@ -47,39 +47,40 @@
  */
 
 #include "prinit.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 
 /*
- * This release (4.5) is backward compatible with the
- * 4.0.x, 4.1.x, 4.2.x, 4.3.x, and 4.4.x releases.  It, of course,
+ * This release (4.6) is backward compatible with the
+ * 4.0.x, 4.1.x, 4.2.x, 4.3.x, 4.4.x, and 4.5.x releases.  It, of course,
  * is 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", PR_VERSION
+    "4.2", "4.2.1", "4.2.2", "4.3", "4.4", "4.4.1",
+    "4.5", "4.5.1", 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.
  */
 static char *incompatible_version[] = {
     "2.1 19980529",
     "3.0", "3.0.1",
     "3.1", "3.1.1", "3.1.2", "3.1.3",
     "3.5", "3.5.1",
-    "4.5.3",
-    "4.6", "4.6.1",
+    "4.6.3",
+    "4.7", "4.7.1",
     "10.0", "11.1", "12.14.20"
 };
 
 int main()
 {
     int idx;
     int num_compatible = sizeof(compatible_version) / sizeof(char *);
     int num_incompatible = sizeof(incompatible_version) / sizeof(char *);