diff --git a/nsprpub/lib/ds/plarena.c b/nsprpub/lib/ds/plarena.c index c41d6b0a..80ff263a 100644 --- a/nsprpub/lib/ds/plarena.c +++ b/nsprpub/lib/ds/plarena.c @@ -260,6 +260,21 @@ PR_IMPLEMENT(void *) PL_ArenaGrow( return newp; } +static void ClearArenaList(PLArena *a, PRInt32 pattern) +{ + + for (; a; a = a->next) { + PR_ASSERT(a->base <= a->avail && a->avail <= a->limit); + a->avail = a->base; + PL_CLEAR_UNUSED_PATTERN(a, pattern); + } +} + +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. @@ -274,12 +289,7 @@ static void FreeArenaList(PLArenaPool *pool, PLArena *head, PRBool reallyFree) return; #ifdef DEBUG - do { - PR_ASSERT(a->base <= a->avail && a->avail <= a->limit); - a->avail = a->base; - PL_CLEAR_UNUSED(a); - } while ((a = a->next) != 0); - a = *ap; + ClearArenaList(a, PL_FREE_PATTERN); #endif if (reallyFree) { diff --git a/nsprpub/lib/ds/plarena.h b/nsprpub/lib/ds/plarena.h index 38f3e399..d6094046 100644 --- a/nsprpub/lib/ds/plarena.h +++ b/nsprpub/lib/ds/plarena.h @@ -138,11 +138,12 @@ struct PLArenaPool { #define PL_ARENA_MARK(pool) ((void *) (pool)->current->avail) #define PR_UPTRDIFF(p,q) ((PRUword)(p) - (PRUword)(q)) +#define PL_CLEAR_UNUSED_PATTERN(a, pattern) \ + (PR_ASSERT((a)->avail <= (a)->limit), \ + memset((void*)(a)->avail, (pattern), (a)->limit - (a)->avail)) #ifdef DEBUG #define PL_FREE_PATTERN 0xDA -#define PL_CLEAR_UNUSED(a) (PR_ASSERT((a)->avail <= (a)->limit), \ - memset((void*)(a)->avail, PL_FREE_PATTERN, \ - (a)->limit - (a)->avail)) +#define PL_CLEAR_UNUSED(a) PL_CLEAR_UNUSED_PATTERN((a), PL_FREE_PATTERN) #define PL_CLEAR_ARENA(a) memset((void*)(a), PL_FREE_PATTERN, \ (a)->limit - (PRUword)(a)) #else diff --git a/nsprpub/lib/ds/plarenas.h b/nsprpub/lib/ds/plarenas.h index e3eca358..778d3af5 100644 --- a/nsprpub/lib/ds/plarenas.h +++ b/nsprpub/lib/ds/plarenas.h @@ -108,6 +108,11 @@ PR_EXTERN(void *) PL_ArenaGrow( 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); + PR_END_EXTERN_C #endif /* defined(PLARENAS_H) */ diff --git a/nsprpub/lib/ds/plds.def b/nsprpub/lib/ds/plds.def index d72796a4..a80e2bca 100644 --- a/nsprpub/lib/ds/plds.def +++ b/nsprpub/lib/ds/plds.def @@ -81,3 +81,8 @@ libVersionPoint; PL_HashTableLookupConst; PL_HashTableRawLookupConst; ;+} NSPR_4.0; +;+ +;+NSPR_4.8.5 { +;+ global: +PL_ClearArenaPool; +;+} NSPR_4.1; diff --git a/nsprpub/pr/include/prtypes.h b/nsprpub/pr/include/prtypes.h index 67ee6082..948f59c6 100644 --- a/nsprpub/pr/include/prtypes.h +++ b/nsprpub/pr/include/prtypes.h @@ -277,6 +277,13 @@ #define PR_MAX(x,y) ((x)>(y)?(x):(y)) #define PR_ABS(x) ((x)<0?-(x):(x)) +/*********************************************************************** +** MACROS: PR_ARRAY_SIZE +** DESCRIPTION: +** The number of elements in an array. +***********************************************************************/ +#define PR_ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) + PR_BEGIN_EXTERN_C /************************************************************************ diff --git a/nsprpub/pr/tests/sprintf.c b/nsprpub/pr/tests/sprintf.c index 7fe2ac19..659bcfec 100644 --- a/nsprpub/pr/tests/sprintf.c +++ b/nsprpub/pr/tests/sprintf.c @@ -56,8 +56,6 @@ #include #include -#define countof(a) (sizeof(a)/sizeof(a[0])) - static char sbuf[20000]; @@ -121,15 +119,15 @@ static void TestI(void) int f, s, n, p; char fmt[20]; - for (f = 0; f < countof(formats); f++) { - for (s = 0; s < countof(signs); s++) { - for (p = 0; p < countof(precs); p++) { + for (f = 0; f < PR_ARRAY_SIZE(formats); f++) { + for (s = 0; s < PR_ARRAY_SIZE(signs); s++) { + for (p = 0; p < PR_ARRAY_SIZE(precs); p++) { fmt[0] = '%'; fmt[1] = 0; if (signs[s]) strcat(fmt, signs[s]); if (precs[p]) strcat(fmt, precs[p]); if (formats[f]) strcat(fmt, formats[f]); - for (n = 0; n < countof(nums); n++) { + for (n = 0; n < PR_ARRAY_SIZE(nums); n++) { test_i(fmt, nums[n]); } } @@ -213,9 +211,9 @@ static void TestL(void) int f, s, n, p; char fmt[40], sfmt[40]; - for (f = 0; f < countof(formats); f++) { - for (s = 0; s < countof(signs); s++) { - for (p = 0; p < countof(precs); p++) { + for (f = 0; f < PR_ARRAY_SIZE(formats); f++) { + for (s = 0; s < PR_ARRAY_SIZE(signs); s++) { + for (p = 0; p < PR_ARRAY_SIZE(precs); p++) { fmt[0] = '%'; fmt[1] = 0; if (signs[s]) strcat(fmt, signs[s]); @@ -223,7 +221,7 @@ static void TestL(void) strcpy(sfmt, fmt); if (formats[f]) strcat(fmt, formats[f]); if (sformats[f]) strcat(sfmt, sformats[f]); - for (n = 0; n < countof(nums); n++) { + for (n = 0; n < PR_ARRAY_SIZE(nums); n++) { test_l(fmt, sfmt, nums[n]); } } @@ -336,9 +334,9 @@ static void TestLL(void) int f, s, n, p; char fmt[40], sfmt[40]; - for (f = 0; f < countof(formats); f++) { - for (s = 0; s < countof(signs); s++) { - for (p = 0; p < countof(precs); p++) { + for (f = 0; f < PR_ARRAY_SIZE(formats); f++) { + for (s = 0; s < PR_ARRAY_SIZE(signs); s++) { + for (p = 0; p < PR_ARRAY_SIZE(precs); p++) { fmt[0] = '%'; fmt[1] = 0; if (signs[s]) strcat(fmt, signs[s]); @@ -346,7 +344,7 @@ static void TestLL(void) strcpy(sfmt, fmt); if (formats[f]) strcat(fmt, formats[f]); if (sformats[f]) strcat(sfmt, sformats[f]); - for (n = 0; n < countof(nums); n++) { + for (n = 0; n < PR_ARRAY_SIZE(nums); n++) { test_ll(fmt, sfmt, nums[n]); } } @@ -424,15 +422,15 @@ static void TestS(void) int f, s, n, p; char fmt[40]; - for (f = 0; f < countof(formats); f++) { - for (s = 0; s < countof(signs); s++) { - for (p = 0; p < countof(precs); p++) { + for (f = 0; f < PR_ARRAY_SIZE(formats); f++) { + for (s = 0; s < PR_ARRAY_SIZE(signs); s++) { + for (p = 0; p < PR_ARRAY_SIZE(precs); p++) { fmt[0] = '%'; fmt[1] = 0; if (signs[s]) strcat(fmt+strlen(fmt), signs[s]); if (precs[p]) strcat(fmt+strlen(fmt), precs[p]); if (formats[f]) strcat(fmt+strlen(fmt), formats[f]); - for (n = 0; n < countof(strs); n++) { + for (n = 0; n < PR_ARRAY_SIZE(strs); n++) { test_s(fmt, strs[n]); } }