From: Nicholas Clark Date: Tue, 26 Feb 2008 23:22:30 +0000 (+0000) Subject: If the C library provides malloc_size(), we can use that in the same X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ca7c1a2998b2bece800791e0ee5cce600e2f647a;p=p5sagit%2Fp5-mst-13.2.git If the C library provides malloc_size(), we can use that in the same places as Perl's malloced_size(), except that we need to be careful of any PERL_TRACK_MEMPOOL manipulations in force. Wrap both as Perl_safesysmalloc_size(), to give a consistent name and interface. p4raw-id: //depot/perl@33379 --- diff --git a/av.c b/av.c index cf95d61..4b3b08d 100644 --- a/av.c +++ b/av.c @@ -117,8 +117,9 @@ Perl_av_extend(pTHX_ AV *av, I32 key) IV itmp; #endif -#ifdef MYMALLOC - newmax = malloced_size((void*)AvALLOC(av))/sizeof(SV*) - 1; +#ifdef Perl_safesysmalloc_size + newmax = Perl_safesysmalloc_size((void*)AvALLOC(av)) / + sizeof(SV*) - 1; if (key <= newmax) goto resized; @@ -147,7 +148,7 @@ Perl_av_extend(pTHX_ AV *av, I32 key) Safefree(AvALLOC(av)); AvALLOC(av) = ary; #endif -#ifdef MYMALLOC +#ifdef Perl_safesysmalloc_size resized: #endif ary = AvALLOC(av) + AvMAX(av) + 1; diff --git a/handy.h b/handy.h index 433fe13..008141e 100644 --- a/handy.h +++ b/handy.h @@ -177,7 +177,7 @@ typedef U64TYPE U64; #endif /* HMB H.Merijn Brand - a placeholder for preparing Configure patches */ -#if defined(HAS_MALLOC_SIZE) && defined(LOCALTIME_R_NEEDS_TZSET) && defined(HAS_PSEUDOFORK) && defined(USE_DTRACE) +#if defined(LOCALTIME_R_NEEDS_TZSET) && defined(HAS_PSEUDOFORK) && defined(USE_DTRACE) /* Not (yet) used at top level, but mention them for metaconfig */ #endif diff --git a/perl.h b/perl.h index 7ad3176..aec1e26 100644 --- a/perl.h +++ b/perl.h @@ -4071,6 +4071,12 @@ struct perl_memory_debug_header { # define INIT_TRACK_MEMPOOL(header, interp) #endif +#ifdef MYMALLOC +# define Perl_safesysmalloc_size(where) Perl_malloced_size(where) +#else if defined(HAS_MALLOC_SIZE) +# define Perl_safesysmalloc_size(where) \ + (malloc_size(((char *)(where)) - sTHX) - sTHX) +#endif typedef int (CPERLscope(*runops_proc_t)) (pTHX); typedef void (CPERLscope(*share_proc_t)) (pTHX_ SV *sv); diff --git a/sv.c b/sv.c index 79fa25e..bde31e1 100644 --- a/sv.c +++ b/sv.c @@ -1492,11 +1492,11 @@ Perl_sv_grow(pTHX_ register SV *const sv, register STRLEN newlen) } } SvPV_set(sv, s); -#ifdef MYMALLOC +#ifdef Perl_safesysmalloc_size /* Do this here, do it once, do it right, and then we will never get called back into sv_grow() unless there really is some growing needed. */ - SvLEN_set(sv, malloced_size(s)); + SvLEN_set(sv, Perl_safesysmalloc_size(s)); #else SvLEN_set(sv, newlen); #endif @@ -4176,7 +4176,7 @@ Perl_sv_usepvn_flags(pTHX_ SV *sv, char *ptr, STRLEN len, U32 flags) allocate = (flags & SV_HAS_TRAILING_NUL) ? len + 1 : -#ifdef MYMALLOC +#ifdef Perl_safesysmalloc_size len + 1; #else PERL_STRLEN_ROUNDUP(len + 1); @@ -4196,8 +4196,8 @@ Perl_sv_usepvn_flags(pTHX_ SV *sv, char *ptr, STRLEN len, U32 flags) ptr = (char*) saferealloc (ptr, allocate); #endif } -#ifdef MYMALLOC - SvLEN_set(sv, malloced_size(ptr)); +#ifdef Perl_safesysmalloc_size + SvLEN_set(sv, Perl_safesysmalloc_size(ptr)); #else SvLEN_set(sv, allocate); #endif