Bug 1293329, land NSPR_4_13_BETA2, r=ted
authorKai Engert <kaie@kuix.de>
Sat, 27 Aug 2016 11:06:04 +0200
changeset 311571 23ecdb879a8bc66c8c96f9650c7cb60e28399fa1
parent 311570 88248d124b9a88885740b78114be1b11576b4dbc
child 311572 acfb2c3ac6ae0a704e2756184815296ac1314f89
child 311611 2ccbded01c01295b4d87e4a13a8f0f5e3e23dad3
push id30616
push userryanvm@gmail.com
push dateMon, 29 Aug 2016 16:48:19 +0000
treeherdermozilla-central@acfb2c3ac6ae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs1293329
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1293329, land NSPR_4_13_BETA2, r=ted
nsprpub/TAG-INFO
nsprpub/automation/release/nspr-release-helper.py
nsprpub/config/prdepend.h
nsprpub/configure
nsprpub/configure.in
nsprpub/lib/ds/plarena.c
nsprpub/lib/ds/plarena.h
nsprpub/lib/ds/plarenas.h
nsprpub/lib/libc/src/strcase.c
nsprpub/lib/libc/src/strcmp.c
nsprpub/pr/include/prinit.h
nsprpub/pr/include/prio.h
nsprpub/pr/include/prolock.h
nsprpub/pr/src/io/prprf.c
nsprpub/pr/src/misc/prlong.c
nsprpub/pr/tests/sockopt.c
nsprpub/pr/tests/vercheck.c
--- a/nsprpub/TAG-INFO
+++ b/nsprpub/TAG-INFO
@@ -1,1 +1,1 @@
-NSPR_4_12_RTM
+NSPR_4_13_BETA2
new file mode 100644
--- /dev/null
+++ b/nsprpub/automation/release/nspr-release-helper.py
@@ -0,0 +1,179 @@
+#!/usr/bin/python
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+import os
+import sys
+import datetime
+import shutil
+import glob
+from optparse import OptionParser
+from subprocess import check_call
+
+prinit_h = "pr/include/prinit.h"
+f_conf = "configure"
+f_conf_in = "configure.in"
+
+def check_call_noisy(cmd, *args, **kwargs):
+    print "Executing command:", cmd
+    check_call(cmd, *args, **kwargs)
+
+o = OptionParser(usage="client.py [options] remove_beta | set_beta | print_library_versions | set_version_to_minor_release | set_version_to_patch_release | create_nspr_release_archive")
+
+try:
+    options, args = o.parse_args()
+    action = args[0]
+except IndexError:
+    o.print_help()
+    sys.exit(2)
+
+def exit_with_failure(what):
+    print "failure: ", what
+    sys.exit(2)
+
+def check_files_exist():
+    if (not os.path.exists(prinit_h)):
+        exit_with_failure("cannot find expected header files, must run from inside NSPR hg directory")
+
+def sed_inplace(sed_expression, filename):
+    backup_file = filename + '.tmp'
+    check_call_noisy(["sed", "-i.tmp", sed_expression, filename])
+    os.remove(backup_file)
+
+def toggle_beta_status(is_beta):
+    check_files_exist()
+    if (is_beta):
+        print "adding Beta status to version numbers"
+        sed_inplace('s/^\(#define *PR_VERSION *\"[0-9.]\+\)\" *$/\\1 Beta\"/', prinit_h)
+        sed_inplace('s/^\(#define *PR_BETA *\)PR_FALSE *$/\\1PR_TRUE/', prinit_h)
+
+    else:
+        print "removing Beta status from version numbers"
+        sed_inplace('s/^\(#define *PR_VERSION *\"[0-9.]\+\) *Beta\" *$/\\1\"/', prinit_h)
+        sed_inplace('s/^\(#define *PR_BETA *\)PR_TRUE *$/\\1PR_FALSE/', prinit_h)
+    print "please run 'hg stat' and 'hg diff' to verify the files have been verified correctly"
+
+def print_beta_versions():
+    check_call_noisy(["egrep", "#define *PR_VERSION|#define *PR_BETA", prinit_h])
+
+def remove_beta_status():
+    print "--- removing beta flags. Existing versions were:"
+    print_beta_versions()
+    toggle_beta_status(False)
+    print "--- finished modifications, new versions are:"
+    print_beta_versions()
+
+def set_beta_status():
+    print "--- adding beta flags. Existing versions were:"
+    print_beta_versions()
+    toggle_beta_status(True)
+    print "--- finished modifications, new versions are:"
+    print_beta_versions()
+
+def print_library_versions():
+    check_files_exist()
+    check_call_noisy(["egrep", "#define *PR_VERSION|#define PR_VMAJOR|#define *PR_VMINOR|#define *PR_VPATCH|#define *PR_BETA", prinit_h])
+
+def ensure_arguments_after_action(how_many, usage):
+    if (len(sys.argv) != (2+how_many)):
+        exit_with_failure("incorrect number of arguments, expected parameters are:\n" + usage)
+
+def set_major_versions(major):
+    sed_inplace('s/^\(#define *PR_VMAJOR *\).*$/\\1' + major + '/', prinit_h)
+    sed_inplace('s/^MOD_MAJOR_VERSION=.*$/MOD_MAJOR_VERSION=' + major + '/', f_conf)
+    sed_inplace('s/^MOD_MAJOR_VERSION=.*$/MOD_MAJOR_VERSION=' + major + '/', f_conf_in)
+
+def set_minor_versions(minor):
+    sed_inplace('s/^\(#define *PR_VMINOR *\).*$/\\1' + minor + '/', prinit_h)
+    sed_inplace('s/^MOD_MINOR_VERSION=.*$/MOD_MINOR_VERSION=' + minor + '/', f_conf)
+    sed_inplace('s/^MOD_MINOR_VERSION=.*$/MOD_MINOR_VERSION=' + minor + '/', f_conf_in)
+
+def set_patch_versions(patch):
+    sed_inplace('s/^\(#define *PR_VPATCH *\).*$/\\1' + patch + '/', prinit_h)
+    sed_inplace('s/^MOD_PATCH_VERSION=.*$/MOD_PATCH_VERSION=' + patch + '/', f_conf)
+    sed_inplace('s/^MOD_PATCH_VERSION=.*$/MOD_PATCH_VERSION=' + patch + '/', f_conf_in)
+
+def set_full_lib_versions(version):
+    sed_inplace('s/^\(#define *PR_VERSION *\"\)\([0-9.]\+\)\(.*\)$/\\1' + version + '\\3/', prinit_h)
+
+def set_all_lib_versions(version, major, minor, patch):
+    set_full_lib_versions(version)
+    set_major_versions(major)
+    set_minor_versions(minor)
+    set_patch_versions(patch)
+    print
+    print "==========================="
+    print "======== ATTENTION ========"
+    print
+    print "You *MUST* manually edit file pr/tests/vercheck.c"
+    print
+    print "Edit two arrays, named compatible_version and incompatible_version"
+    print "according to the new version you're adding."
+    print
+    print "======== ATTENTION ========"
+    print "==========================="
+
+def set_version_to_minor_release():
+    ensure_arguments_after_action(2, "major_version  minor_version")
+    major = args[1].strip()
+    minor = args[2].strip()
+    version = major + '.' + minor
+    patch = "0"
+    set_all_lib_versions(version, major, minor, patch)
+
+def set_version_to_patch_release():
+    ensure_arguments_after_action(3, "major_version  minor_version  patch_release")
+    major = args[1].strip()
+    minor = args[2].strip()
+    patch = args[3].strip()
+    version = major + '.' + minor + '.' + patch
+    set_all_lib_versions(version, major, minor, patch)
+
+def create_nspr_release_archive():
+    ensure_arguments_after_action(2, "nspr_release_version  nspr_hg_release_tag")
+    nsprrel = args[1].strip() #e.g. 4.10.9
+    nsprreltag = args[2].strip() #e.g. NSPR_4_10_9_RTM
+
+    nspr_tar = "nspr-" + nsprrel + ".tar.gz"
+    nspr_stagedir="../stage/v" + nsprrel + "/src"
+    if (os.path.exists(nspr_stagedir)):
+        exit_with_failure("nspr stage directory already exists: " + nspr_stagedir)
+
+    check_call_noisy(["mkdir", "-p", nspr_stagedir])
+    check_call_noisy(["hg", "archive", "-r", nsprreltag, "--prefix=nspr-" + nsprrel + "/nspr",
+                      "../stage/v" + nsprrel + "/src/" + nspr_tar, "-X", ".hgtags"])
+    print "changing to directory " + nspr_stagedir
+    os.chdir(nspr_stagedir)
+
+    check_call("sha1sum " + nspr_tar + " > SHA1SUMS", shell=True)
+    check_call("sha256sum " + nspr_tar + " > SHA256SUMS", shell=True)
+    print "created directory " + nspr_stagedir + " with files:"
+    check_call_noisy(["ls", "-l"])
+
+if action in ('remove_beta'):
+    remove_beta_status()
+
+elif action in ('set_beta'):
+    set_beta_status()
+
+elif action in ('print_library_versions'):
+    print_library_versions()
+
+# x.y version number - 2 parameters
+elif action in ('set_version_to_minor_release'):
+    set_version_to_minor_release()
+
+# x.y.z version number - 3 parameters
+elif action in ('set_version_to_patch_release'):
+    set_version_to_patch_release()
+
+elif action in ('create_nspr_release_archive'):
+    create_nspr_release_archive()
+
+else:
+    o.print_help()
+    sys.exit(2)
+
+sys.exit(0)
--- a/nsprpub/config/prdepend.h
+++ b/nsprpub/config/prdepend.h
@@ -5,9 +5,8 @@
 
 /*
  * A dummy header file that is a dependency for all the object files.
  * Used to force a full recompilation of NSPR in Mozilla's Tinderbox
  * depend builds.  See comments in rules.mk.
  */
 
 #error "Do not include this header file."
