Change 33389 by [EMAIL PROTECTED] on 2008/02/27 19:10:02

        Add Perl_malloc_good_size to malloc.c. (A routine that rounds up the 
        passed in request to the size that will actually be allocated. It's
        the same interface as Darwin already provides with malloc_good_size().)

Affected files ...

... //depot/perl/embed.fnc#591 edit
... //depot/perl/embed.h#753 edit
... //depot/perl/makedef.pl#231 edit
... //depot/perl/malloc.c#128 edit
... //depot/perl/proto.h#926 edit

Differences ...

==== //depot/perl/embed.fnc#591 (text) ====
Index: perl/embed.fnc
--- perl/embed.fnc#590~33384~   2008-02-27 04:29:36.000000000 -0800
+++ perl/embed.fnc      2008-02-27 11:10:02.000000000 -0800
@@ -87,6 +87,7 @@
 Anop   |Free_t |mfree          |Malloc_t where
 #if defined(MYMALLOC)
 npR    |MEM_SIZE|malloced_size |NN void *p
+npR    |MEM_SIZE|malloc_good_size      |size_t nbytes
 #endif
 
 AnpR   |void*  |get_context

==== //depot/perl/embed.h#753 (text+w) ====
Index: perl/embed.h
--- perl/embed.h#752~33365~     2008-02-25 00:04:14.000000000 -0800
+++ perl/embed.h        2008-02-27 11:10:02.000000000 -0800
@@ -38,6 +38,7 @@
 #if defined(MYMALLOC)
 #ifdef PERL_CORE
 #define malloced_size          Perl_malloced_size
+#define malloc_good_size       Perl_malloc_good_size
 #endif
 #endif
 #define get_context            Perl_get_context
@@ -2349,6 +2350,7 @@
 #if defined(MYMALLOC)
 #ifdef PERL_CORE
 #define malloced_size          Perl_malloced_size
+#define malloc_good_size       Perl_malloc_good_size
 #endif
 #endif
 #define get_context            Perl_get_context

==== //depot/perl/makedef.pl#231 (text) ====
Index: perl/makedef.pl
--- perl/makedef.pl#230~32835~  2008-01-04 14:20:48.000000000 -0800
+++ perl/makedef.pl     2008-02-27 11:10:02.000000000 -0800
@@ -667,6 +667,7 @@
                    Perl_dump_mstats
                    Perl_get_mstats
                    Perl_malloced_size
+                   Perl_malloc_good_size
                    MallocCfg_ptr
                    MallocCfgP_ptr
                    )];

==== //depot/perl/malloc.c#128 (text) ====
Index: perl/malloc.c
--- perl/malloc.c#127~33291~    2008-02-12 05:15:20.000000000 -0800
+++ perl/malloc.c       2008-02-27 11:10:02.000000000 -0800
@@ -1404,23 +1404,12 @@
 #  define FILLCHECK_DEADBEEF(s, n)     ((void)0)
 #endif
 
-Malloc_t
-Perl_malloc(register size_t nbytes)
+int
+S_ajust_size_and_find_bucket(size_t *nbytes_p)
 {
-        dVAR;
-       register union overhead *p;
-       register int bucket;
-       register MEM_SIZE shiftr;
-
-#if defined(DEBUGGING) || defined(RCHECK)
-       MEM_SIZE size = nbytes;
-#endif
-
-       BARK_64K_LIMIT("Allocation",nbytes,nbytes);
-#ifdef DEBUGGING
-       if ((long)nbytes < 0)
-           croak("%s", "panic: malloc");
-#endif
+       MEM_SIZE shiftr;
+       int bucket;
+       size_t nbytes = *nbytes_p;
 
        /*
         * Convert amount of memory requested into
@@ -1455,6 +1444,28 @@
            while (shiftr >>= 1)
                bucket += BUCKETS_PER_POW2;
        }
+       *nbytes_p = nbytes;
+       return bucket;
+}
+
+Malloc_t
+Perl_malloc(size_t nbytes)
+{
+        dVAR;
+       register union overhead *p;
+       register int bucket;
+
+#if defined(DEBUGGING) || defined(RCHECK)
+       MEM_SIZE size = nbytes;
+#endif
+
+       BARK_64K_LIMIT("Allocation",nbytes,nbytes);
+#ifdef DEBUGGING
+       if ((long)nbytes < 0)
+           croak("%s", "panic: malloc");
+#endif
+
+       bucket = S_ajust_size_and_find_bucket(&nbytes);
        MALLOC_LOCK;
        /*
         * If nothing in hash bucket right now,
@@ -2376,6 +2387,13 @@
     return BUCKET_SIZE_REAL(bucket);
 }
 
+
+MEM_SIZE
+Perl_malloc_good_size(size_t wanted)
+{
+    return BUCKET_SIZE_REAL(S_ajust_size_and_find_bucket(&wanted));
+}
+
 #  ifdef BUCKETS_ROOT2
 #    define MIN_EVEN_REPORT 6
 #  else

==== //depot/perl/proto.h#926 (text+w) ====
Index: perl/proto.h
--- perl/proto.h#925~33384~     2008-02-27 04:29:36.000000000 -0800
+++ perl/proto.h        2008-02-27 11:10:02.000000000 -0800
@@ -106,6 +106,9 @@
 #define PERL_ARGS_ASSERT_MALLOCED_SIZE \
        assert(p)
 
+PERL_CALLCONV MEM_SIZE Perl_malloc_good_size(size_t nbytes)
+                       __attribute__warn_unused_result__;
+
 #endif
 
 PERL_CALLCONV void*    Perl_get_context(void)
End of Patch.

Reply via email to