In perl.git, the branch smoke-me/nicholas/abolish-STRANGE_MALLOC has been 
updated

<http://perl5.git.perl.org/perl.git/commitdiff/b9cf7e8932843f09df57a0cbaeececc637d8f34c?hp=c5e13bf5ce9484aa5cbdcc8102718ee15d41c091>

- Log -----------------------------------------------------------------
commit b9cf7e8932843f09df57a0cbaeececc637d8f34c
Author: Nicholas Clark <[email protected]>
Date:   Wed Feb 20 21:38:33 2013 +0100

    Abolish STRANGE_MALLOC. Now all malloc()s are considered strange :-)
    
    STRANGE_MALLOC was added in 5.002 beta 1 (4633a7c4bad06b47) as part of an
    work around for typical mallocs, which had a bad interaction with perl's
    allocation needs. Specifically, repeatedly extending an array and then
    creating SV heads (such as when reading lines of a file into an array)
    could end up with each reallocation for the array being unable to extend in
    place, needing a fresh chunk of memory, and the released memory not being
    suitable for use as more SV heads, so sitting unused. The solution was for
    perl to recycle the old array body as SV heads, instead of returning it to
    the system, passing the memory from the the AV code to the SV code using
    offer_nice_chunk(), PL_nice_chunk and PL_nice_chunk_size.
    
    STRANGE_MALLOC was actually a signal that the malloc() didn't need
    protecting from itself, and to disable the work around.
    
    offer_nice_chunk(), PL_nice_chunk and PL_nice_chunk_size were removed by
    commit 9a87bd09eea1d037 in Nov 2010, without any ill effects, hence the
    code used when STRANGE_MALLOC was *not* defined is essentially doing extra
    work for no benefits.
    
    From the lack of problems reported, one can assume that in the intervening
    15 years malloc technology has got significantly improved, and it is 
probably
    better to be honest with it, rather than trying to second guess it.
    
    Hence remove all the non-STRANGE_MALLOC code, and leave everyone using the
    much simpler code. See also
    http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2005-11/msg00495.html
    http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2013-01/msg00126.html
-----------------------------------------------------------------------

Summary of changes:
 av.c |   21 ---------------------
 hv.c |   28 ----------------------------
 2 files changed, 0 insertions(+), 49 deletions(-)

diff --git a/av.c b/av.c
index 3041cd2..44b5fbc 100644
--- a/av.c
+++ b/av.c
@@ -119,10 +119,6 @@ Perl_av_extend_guts(pTHX_ AV *av, I32 key, SSize_t *maxp, 
SV ***allocp,
 #endif
 
            if (*allocp) {
-#if !defined(STRANGE_MALLOC) && !defined(MYMALLOC)
-               MEM_SIZE bytes;
-               IV itmp;
-#endif
 
 #ifdef Perl_safesysmalloc_size
                /* Whilst it would be quite possible to move this logic around
@@ -147,24 +143,7 @@ Perl_av_extend_guts(pTHX_ AV *av, I32 key, SSize_t *maxp, 
SV ***allocp,
                newmax = key + *maxp / 5;
              resize:
                MEM_WRAP_CHECK_1(newmax+1, SV*, oom_array_extend);
-#if defined(STRANGE_MALLOC) || defined(MYMALLOC)
                Renew(*allocp,newmax+1, SV*);
-#else
-               bytes = (newmax + 1) * sizeof(const SV *);
-#define MALLOC_OVERHEAD 16
-               itmp = MALLOC_OVERHEAD;
-               while ((MEM_SIZE)(itmp - MALLOC_OVERHEAD) < bytes)
-                   itmp += itmp;
-               itmp -= MALLOC_OVERHEAD;
-               itmp /= sizeof(const SV *);
-               assert(itmp > newmax);
-               newmax = itmp - 1;
-               assert(newmax >= *maxp);
-               Newx(ary, newmax+1, SV*);
-               Copy(*allocp, ary, *maxp+1, SV*);
-               Safefree(*allocp);
-               *allocp = ary;
-#endif
 #ifdef Perl_safesysmalloc_size
              resized:
 #endif
diff --git a/hv.c b/hv.c
index 5f7ae85..0879fe4 100644
--- a/hv.c
+++ b/hv.c
@@ -1109,7 +1109,6 @@ S_hsplit(pTHX_ HV *hv)
     }
               
     PL_nomemok = TRUE;
-#if defined(STRANGE_MALLOC) || defined(MYMALLOC)
     Renew(a, PERL_HV_ARRAY_ALLOC_BYTES(newsize)
          + (SvOOK(hv) ? sizeof(struct xpvhv_aux) : 0), char);
     if (!a) {
@@ -1119,19 +1118,6 @@ S_hsplit(pTHX_ HV *hv)
     if (SvOOK(hv)) {
        Move(&a[oldsize * sizeof(HE*)], &a[newsize * sizeof(HE*)], 1, struct 
xpvhv_aux);
     }
-#else
-    Newx(a, PERL_HV_ARRAY_ALLOC_BYTES(newsize)
-       + (SvOOK(hv) ? sizeof(struct xpvhv_aux) : 0), char);
-    if (!a) {
-      PL_nomemok = FALSE;
-      return;
-    }
-    Copy(HvARRAY(hv), a, oldsize * sizeof(HE*), char);
-    if (SvOOK(hv)) {
-       Copy(HvAUX(hv), &a[newsize * sizeof(HE*)], 1, struct xpvhv_aux);
-    }
-    Safefree(HvARRAY(hv));
-#endif
 
     PL_nomemok = FALSE;
     Zero(&a[oldsize * sizeof(HE*)], (newsize-oldsize) * sizeof(HE*), char);    
/* zero 2nd half*/
@@ -1191,7 +1177,6 @@ Perl_hv_ksplit(pTHX_ HV *hv, IV newmax)
     a = (char *) HvARRAY(hv);
     if (a) {
        PL_nomemok = TRUE;
-#if defined(STRANGE_MALLOC) || defined(MYMALLOC)
        Renew(a, PERL_HV_ARRAY_ALLOC_BYTES(newsize)
              + (SvOOK(hv) ? sizeof(struct xpvhv_aux) : 0), char);
        if (!a) {
@@ -1201,19 +1186,6 @@ Perl_hv_ksplit(pTHX_ HV *hv, IV newmax)
        if (SvOOK(hv)) {
            Copy(&a[oldsize * sizeof(HE*)], &a[newsize * sizeof(HE*)], 1, 
struct xpvhv_aux);
        }
-#else
-       Newx(a, PERL_HV_ARRAY_ALLOC_BYTES(newsize)
-           + (SvOOK(hv) ? sizeof(struct xpvhv_aux) : 0), char);
-       if (!a) {
-         PL_nomemok = FALSE;
-         return;
-       }
-       Copy(HvARRAY(hv), a, oldsize * sizeof(HE*), char);
-       if (SvOOK(hv)) {
-           Copy(HvAUX(hv), &a[newsize * sizeof(HE*)], 1, struct xpvhv_aux);
-       }
-       Safefree(HvARRAY(hv));
-#endif
        PL_nomemok = FALSE;
        Zero(&a[oldsize * sizeof(HE*)], (newsize-oldsize) * sizeof(HE*), char); 
/* zero 2nd half*/
     }

--
Perl5 Master Repository

Reply via email to