-
--- a/nsprpub/configure
+++ b/nsprpub/configure
@@ -2483,17 +2483,17 @@ case $target_os in *\ *) target_os=`echo
 # The aliases save the names the user supplied, while $host etc.
 # will get canonicalized.
 test -n "$target_alias" &&
   test "$program_prefix$program_suffix$program_transform_name" = \
     NONENONEs,x,x, &&
   program_prefix=${target_alias}-
 
 MOD_MAJOR_VERSION=4
-MOD_MINOR_VERSION=12
+MOD_MINOR_VERSION=13
 MOD_PATCH_VERSION=0
 NSPR_MODNAME=nspr20
 _HAVE_PTHREADS=
 USE_PTHREADS=
 USE_USER_PTHREADS=
 USE_NSPR_THREADS=
 USE_N32=
 USE_X32=
--- a/nsprpub/configure.in
+++ b/nsprpub/configure.in
@@ -10,17 +10,17 @@ AC_CONFIG_SRCDIR([pr/include/nspr.h])
 
 AC_CONFIG_AUX_DIR(${srcdir}/build/autoconf)
 AC_CANONICAL_TARGET
 
 dnl ========================================================
 dnl = Defaults
 dnl ========================================================
 MOD_MAJOR_VERSION=4
-MOD_MINOR_VERSION=12
+MOD_MINOR_VERSION=13
 MOD_PATCH_VERSION=0
 NSPR_MODNAME=nspr20
 _HAVE_PTHREADS=
 USE_PTHREADS=
 USE_USER_PTHREADS=
 USE_NSPR_THREADS=
 USE_N32=
 USE_X32=
--- a/nsprpub/lib/ds/plarena.c
+++ b/nsprpub/lib/ds/plarena.c
@@ -12,71 +12,26 @@
 #include <string.h>
 #include "plarena.h"
 #include "prmem.h"
 #include "prbit.h"
 #include "prlog.h"
 #include "prlock.h"
 #include "prinit.h"
 
-static PLArena *arena_freelist;
-
 #ifdef PL_ARENAMETER
 static PLArenaStats *arena_stats_list;
 
 #define COUNT(pool,what)  (pool)->stats.what++
 #else
 #define COUNT(pool,what)  /* nothing */
 #endif
 
 #define PL_ARENA_DEFAULT_ALIGN  sizeof(double)
 
-static PRLock    *arenaLock;
-static PRCallOnceType once;
-static const PRCallOnceType pristineCallOnce;
-
-/*
-** InitializeArenas() -- Initialize arena operations.
-**
-** InitializeArenas() is called exactly once and only once from 
-** LockArena(). This function creates the arena protection 
-** lock: arenaLock.
-**
-** Note: If the arenaLock cannot be created, InitializeArenas()
-** fails quietly, returning only PR_FAILURE. This percolates up
-** to the application using the Arena API. He gets no arena
-** from PL_ArenaAllocate(). It's up to him to fail gracefully
-** or recover.
-**
-*/
-static PRStatus InitializeArenas( void )
-{
-    PR_ASSERT( arenaLock == NULL );
-    arenaLock = PR_NewLock();
-    if ( arenaLock == NULL )
-        return PR_FAILURE;
-    else
-        return PR_SUCCESS;
-} /* end ArenaInitialize() */
-
-static PRStatus LockArena( void )
-{
-    PRStatus rc = PR_CallOnce( &once, InitializeArenas );
-
-    if ( PR_FAILURE != rc )
-        PR_Lock( arenaLock );
-    return(rc);
-} /* end LockArena() */
-
-static void UnlockArena( void )
-{
-    PR_Unlock( arenaLock );
-    return;
-} /* end UnlockArena() */
-
 PR_IMPLEMENT(void) PL_InitArenaPool(
     PLArenaPool *pool, const char *name, PRUint32 size, PRUint32 align)
 {
     /*
      * Look-up table of PR_BITMASK(PR_CeilingLog2(align)) values for
      * align = 1 to 32.
      */
     static const PRUint8 pmasks[33] = {
@@ -119,24 +74,17 @@ PR_IMPLEMENT(void) PL_InitArenaPool(
 
 /*
 ** PL_ArenaAllocate() -- allocate space from an arena pool
 ** 
 ** Description: PL_ArenaAllocate() allocates space from an arena
 ** pool. 
 **
 ** First, try to satisfy the request from arenas starting at
-** pool->current.
-**
-** If there is not enough space in the arena pool->current, try
-** to claim an arena, on a first fit basis, from the global
-** freelist (arena_freelist).
-** 
-** If no arena in arena_freelist is suitable, then try to
-** allocate a new arena from the heap.
+** pool->current. Then try to allocate a new arena from the heap.
 **
 ** Returns: pointer to allocated space or NULL
 ** 
 ** Notes: The original implementation had some difficult to
 ** solve bugs; the code was difficult to read. Sometimes it's
 ** just easier to rewrite it. I did that. larryh.
 **
 ** See also: bugzilla: 45343.
@@ -164,47 +112,16 @@ PR_IMPLEMENT(void *) PL_ArenaAllocate(PL
                 pool->current = a;
                 rp = (char *)a->avail;
                 a->avail += nb;
                 return rp;
             }
         } while( NULL != (a = a->next) );
     }
 
-    /* attempt to allocate from arena_freelist */
-    {
-        PLArena *p; /* previous pointer, for unlinking from freelist */
-
-        /* lock the arena_freelist. Make access to the freelist MT-Safe */
-        if ( PR_FAILURE == LockArena())
-            return(0);
-
-        for ( a = arena_freelist, p = NULL; a != NULL ; p = a, a = a->next ) {
-            if ( nb <= a->limit - a->base )  {
-                if ( p == NULL )
-                    arena_freelist = a->next;
-                else
-                    p->next = a->next;
-                UnlockArena();
-                a->avail = a->base;
-                rp = (char *)a->avail;
-                a->avail += nb;
-                /* the newly allocated arena is linked after pool->current 
-                *  and becomes pool->current */
-                a->next = pool->current->next;
-                pool->current->next = a;
-                pool->current = a;
-                if ( NULL == pool->first.next )
-                    pool->first.next = a;
-                return(rp);
-            }
-        }
-        UnlockArena();
-    }
-
     /* attempt to allocate from the heap */ 
     {  
         PRUint32 sz = PR_MAX(pool->arenasize, nb);
         if (PR_UINT32_MAX - sz < sizeof *a + pool->mask) {
             a = NULL;
         } else {
             sz += sizeof *a + pool->mask;  /* header and alignment slop */
             a = (PLArena*)PR_MALLOC(sz);
@@ -241,95 +158,73 @@ PR_IMPLEMENT(void *) PL_ArenaGrow(
     if (PR_UINT32_MAX - size < incr)
         return NULL;
     PL_ARENA_ALLOCATE(newp, pool, size + incr);
     if (newp)
         memcpy(newp, p, size);
     return newp;
 }
 
-static void ClearArenaList(PLArena *a, PRInt32 pattern)
+PR_IMPLEMENT(void) PL_ClearArenaPool(PLArenaPool *pool, PRInt32 pattern)
 {
+    PLArena *a;
 
-    for (; a; a = a->next) {
+    for (a = pool->first.next; a; a = a->next) {
         PR_ASSERT(a->base <= a->avail && a->avail <= a->limit);
         a->avail = a->base;
         PL_CLEAR_UNUSED_PATTERN(a, pattern);
         PL_MAKE_MEM_NOACCESS((void*)a->avail, a->limit - a->avail);
     }
 }
 
-PR_IMPLEMENT(void) PL_ClearArenaPool(PLArenaPool *pool, PRInt32 pattern)
-{
-    ClearArenaList(pool->first.next, pattern);
-}
-
 /*
  * Free tail arenas linked after head, which may not be the true list head.
  * Reset pool->current to point to head in case it pointed at a tail arena.
  */
-static void FreeArenaList(PLArenaPool *pool, PLArena *head, PRBool reallyFree)
+static void FreeArenaList(PLArenaPool *pool, PLArena *head)
 {
-    PLArena **ap, *a;
-
-    ap = &head->next;
-    a = *ap;
+    PLArena *a = head->next;
     if (!a)
         return;
 
-#ifdef DEBUG
-    ClearArenaList(a, PL_FREE_PATTERN);
-#endif
+    head->next = NULL;
 
-    if (reallyFree) {
-        do {
-            *ap = a->next;
-            PL_CLEAR_ARENA(a);
-            PL_COUNT_ARENA(pool,--);
-            PR_DELETE(a);
-        } while ((a = *ap) != 0);
-    } else {
-        /* Insert the whole arena chain at the front of the freelist. */
-        do {
-            PL_MAKE_MEM_NOACCESS((void*)(*ap)->base,
-                                 (*ap)->limit - (*ap)->base);
-            ap = &(*ap)->next;
-        } while (*ap);
-        LockArena();
-        *ap = arena_freelist;
-        arena_freelist = a;
-        head->next = 0;
-        UnlockArena();
-    }
+    do {
+        PLArena *tmp = a;
+        a = a->next;
+        PL_CLEAR_ARENA(tmp);
+        PL_COUNT_ARENA(pool,--);
+        PR_DELETE(tmp);
+    } while (a);
 
     pool->current = head;
 }
 
 PR_IMPLEMENT(void) PL_ArenaRelease(PLArenaPool *pool, char *mark)
 {
     PLArena *a;
 
     for (a = &pool->first; a; a = a->next) {
         if (PR_UPTRDIFF(mark, a->base) <= PR_UPTRDIFF(a->avail, a->base)) {
             a->avail = (PRUword)PL_ARENA_ALIGN(pool, mark);
-            FreeArenaList(pool, a, PR_FALSE);
+            FreeArenaList(pool, a);
             return;
         }
     }
 }
 
 PR_IMPLEMENT(void) PL_FreeArenaPool(PLArenaPool *pool)
 {
-    FreeArenaList(pool, &pool->first, PR_FALSE);
+    FreeArenaList(pool, &pool->first);
     COUNT(pool, ndeallocs);
 }
 
 PR_IMPLEMENT(void) PL_FinishArenaPool(PLArenaPool *pool)
 {
-    FreeArenaList(pool, &pool->first, PR_TRUE);
+    FreeArenaList(pool, &pool->first);
 #ifdef PL_ARENAMETER
     {
         PLArenaStats *stats, **statsp;
 
         if (pool->stats.name)
             PR_DELETE(pool->stats.name);
         for (statsp = &arena_stats_list; (stats = *statsp) != 0;
              statsp = &stats->next) {
@@ -343,29 +238,16 @@ PR_IMPLEMENT(void) PL_FinishArenaPool(PL
 }
 
 PR_IMPLEMENT(void) PL_CompactArenaPool(PLArenaPool *ap)
 {
 }
 
 PR_IMPLEMENT(void) PL_ArenaFinish(void)
 {
-    PLArena *a, *next;
-
-    for (a = arena_freelist; a; a = next) {
-        next = a->next;
-        PR_DELETE(a);
-    }
-    arena_freelist = NULL;
-
-    if (arenaLock) {
-        PR_DestroyLock(arenaLock);
-        arenaLock = NULL;
-    }
-    once = pristineCallOnce;
 }
 
 PR_IMPLEMENT(size_t) PL_SizeOfArenaPoolExcludingPool(
     const PLArenaPool *pool, PLMallocSizeFn mallocSizeOf)
 {
     /*
      * The first PLArena is within |pool|, so don't measure it.  Subsequent
      * PLArenas are separate and must be measured.
--- a/nsprpub/lib/ds/plarena.h
+++ b/nsprpub/lib/ds/plarena.h
@@ -8,17 +8,16 @@
 /*
  * Lifetime-based fast allocation, inspired by much prior art, including
  * "Fast Allocation and Deallocation of Memory Based on Object Lifetimes"
  * David R. Hanson, Software -- Practice and Experience, Vol. 20(1).
  *
  * Also supports LIFO allocation (PL_ARENA_MARK/PL_ARENA_RELEASE).
  */
 #include "prtypes.h"
-#include "plarenas.h"
 
 PR_BEGIN_EXTERN_C
 
 typedef struct PLArena          PLArena;
 
 struct PLArena {
     PLArena     *next;          /* next arena for this lifetime */
     PRUword     base;           /* aligned base address, follows this header */
@@ -42,16 +41,18 @@ struct PLArenaStats {
     PRUint32      nreleases;    /* number of PL_ARENA_RELEASE() calls */
     PRUint32      nfastrels;    /* number of "fast path" releases */
     PRUint32      nbytes;       /* total bytes allocated */
     PRUint32      maxalloc;     /* maximum allocation size in bytes */
     PRFloat64     variance;     /* size variance accumulator */
 };
 #endif
 
+typedef struct PLArenaPool      PLArenaPool;
+
 struct PLArenaPool {
     PLArena     first;          /* first arena in pool list */
     PLArena     *current;       /* arena from which to allocate space */
     PRUint32    arenasize;      /* net exact size of a new arena */
     PRUword     mask;           /* alignment mask (power-of-2 - 1) */
 #ifdef PL_ARENAMETER
     PLArenaStats stats;
 #endif
@@ -220,16 +221,84 @@ PR_IMPORT(void) __asan_unpoison_memory_r
         PL_COUNT_ARENA(pool,--); \
         if ((pool)->current == (a)) (pool)->current = &(pool)->first; \
         *(pnext) = (a)->next; \
         PL_CLEAR_ARENA(a); \
         free(a); \
         (a) = 0; \
     PR_END_MACRO
 
+/*
+** Initialize an arena pool with the given name for debugging and metering,
+** with a minimum gross size per arena of size bytes.  The net size per arena
+** is smaller than the gross size by a header of four pointers plus any
+** necessary padding for alignment.
+**
+** Note: choose a gross size that's a power of two to avoid the heap allocator
+** rounding the size up.
+**/
+PR_EXTERN(void) PL_InitArenaPool(
+    PLArenaPool *pool, const char *name, PRUint32 size, PRUint32 align);
+
+/*
+** Finish using arenas, freeing all memory associated with them.
+** NOTE: this function is now a no-op. If you want to free a single
+** PLArenaPoolUse use PL_FreeArenaPool() or PL_FinishArenaPool().
+**/
+PR_EXTERN(void) PL_ArenaFinish(void);
+
+/*
+** Free the arenas in pool.  The user may continue to allocate from pool
+** after calling this function.  There is no need to call PL_InitArenaPool()
+** again unless PL_FinishArenaPool(pool) has been called.
+**/
+PR_EXTERN(void) PL_FreeArenaPool(PLArenaPool *pool);
+
+/*
+** Free the arenas in pool and finish using it altogether.
+**/
+PR_EXTERN(void) PL_FinishArenaPool(PLArenaPool *pool);
+
+/*
+** Compact all of the arenas in a pool so that no space is wasted.
+** NOT IMPLEMENTED.  Do not use.
+**/
+PR_EXTERN(void) PL_CompactArenaPool(PLArenaPool *pool);
+
+/*
+** Friend functions used by the PL_ARENA_*() macros.
+**
+** WARNING: do not call these functions directly. Always use the
+** PL_ARENA_*() macros.
+**/
+PR_EXTERN(void *) PL_ArenaAllocate(PLArenaPool *pool, PRUint32 nb);
+
+PR_EXTERN(void *) PL_ArenaGrow(
+    PLArenaPool *pool, void *p, PRUint32 size, PRUint32 incr);
+
+PR_EXTERN(void) PL_ArenaRelease(PLArenaPool *pool, char *mark);
+
+/*
+** memset contents of all arenas in pool to pattern
+*/
+PR_EXTERN(void) PL_ClearArenaPool(PLArenaPool *pool, PRInt32 pattern);
+
+/*
+** A function like malloc_size() or malloc_usable_size() that measures the
+** size of a heap block.
+*/
+typedef size_t (*PLMallocSizeFn)(const void *ptr);
+
+/*
+** Measure all memory used by a PLArenaPool, excluding the PLArenaPool
+** structure.
+*/
+PR_EXTERN(size_t) PL_SizeOfArenaPoolExcludingPool(
+    const PLArenaPool *pool, PLMallocSizeFn mallocSizeOf);
+
 #ifdef PL_ARENAMETER
 
 #include <stdio.h>
 
 PR_EXTERN(void) PL_ArenaCountAllocation(PLArenaPool *pool, PRUint32 nb);
 
 PR_EXTERN(void) PL_ArenaCountInplaceGrowth(
     PLArenaPool *pool, PRUint32 size, PRUint32 incr);
--- a/nsprpub/lib/ds/plarenas.h
+++ b/nsprpub/lib/ds/plarenas.h
@@ -1,81 +1,12 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifndef PLARENAS_H
-#define PLARENAS_H
-
-PR_BEGIN_EXTERN_C
-
-typedef struct PLArenaPool      PLArenaPool;
-
 /*
-** Initialize an arena pool with the given name for debugging and metering,
-** with a minimum gross size per arena of size bytes.  The net size per arena
-** is smaller than the gross size by a header of four pointers plus any
-** necessary padding for alignment.
-**
-** Note: choose a gross size that's a power of two to avoid the heap allocator
-** rounding the size up.
-**/
-PR_EXTERN(void) PL_InitArenaPool(
-    PLArenaPool *pool, const char *name, PRUint32 size, PRUint32 align);
-
-/*
-** Finish using arenas, freeing all memory associated with them.
-**/
-PR_EXTERN(void) PL_ArenaFinish(void);
-
-/*
-** Free the arenas in pool.  The user may continue to allocate from pool
-** after calling this function.  There is no need to call PL_InitArenaPool()
-** again unless PL_FinishArenaPool(pool) has been called.
-**/
-PR_EXTERN(void) PL_FreeArenaPool(PLArenaPool *pool);
-
-/*
-** Free the arenas in pool and finish using it altogether.
+** PLArena-related declarations used to be split between plarenas.h and
+** plarena.h. That split wasn't useful, so now all the declarations are in
+** plarena.h. However, this file still exists so that any old code that
+** includes it will still work.
 **/
-PR_EXTERN(void) PL_FinishArenaPool(PLArenaPool *pool);
-
-/*
-** Compact all of the arenas in a pool so that no space is wasted.
-** NOT IMPLEMENTED.  Do not use.
-**/
-PR_EXTERN(void) PL_CompactArenaPool(PLArenaPool *pool);
-
-/*
-** Friend functions used by the PL_ARENA_*() macros.
-**
-** WARNING: do not call these functions directly. Always use the
-** PL_ARENA_*() macros.
-**/
-PR_EXTERN(void *) PL_ArenaAllocate(PLArenaPool *pool, PRUint32 nb);
-
-PR_EXTERN(void *) PL_ArenaGrow(
-    PLArenaPool *pool, void *p, PRUint32 size, PRUint32 incr);
-
-PR_EXTERN(void) PL_ArenaRelease(PLArenaPool *pool, char *mark);
-
-/*
-** memset contents of all arenas in pool to pattern
-*/
-PR_EXTERN(void) PL_ClearArenaPool(PLArenaPool *pool, PRInt32 pattern);
-
-/*
-** A function like malloc_size() or malloc_usable_size() that measures the
-** size of a heap block.
-*/
-typedef size_t (*PLMallocSizeFn)(const void *ptr);
-
-/*
-** Measure all memory used by a PLArenaPool, excluding the PLArenaPool
-** structure.
-*/
-PR_EXTERN(size_t) PL_SizeOfArenaPoolExcludingPool(
-    const PLArenaPool *pool, PLMallocSizeFn mallocSizeOf);
-
-PR_END_EXTERN_C
-
-#endif /* PLARENAS_H */
+#include "plarena.h"
--- a/nsprpub/lib/libc/src/strcase.c
+++ b/nsprpub/lib/libc/src/strcase.c
@@ -43,18 +43,20 @@ static const unsigned char uc[] =
 };
 
 PR_IMPLEMENT(PRIntn)
 PL_strcasecmp(const char *a, const char *b)
 {
     const unsigned char *ua = (const unsigned char *)a;
     const unsigned char *ub = (const unsigned char *)b;
 
-    if( ((const char *)0 == a) || (const char *)0 == b ) 
-        return (PRIntn)(a-b);
+    if( (const char *)0 == a )
+        return ((const char *)0 == b) ? 0 : -1;
+    if( (const char *)0 == b )
+        return 1;
 
     while( (uc[*ua] == uc[*ub]) && ('\0' != *a) )
     {
         a++;
         ua++;
         ub++;
     }
 
@@ -62,18 +64,20 @@ PL_strcasecmp(const char *a, const char 
 }
 
 PR_IMPLEMENT(PRIntn)
 PL_strncasecmp(const char *a, const char *b, PRUint32 max)
 {
     const unsigned char *ua = (const unsigned char *)a;
     const unsigned char *ub = (const unsigned char *)b;
 
-    if( ((const char *)0 == a) || (const char *)0 == b ) 
-        return (PRIntn)(a-b);
+    if( (const char *)0 == a )
+        return ((const char *)0 == b) ? 0 : -1;
+    if( (const char *)0 == b )
+        return 1;
 
     while( max && (uc[*ua] == uc[*ub]) && ('\0' != *a) )
     {
         a++;
         ua++;
         ub++;
         max--;
     }
--- a/nsprpub/lib/libc/src/strcmp.c
+++ b/nsprpub/lib/libc/src/strcmp.c
@@ -4,22 +4,26 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "plstr.h"
 #include <string.h>
 
 PR_IMPLEMENT(PRIntn)
 PL_strcmp(const char *a, const char *b)
 {
-    if( ((const char *)0 == a) || (const char *)0 == b ) 
-        return (PRIntn)(a-b);
+    if( (const char *)0 == a )
+        return ((const char *)0 == b) ? 0 : -1;
+    if( (const char *)0 == b )
+        return 1;
 
     return (PRIntn)strcmp(a, b);
 }
 
 PR_IMPLEMENT(PRIntn)
 PL_strncmp(const char *a, const char *b, PRUint32 max)
 {
-    if( ((const char *)0 == a) || (const char *)0 == b ) 
-        return (PRIntn)(a-b);
+    if( (const char *)0 == a )
+        return ((const char *)0 == b) ? 0 : -1;
+    if( (const char *)0 == b )
+        return 1;
 
     return (PRIntn)strncmp(a, b, (size_t)max);
 }
--- a/nsprpub/pr/include/prinit.h
+++ b/nsprpub/pr/include/prinit.h
@@ -26,21 +26,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.12"
+#define PR_VERSION  "4.13 Beta"
 #define PR_VMAJOR   4
-#define PR_VMINOR   12
+#define PR_VMINOR   13
 #define PR_VPATCH   0
-#define PR_BETA     PR_FALSE
+#define PR_BETA     PR_TRUE
 
 /*
 ** 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/nsprpub/pr/include/prio.h
+++ b/nsprpub/pr/include/prio.h
@@ -191,18 +191,18 @@ union PRNetAddr {
 ***************************************************************************
 */
 typedef enum PRSockOption
 {
     PR_SockOpt_Nonblocking,     /* nonblocking io */
     PR_SockOpt_Linger,          /* linger on close if data present */
     PR_SockOpt_Reuseaddr,       /* allow local address reuse */
     PR_SockOpt_Keepalive,       /* keep connections alive */
-    PR_SockOpt_RecvBufferSize,  /* send buffer size */
-    PR_SockOpt_SendBufferSize,  /* receive buffer size */
+    PR_SockOpt_RecvBufferSize,  /* receive buffer size */
+    PR_SockOpt_SendBufferSize,  /* send buffer size */
 
     PR_SockOpt_IpTimeToLive,    /* time to live */
     PR_SockOpt_IpTypeOfService, /* type of service and precedence */
 
     PR_SockOpt_AddMember,       /* add an IP group membership */
     PR_SockOpt_DropMember,      /* drop an IP group membership */
     PR_SockOpt_McastInterface,  /* multicast interface address */
     PR_SockOpt_McastTimeToLive, /* multicast timetolive */
--- a/nsprpub/pr/include/prolock.h
+++ b/nsprpub/pr/include/prolock.h
@@ -6,31 +6,31 @@
 #ifndef prolock_h___
 #define prolock_h___
 
 #include "prtypes.h"
 
 PR_BEGIN_EXTERN_C
 
 /*
-** A locking mechanism, built on the existing PRLock definiion,
+** A locking mechanism, built on the existing PRLock definition,
 ** is provided that will permit applications to define a Lock
 ** Hierarchy (or Lock Ordering) schema. An application designed
 ** using the Ordered Lock functions will terminate with a
 ** diagnostic message when a lock inversion condition is
 ** detected. 
 ** 
-** The lock ordering detection is complile-time enabled only. in
+** The lock ordering detection is compile-time enabled only. In
 ** optimized builds of NSPR, the Ordered Lock functions map
 ** directly to PRLock functions, providing no lock order
 ** detection.
 ** 
 ** The Ordered Lock Facility is compiled in when DEBUG is defined at
-** compile time. Ordered Lock can be forced on in optimized builds by
-** defining FORCE_NSPR_ORDERED_LOCK at compile time. Both the
+** compile-time. Ordered Lock can be forced on in optimized builds by
+** defining FORCE_NSPR_ORDERED_LOCK at compile-time. Both the
 ** application using Ordered Lock and NSPR must be compiled with the
 ** facility enabled to achieve the desired results.
 ** 
 ** Application designers should use the macro interfaces to the Ordered
 ** Lock facility to ensure that it is compiled out in optimized builds.
 **
 ** Application designers are responsible for defining their own
 ** lock hierarchy. 
--- a/nsprpub/pr/src/io/prprf.c
+++ b/nsprpub/pr/src/io/prprf.c
@@ -456,17 +456,17 @@ static struct NumArg* BuildArgArray( con
 
     p = fmt;
     while( ( c = *p++ ) != 0 ){
     	if( c != '%' )	continue;
 	    c = *p++;
 	if( c == '%' )	continue;
 
 	cn = 0;
-	while( c && c != '$' ){	    /* should imporve error check later */
+	while( c && c != '$' ){	    /* should improve error check later */
 	    cn = cn*10 + c - '0';
 	    c = *p++;
 	}
 
 	if( !c || cn < 1 || cn > number ){
 	    *rv = -1;
 	    break;
         }
@@ -740,17 +740,17 @@ static int dosprintf(SprintfState *ss, c
 		return rv;
 	    }
 	    continue;
 	}
 
 	if( nas != NULL ){
 	    /* the fmt contains the Numbered Arguments feature */
 	    i = 0;
-	    while( c && c != '$' ){	    /* should imporve error check later */
+	    while( c && c != '$' ){	    /* should improve error check later */
 		i = ( i * 10 ) + ( c - '0' );
 		c = *fmt++;
 	    }
 
 	    if( nas[i-1].type == TYPE_UNKNOWN ){
 		if( nas && ( nas != nasArray ) )
 		    PR_DELETE( nas );
 		return -1;
--- a/nsprpub/pr/src/misc/prlong.c
+++ b/nsprpub/pr/src/misc/prlong.c
@@ -1,19 +1,19 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "prlong.h"
 
-static PRInt64 ll_zero = LL_INIT( 0x00000000,0x00000000 );
-static PRInt64 ll_maxint = LL_INIT( 0x7fffffff, 0xffffffff );
-static PRInt64 ll_minint = LL_INIT( 0x80000000, 0x00000000 );
-static PRUint64 ll_maxuint = LL_INIT( 0xffffffff, 0xffffffff );
+static PRInt64 ll_zero = PR_INT64(0x0000000000000000);
+static PRInt64 ll_maxint = PR_INT64(0x7fffffffffffffff);
+static PRInt64 ll_minint = PR_INT64(0x8000000000000000);
+static PRUint64 ll_maxuint = PR_UINT64(0xffffffffffffffff);
 
 PR_IMPLEMENT(PRInt64) LL_Zero(void) { return ll_zero; }
 PR_IMPLEMENT(PRInt64) LL_MaxInt(void) { return ll_maxint; }
 PR_IMPLEMENT(PRInt64) LL_MinInt(void) { return ll_minint; }
 PR_IMPLEMENT(PRUint64) LL_MaxUint(void) { return ll_maxuint; }
 
 #ifndef HAVE_LONG_LONG
 /*
--- a/nsprpub/pr/tests/sockopt.c
+++ b/nsprpub/pr/tests/sockopt.c
@@ -38,18 +38,18 @@ int main(int argc, char **argv)
     PRFileDesc *udp = PR_NewUDPSocket();
     PRFileDesc *tcp = PR_NewTCPSocket();
     const char *tag[] =
     {
         "PR_SockOpt_Nonblocking",     /* nonblocking io */
         "PR_SockOpt_Linger",          /* linger on close if data present */
         "PR_SockOpt_Reuseaddr",       /* allow local address reuse */
         "PR_SockOpt_Keepalive",       /* keep connections alive */
-        "PR_SockOpt_RecvBufferSize",  /* send buffer size */
-        "PR_SockOpt_SendBufferSize",  /* receive buffer size */
+        "PR_SockOpt_RecvBufferSize",  /* receive buffer size */
+        "PR_SockOpt_SendBufferSize",  /* send buffer size */
 
         "PR_SockOpt_IpTimeToLive",    /* time to live */
         "PR_SockOpt_IpTypeOfService", /* type of service and precedence */
 
         "PR_SockOpt_AddMember",       /* add an IP group membership */
         "PR_SockOpt_DropMember",      /* drop an IP group membership */
         "PR_SockOpt_McastInterface",  /* multicast interface address */
         "PR_SockOpt_McastTimeToLive", /* multicast timetolive */
--- a/nsprpub/pr/tests/vercheck.c
+++ b/nsprpub/pr/tests/vercheck.c
@@ -34,34 +34,34 @@ static char *compatible_version[] = {
     "4.7", "4.7.1", "4.7.2", "4.7.3", "4.7.4", "4.7.5",
     "4.7.6",
     "4.8", "4.8.1", "4.8.2", "4.8.3", "4.8.4", "4.8.5",
     "4.8.6", "4.8.7", "4.8.8", "4.8.9",
     "4.9", "4.9.1", "4.9.2", "4.9.3", "4.9.4", "4.9.5",
     "4.9.6",
     "4.10", "4.10.1", "4.10.2", "4.10.3", "4.10.4",
     "4.10.5", "4.10.6", "4.10.7", "4.10.8", "4.10.9",
-    "4.10.10", "4.11",
+    "4.10.10", "4.11", "4.12",
     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.11.1",
-    "4.12.1",
+    "4.13.1",
+    "4.14", "4.14.1",
     "10.0", "11.1", "12.14.20"
 };
 
 int main(int argc, char **argv)
 {
     int idx;
     int num_compatible = sizeof(compatible_version) / sizeof(char *);
     int num_incompatible = sizeof(incompatible_version) / sizeof(char *);