summaryrefslogtreecommitdiffstats
path: root/nsprpub/lib/ds
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2020-01-02 21:01:38 +0100
committerwolfbeast <mcwerewolf@wolfbeast.com>2020-01-02 21:01:38 +0100
commitf7d30133221896638f7bf4f66c504255c4b14f48 (patch)
tree5f3e07a049f388a3a309a615b8884318f6668a98 /nsprpub/lib/ds
parent26b297510a11758727438df4669357a2a2bc42ce (diff)
downloadUXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.gz
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.lz
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.tar.xz
UXP-f7d30133221896638f7bf4f66c504255c4b14f48.zip
Issue #1338 - Part 1: Update NSPR to 4.24
Diffstat (limited to 'nsprpub/lib/ds')
-rw-r--r--nsprpub/lib/ds/Makefile.in4
-rw-r--r--nsprpub/lib/ds/plarena.c64
-rw-r--r--nsprpub/lib/ds/plhash.c44
-rw-r--r--nsprpub/lib/ds/plvrsion.c8
4 files changed, 71 insertions, 49 deletions
diff --git a/nsprpub/lib/ds/Makefile.in b/nsprpub/lib/ds/Makefile.in
index e73779127..38a9e3dd1 100644
--- a/nsprpub/lib/ds/Makefile.in
+++ b/nsprpub/lib/ds/Makefile.in
@@ -43,10 +43,6 @@ OS_LIBS = -lc_r
endif
endif
-ifeq ($(OS_ARCH),IRIX)
-OS_LIBS = -lc
-endif
-
ifeq ($(OS_ARCH),SunOS)
OS_LIBS = -lc
MAPFILE = $(OBJDIR)/pldsmap.sun
diff --git a/nsprpub/lib/ds/plarena.c b/nsprpub/lib/ds/plarena.c
index a582ac638..3c6df2b7f 100644
--- a/nsprpub/lib/ds/plarena.c
+++ b/nsprpub/lib/ds/plarena.c
@@ -35,34 +35,40 @@ PR_IMPLEMENT(void) PL_InitArenaPool(
* align = 1 to 32.
*/
static const PRUint8 pmasks[33] = {
- 0, /* not used */
- 0, 1, 3, 3, 7, 7, 7, 7,15,15,15,15,15,15,15,15, /* 1 ... 16 */
- 31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31}; /* 17 ... 32 */
+ 0, /* not used */
+ 0, 1, 3, 3, 7, 7, 7, 7,15,15,15,15,15,15,15,15, /* 1 ... 16 */
+ 31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31 /* 17 ... 32 */
+ };
- if (align == 0)
+ if (align == 0) {
align = PL_ARENA_DEFAULT_ALIGN;
+ }
- if (align < sizeof(pmasks)/sizeof(pmasks[0]))
+ if (align < sizeof(pmasks)/sizeof(pmasks[0])) {
pool->mask = pmasks[align];
- else
+ }
+ else {
pool->mask = PR_BITMASK(PR_CeilingLog2(align));
+ }
pool->first.next = NULL;
/* Set all three addresses in pool->first to the same dummy value.
* These addresses are only compared with each other, but never
* dereferenced. */
pool->first.base = pool->first.avail = pool->first.limit =
- (PRUword)PL_ARENA_ALIGN(pool, &pool->first + 1);
+ (PRUword)PL_ARENA_ALIGN(pool, &pool->first + 1);
pool->current = &pool->first;
/*
* Compute the net size so that each arena's gross size is |size|.
* sizeof(PLArena) + pool->mask is the header and alignment slop
* that PL_ArenaAllocate adds to the net size.
*/
- if (size > sizeof(PLArena) + pool->mask)
+ if (size > sizeof(PLArena) + pool->mask) {
pool->arenasize = size - (sizeof(PLArena) + pool->mask);
- else
+ }
+ else {
pool->arenasize = size;
+ }
#ifdef PL_ARENAMETER
memset(&pool->stats, 0, sizeof pool->stats);
pool->stats.name = strdup(name);
@@ -74,15 +80,15 @@ PR_IMPLEMENT(void) PL_InitArenaPool(
/*
** PL_ArenaAllocate() -- allocate space from an arena pool
-**
+**
** Description: PL_ArenaAllocate() allocates space from an arena
-** pool.
+** pool.
**
** First, try to satisfy the request from arenas starting at
** 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.
@@ -93,16 +99,17 @@ PR_IMPLEMENT(void) PL_InitArenaPool(
PR_IMPLEMENT(void *) PL_ArenaAllocate(PLArenaPool *pool, PRUint32 nb)
{
- PLArena *a;
+ PLArena *a;
char *rp; /* returned pointer */
PRUint32 nbOld;
PR_ASSERT((nb & pool->mask) == 0);
-
+
nbOld = nb;
nb = (PRUword)PL_ARENA_ALIGN(pool, nb); /* force alignment */
- if (nb < nbOld)
+ if (nb < nbOld) {
return NULL;
+ }
/* attempt to allocate from arenas at pool->current */
{
@@ -117,8 +124,8 @@ PR_IMPLEMENT(void *) PL_ArenaAllocate(PLArenaPool *pool, PRUint32 nb)
} while( NULL != (a = a->next) );
}
- /* attempt to allocate from the heap */
- {
+ /* attempt to allocate from the heap */
+ {
PRUint32 sz = PR_MAX(pool->arenasize, nb);
if (PR_UINT32_MAX - sz < sizeof *a + pool->mask) {
a = NULL;
@@ -133,13 +140,14 @@ PR_IMPLEMENT(void *) PL_ArenaAllocate(PLArenaPool *pool, PRUint32 nb)
rp = (char *)a->avail;
a->avail += nb;
PR_ASSERT(a->avail <= a->limit);
- /* the newly allocated arena is linked after pool->current
+ /* 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 )
+ if ( NULL == pool->first.next ) {
pool->first.next = a;
+ }
PL_COUNT_ARENA(pool,++);
COUNT(pool, nmallocs);
return(rp);
@@ -155,11 +163,13 @@ PR_IMPLEMENT(void *) PL_ArenaGrow(
{
void *newp;
- if (PR_UINT32_MAX - size < incr)
+ if (PR_UINT32_MAX - size < incr) {
return NULL;
+ }
PL_ARENA_ALLOCATE(newp, pool, size + incr);
- if (newp)
+ if (newp) {
memcpy(newp, p, size);
+ }
return newp;
}
@@ -182,8 +192,9 @@ PR_IMPLEMENT(void) PL_ClearArenaPool(PLArenaPool *pool, PRInt32 pattern)
static void FreeArenaList(PLArenaPool *pool, PLArena *head)
{
PLArena *a = head->next;
- if (!a)
+ if (!a) {
return;
+ }
head->next = NULL;
@@ -224,8 +235,9 @@ PR_IMPLEMENT(void) PL_FinishArenaPool(PLArenaPool *pool)
{
PLArenaStats *stats, **statsp;
- if (pool->stats.name)
+ if (pool->stats.name) {
PR_DELETE(pool->stats.name);
+ }
for (statsp = &arena_stats_list; (stats = *statsp) != 0;
statsp = &stats->next) {
if (stats == &pool->stats) {
@@ -266,8 +278,9 @@ PR_IMPLEMENT(void) PL_ArenaCountAllocation(PLArenaPool *pool, PRUint32 nb)
{
pool->stats.nallocs++;
pool->stats.nbytes += nb;
- if (nb > pool->stats.maxalloc)
+ if (nb > pool->stats.maxalloc) {
pool->stats.maxalloc = nb;
+ }
pool->stats.variance += nb * nb;
}
@@ -284,8 +297,9 @@ PR_IMPLEMENT(void) PL_ArenaCountGrowth(
pool->stats.nbytes += incr;
pool->stats.variance -= size * size;
size += incr;
- if (size > pool->stats.maxalloc)
+ if (size > pool->stats.maxalloc) {
pool->stats.maxalloc = size;
+ }
pool->stats.variance += size * size;
}
diff --git a/nsprpub/lib/ds/plhash.c b/nsprpub/lib/ds/plhash.c
index 0011df336..95497f06f 100644
--- a/nsprpub/lib/ds/plhash.c
+++ b/nsprpub/lib/ds/plhash.c
@@ -51,8 +51,9 @@ DefaultAllocEntry(void *pool, const void *key)
static void PR_CALLBACK
DefaultFreeEntry(void *pool, PLHashEntry *he, PRUintn flag)
{
- if (flag == HT_FREE_ENTRY)
+ if (flag == HT_FREE_ENTRY) {
PR_Free(he);
+ }
}
static PLHashAllocOps defaultHashAllocOps = {
@@ -72,15 +73,19 @@ PL_NewHashTable(PRUint32 n, PLHashFunction keyHash,
n = MINBUCKETSLOG2;
} else {
n = PR_CeilingLog2(n);
- if ((PRInt32)n < 0)
+ if ((PRInt32)n < 0) {
return 0;
+ }
}
- if (!allocOps) allocOps = &defaultHashAllocOps;
+ if (!allocOps) {
+ allocOps = &defaultHashAllocOps;
+ }
ht = (PLHashTable*)((*allocOps->allocTable)(allocPriv, sizeof *ht));
- if (!ht)
- return 0;
+ if (!ht) {
+ return 0;
+ }
memset(ht, 0, sizeof *ht);
ht->shift = PL_HASH_BITS - n;
n = 1 << n;
@@ -202,7 +207,7 @@ PL_HashTableRawAdd(PLHashTable *ht, PLHashEntry **hep,
oldbuckets = ht->buckets;
nb = 2 * n * sizeof(PLHashEntry *);
ht->buckets = (PLHashEntry**)
- ((*ht->allocOps->allocTable)(ht->allocPriv, nb));
+ ((*ht->allocOps->allocTable)(ht->allocPriv, nb));
if (!ht->buckets) {
ht->buckets = oldbuckets;
return 0;
@@ -231,8 +236,9 @@ PL_HashTableRawAdd(PLHashTable *ht, PLHashEntry **hep,
/* Make a new key value entry */
he = (*ht->allocOps->allocEntry)(ht->allocPriv, key);
- if (!he)
- return 0;
+ if (!he) {
+ return 0;
+ }
he->keyHash = keyHash;
he->key = key;
he->value = value;
@@ -256,8 +262,9 @@ PL_HashTableAdd(PLHashTable *ht, const void *key, void *value)
/* key,value pair is already present in table */
return he;
}
- if (he->value)
+ if (he->value) {
(*ht->allocOps->freeEntry)(ht->allocPriv, he, HT_FREE_VALUE);
+ }
he->value = value;
return he;
}
@@ -280,7 +287,7 @@ PL_HashTableRawRemove(PLHashTable *ht, PLHashEntry **hep, PLHashEntry *he)
oldbuckets = ht->buckets;
nb = n * sizeof(PLHashEntry*) / 2;
ht->buckets = (PLHashEntry**)(
- (*ht->allocOps->allocTable)(ht->allocPriv, nb));
+ (*ht->allocOps->allocTable)(ht->allocPriv, nb));
if (!ht->buckets) {
ht->buckets = oldbuckets;
return;
@@ -315,8 +322,9 @@ PL_HashTableRemove(PLHashTable *ht, const void *key)
keyHash = (*ht->keyHash)(key);
hep = PL_HashTableRawLookup(ht, keyHash, key);
- if ((he = *hep) == 0)
+ if ((he = *hep) == 0) {
return PR_FALSE;
+ }
/* Hit; remove element */
PL_HashTableRawRemove(ht, hep, he);
@@ -414,11 +422,13 @@ PL_HashTableDumpMeter(PLHashTable *ht, PLHashEnumerator dump, FILE *fp)
nbuckets = NBUCKETS(ht);
for (i = 0; i < nbuckets; i++) {
he = ht->buckets[i];
- if (!he)
+ if (!he) {
continue;
+ }
nchains++;
- for (n = 0; he; he = he->next)
+ for (n = 0; he; he = he->next) {
n++;
+ }
variance += n * n;
if (n > maxChainLen) {
maxChainLen = n;
@@ -434,15 +444,16 @@ PL_HashTableDumpMeter(PLHashTable *ht, PLHashEnumerator dump, FILE *fp)
fprintf(fp, " number of grows: %u\n", ht->ngrows);
fprintf(fp, " number of shrinks: %u\n", ht->nshrinks);
fprintf(fp, " mean steps per hash: %g\n", (double)ht->nsteps
- / ht->nlookups);
+ / ht->nlookups);
fprintf(fp, "mean hash chain length: %g\n", mean);
fprintf(fp, " standard deviation: %g\n", sqrt(variance));
fprintf(fp, " max hash chain length: %u\n", maxChainLen);
fprintf(fp, " max hash chain: [%u]\n", maxChain);
for (he = ht->buckets[maxChain], i = 0; he; he = he->next, i++)
- if ((*dump)(he, i, fp) != HT_ENUMERATE_NEXT)
+ if ((*dump)(he, i, fp) != HT_ENUMERATE_NEXT) {
break;
+ }
}
#endif /* HASHMETER */
@@ -465,8 +476,9 @@ PL_HashString(const void *key)
const PRUint8 *s;
h = 0;
- for (s = (const PRUint8*)key; *s; s++)
+ for (s = (const PRUint8*)key; *s; s++) {
h = PR_ROTATE_LEFT32(h, 4) ^ *s;
+ }
return h;
}
diff --git a/nsprpub/lib/ds/plvrsion.c b/nsprpub/lib/ds/plvrsion.c
index 8b351b4db..14c1d676e 100644
--- a/nsprpub/lib/ds/plvrsion.c
+++ b/nsprpub/lib/ds/plvrsion.c
@@ -54,7 +54,7 @@ PRVersionDescription VERSION_DESC_NAME =
/* filename */ _PRODUCTION, /* the produced library name */
/* description */ "Portable runtime", /* what we are */
/* security */ "N/A", /* not applicable here */
- /* copywrite */ "Copyright (c) 1998 Netscape Communications Corporation. All Rights Reserved",
+ /* copywrite */ "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/.",
/* comment */ "http://www.mozilla.org/MPL/",
/* specialString */ ""
};
@@ -68,9 +68,9 @@ PRVersionDescription VERSION_DESC_NAME =
* must not end in a '$' to prevent rcs keyword substitution.
*/
static char rcsid[] = "$Header: NSPR " PR_VERSION _DEBUG_STRING
- " " _BUILD_STRING " $";
+ " " _BUILD_STRING " $";
static char sccsid[] = "@(#)NSPR " PR_VERSION _DEBUG_STRING
- " " _BUILD_STRING;
+ " " _BUILD_STRING;
#endif /* XP_UNIX */
@@ -86,7 +86,7 @@ PR_IMPLEMENT(const PRVersionDescription*) libVersionPoint()
* from being optimized away as unused variables.
*/
const char *dummy;
-
+
dummy = rcsid;
dummy = sccsid;
#endif