From: Gisle Aas Date: Sat, 4 Jul 1998 10:20:35 +0000 (+0200) Subject: applied suggested fix for xhv_array sizing, with portability tweaks X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=dcb4812c733545a68ef39b77c2dc4f7d440de203;p=p5sagit%2Fp5-mst-13.2.git applied suggested fix for xhv_array sizing, with portability tweaks Subject: Re: [PATCH] Re: perl5.004_69 core dump Message-ID: p4raw-id: //depot/perl@1313 --- diff --git a/hv.c b/hv.c index 4f5642f..784aadf 100644 --- a/hv.c +++ b/hv.c @@ -21,6 +21,13 @@ static void hfreeentries _((HV *hv)); static HE* more_he _((void)); #endif +#if defined(STRANGE_MALLOC) || defined(MYMALLOC) +# define ARRAY_ALLOC_BYTES(size) ( (size)*sizeof(HE*) ) +#else +# define MALLOC_OVERHEAD 16 +# define ARRAY_ALLOC_BYTES(size) ( (size)*sizeof(HE*)*2 - MALLOC_OVERHEAD ) +#endif + STATIC HE* new_he(void) { @@ -121,7 +128,7 @@ hv_fetch(HV *hv, char *key, U32 klen, I32 lval) || (HvNAME(hv) && strEQ(HvNAME(hv),ENV_HV_NAME)) #endif ) - Newz(503,xhv->xhv_array, sizeof(HE*) * (xhv->xhv_max + 1), char); + Newz(503,xhv->xhv_array, ARRAY_ALLOC_BYTES(xhv->xhv_max + 1), char); else return 0; } @@ -209,7 +216,7 @@ hv_fetch_ent(HV *hv, SV *keysv, I32 lval, register U32 hash) || (HvNAME(hv) && strEQ(HvNAME(hv),ENV_HV_NAME)) #endif ) - Newz(503,xhv->xhv_array, sizeof(HE*) * (xhv->xhv_max + 1), char); + Newz(503,xhv->xhv_array, ARRAY_ALLOC_BYTES(xhv->xhv_max + 1), char); else return 0; } @@ -299,7 +306,7 @@ hv_store(HV *hv, char *key, U32 klen, SV *val, register U32 hash) PERL_HASH(hash, key, klen); if (!xhv->xhv_array) - Newz(505, xhv->xhv_array, sizeof(HE*) * (xhv->xhv_max + 1), char); + Newz(505, xhv->xhv_array, ARRAY_ALLOC_BYTES(xhv->xhv_max + 1), char); oentry = &((HE**)xhv->xhv_array)[hash & (I32) xhv->xhv_max]; i = 1; @@ -380,7 +387,7 @@ hv_store_ent(HV *hv, SV *keysv, SV *val, register U32 hash) PERL_HASH(hash, key, klen); if (!xhv->xhv_array) - Newz(505, xhv->xhv_array, sizeof(HE*) * (xhv->xhv_max + 1), char); + Newz(505, xhv->xhv_array, ARRAY_ALLOC_BYTES(xhv->xhv_max + 1), char); oentry = &((HE**)xhv->xhv_array)[hash & (I32) xhv->xhv_max]; i = 1; @@ -673,22 +680,21 @@ hsplit(HV *hv) nomemok = TRUE; #if defined(STRANGE_MALLOC) || defined(MYMALLOC) - Renew(a, newsize * sizeof(HE*), char); + Renew(a, ARRAY_ALLOC_BYTES(newsize), char); if (!a) { nomemok = FALSE; return; } #else #define MALLOC_OVERHEAD 16 - New(2, a, newsize*sizeof(HE*) * 2 - MALLOC_OVERHEAD, char); + New(2, a, ARRAY_ALLOC_BYTES(newsize), char); if (!a) { nomemok = FALSE; return; } Copy(xhv->xhv_array, a, oldsize * sizeof(HE*), char); if (oldsize >= 64) { - offer_nice_chunk(xhv->xhv_array, - oldsize * sizeof(HE*) * 2 - MALLOC_OVERHEAD); + offer_nice_chunk(xhv->xhv_array, ARRAY_ALLOC_BYTES(oldsize)); } else Safefree(xhv->xhv_array); @@ -749,21 +755,20 @@ hv_ksplit(HV *hv, IV newmax) if (a) { nomemok = TRUE; #if defined(STRANGE_MALLOC) || defined(MYMALLOC) - Renew(a, newsize * sizeof(HE*), char); + Renew(a, ARRAY_ALLOC_BYTES(newsize), char); if (!a) { nomemok = FALSE; return; } #else - New(2, a, newsize * sizeof(HE*) * 2 - MALLOC_OVERHEAD, char); + New(2, a, ARRAY_ALLOC_BYTES(newsize), char); if (!a) { nomemok = FALSE; return; } Copy(xhv->xhv_array, a, oldsize * sizeof(HE*), char); if (oldsize >= 64) { - offer_nice_chunk(xhv->xhv_array, - oldsize * sizeof(HE*) * 2 - MALLOC_OVERHEAD); + offer_nice_chunk(xhv->xhv_array, ARRAY_ALLOC_BYTES(oldsize)); } else Safefree(xhv->xhv_array); @@ -772,11 +777,7 @@ hv_ksplit(HV *hv, IV newmax) Zero(&a[oldsize * sizeof(HE*)], (newsize-oldsize) * sizeof(HE*), char); /* zero 2nd half*/ } else { -#if defined(STRANGE_MALLOC) || defined(MYMALLOC) - Newz(0, a, newsize * sizeof(HE*), char); -#else - Newz(0, a, newsize * sizeof(HE*) * 2 - MALLOC_OVERHEAD, char); -#endif + Newz(0, a, ARRAY_ALLOC_BYTES(newsize), char); } xhv->xhv_max = --newsize; xhv->xhv_array = a; @@ -1045,7 +1046,7 @@ hv_iternext(HV *hv) } if (!xhv->xhv_array) - Newz(506,xhv->xhv_array, sizeof(HE*) * (xhv->xhv_max + 1), char); + Newz(506,xhv->xhv_array, ARRAY_ALLOC_BYTES(xhv->xhv_max + 1), char); if (entry) entry = HeNEXT(entry); while (!entry) {