From: Ilya Zakharevich Date: Sun, 15 Jun 1997 23:17:08 +0000 (+1200) Subject: : reduced malloc patch X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=38a1ac3f7341206073b47f38b6bdb094f3f50352;p=p5sagit%2Fp5-mst-13.2.git : reduced malloc patch Since this problems arise again and again on the list, here is the reduced malloc patch. It corrects the following problems: a) several off-by-one in av_make(); b) Growing TMP on conversion number=>string; c) Uncompatibility of -DDEBUGGING_MSTATS and system malloc; (The first two problems are fixed by malloc_jumbo_2 as well, but the 2 chunks for "c" - in perl.c - were forgotten in that patch). Enjoy, p5p-msgid: 199707150829.EAA01291@monk.mps.ohio-state.edu --- diff --git a/av.c b/av.c index 9e94805..6b4c03d 100644 --- a/av.c +++ b/av.c @@ -253,17 +253,19 @@ register SV **strp; av = (AV*)NEWSV(8,0); sv_upgrade((SV *) av,SVt_PVAV); - New(4,ary,size+1,SV*); - AvALLOC(av) = ary; AvFLAGS(av) = AVf_REAL; - SvPVX(av) = (char*)ary; - AvFILL(av) = size - 1; - AvMAX(av) = size - 1; - for (i = 0; i < size; i++) { - assert (*strp); - ary[i] = NEWSV(7,0); - sv_setsv(ary[i], *strp); - strp++; + if (size) { /* `defined' was returning undef for size==0 anyway. */ + New(4,ary,size,SV*); + AvALLOC(av) = ary; + SvPVX(av) = (char*)ary; + AvFILL(av) = size - 1; + AvMAX(av) = size - 1; + for (i = 0; i < size; i++) { + assert (*strp); + ary[i] = NEWSV(7,0); + sv_setsv(ary[i], *strp); + strp++; + } } return av; } diff --git a/malloc.c b/malloc.c index e9b200b..df72105 100644 --- a/malloc.c +++ b/malloc.c @@ -2,6 +2,10 @@ * */ +#if defined(PERL_CORE) && !defined(DEBUGGING_MSTATS) +# define DEBUGGING_MSTATS +#endif + #ifndef lint # if defined(DEBUGGING) && !defined(NO_RCHECK) # define RCHECK diff --git a/perl.c b/perl.c index 8ef13a3..93e7aa1 100644 --- a/perl.c +++ b/perl.c @@ -815,7 +815,7 @@ print \" \\@INC:\\n @INC\\n\";"); LEAVE; FREETMPS; -#ifdef DEBUGGING_MSTATS +#ifdef MYMALLOC if ((s=getenv("PERL_DEBUG_MSTATS")) && atoi(s) >= 2) dump_mstats("after compilation:"); #endif @@ -852,7 +852,7 @@ PerlInterpreter *sv_interp; if (endav) call_list(oldscope, endav); FREETMPS; -#ifdef DEBUGGING_MSTATS +#ifdef MYMALLOC if (getenv("PERL_DEBUG_MSTATS")) dump_mstats("after execution: "); #endif diff --git a/sv.c b/sv.c index 53499fd..f53315a 100644 --- a/sv.c +++ b/sv.c @@ -4625,7 +4625,7 @@ sv_vcatpvfn(sv, pat, patlen, args, svargs, svmax, used_locale) need = (have > width ? have : width); gap = need - have; - SvGROW(sv, SvLEN(sv) + need); + SvGROW(sv, SvCUR(sv) + need + 1); p = SvEND(sv); if (esignlen && fill == '0') { for (i = 0; i < esignlen; i++)