summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embed.fnc1
-rw-r--r--embed.h2
-rw-r--r--makedef.pl1
-rw-r--r--malloc.c50
-rw-r--r--proto.h3
5 files changed, 41 insertions, 16 deletions
diff --git a/embed.fnc b/embed.fnc
index 79944b422b..b48af1e8ba 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -87,6 +87,7 @@ Aanop |Malloc_t|realloc |Malloc_t where|MEM_SIZE nbytes
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
diff --git a/embed.h b/embed.h
index 3b6cb78847..f8fce70315 100644
--- a/embed.h
+++ b/embed.h
@@ -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
diff --git a/makedef.pl b/makedef.pl
index dad466ad42..a559061a5f 100644
--- a/makedef.pl
+++ b/makedef.pl
@@ -667,6 +667,7 @@ else {
Perl_dump_mstats
Perl_get_mstats
Perl_malloced_size
+ Perl_malloc_good_size
MallocCfg_ptr
MallocCfgP_ptr
)];
diff --git a/malloc.c b/malloc.c
index 46a80a4ecd..682eeb6278 100644
--- a/malloc.c
+++ b/malloc.c
@@ -1404,23 +1404,12 @@ cmp_pat_4bytes(unsigned char *s, size_t nbytes, const unsigned char *fill)
# 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 @@ Perl_malloc(register size_t nbytes)
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 @@ Perl_malloced_size(void *p)
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
diff --git a/proto.h b/proto.h
index 7ba57ff129..f764d5ccae 100644
--- a/proto.h
+++ b/proto.h
@@ -106,6 +106,9 @@ PERL_CALLCONV MEM_SIZE Perl_malloced_size(void *p)
#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)