develooper Front page | perl.perl5.changes | Postings from February 2008

Change 33379: If the C library provides malloc_size(), we can use that in the same

From:
Nicholas Clark
Date:
February 26, 2008 15:30
Subject:
Change 33379: If the C library provides malloc_size(), we can use that in the same
Message ID:
20080226233009.8A6355011A@mx.activestate.com
Change 33379 by nicholas@mouse-mill on 2008/02/26 23:22:30

	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.

Affected files ...

... //depot/perl/av.c#129 edit
... //depot/perl/handy.h#139 edit
... //depot/perl/perl.h#831 edit
... //depot/perl/sv.c#1512 edit

Differences ...

==== //depot/perl/av.c#129 (text) ====
Index: perl/av.c
--- perl/av.c#128~33291~	2008-02-12 05:15:20.000000000 -0800
+++ perl/av.c	2008-02-26 15:22:30.000000000 -0800
@@ -117,8 +117,9 @@
 		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 @@
 		    Safefree(AvALLOC(av));
 		AvALLOC(av) = ary;
 #endif
-#ifdef MYMALLOC
+#ifdef Perl_safesysmalloc_size
 	      resized:
 #endif
 		ary = AvALLOC(av) + AvMAX(av) + 1;

==== //depot/perl/handy.h#139 (text) ====
Index: perl/handy.h
--- perl/handy.h#138~33045~	2008-01-22 23:51:53.000000000 -0800
+++ perl/handy.h	2008-02-26 15:22:30.000000000 -0800
@@ -177,7 +177,7 @@
 #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
 

==== //depot/perl/perl.h#831 (text) ====
Index: perl/perl.h
--- perl/perl.h#830~33376~	2008-02-26 05:13:18.000000000 -0800
+++ perl/perl.h	2008-02-26 15:22:30.000000000 -0800
@@ -4071,6 +4071,12 @@
 #  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);

==== //depot/perl/sv.c#1512 (text) ====
Index: perl/sv.c
--- perl/sv.c#1511~33378~	2008-02-26 11:55:33.000000000 -0800
+++ perl/sv.c	2008-02-26 15:22:30.000000000 -0800
@@ -1492,11 +1492,11 @@
 	    }
 	}
 	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 @@
 
     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 @@
 	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
End of Patch.



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About