summaryrefslogtreecommitdiff
path: root/malloc.c
diff options
context:
space:
mode:
authorDave Mitchell <davem@fdisolutions.com>2008-05-28 01:21:26 +0000
committerDave Mitchell <davem@fdisolutions.com>2008-05-28 01:21:26 +0000
commitc744a122a1c10b8cd7572c27f7b931414ca54920 (patch)
treefef147906f6d610d46e4b18858a0eb1cff951f8a /malloc.c
parent1846de3e2fab78cf13604ab27bf509695367229b (diff)
downloadperl-c744a122a1c10b8cd7572c27f7b931414ca54920.tar.gz
Integrate:
[ 33337] Setting the f flag on length causes the op to be constant folded. [ 33342] fix variable names in 'ununit var' warnings in evals [ 33363] Subject: [PATCH] B::Debug enhancements From: "Reini Urban" <rurban@x-ray.at> Date: Fri, 22 Feb 2008 09:52:32 +0100 Message-ID: <6910a60802220052t3c1f1d91ne38b8ba6f6c56651@mail.gmail.com> [ 33367] Avoid a segfault case in MRO code, based on : Subject: [perl #51092] [PATCH] Segfault when calling ->next::method on non-existing package From: ilmari@vesla.ilmari.org (via RT) <perlbug-followup@perl.org> Date: Thu, 21 Feb 2008 20:29:42 -0800 Message-ID: <rt-3.6.HEAD-15287-1203654581-377.51092-75-0@perl.org> [ 33369] Ensure that constant folding runs with IN_PERL_RUNTIME true, by copying the current compiling cop to a different address. This ensures that lexical hints are correctly honoured, and allows us to fold sprintf. [ 33377] If we have malloced_size() available, then avoid rounding up the string to the next (guessed) plausible alignment size, and instead find out how much memory was actually allocated, so that we can set this in the scalar's SvLEN(). This way, sv_grow() will be called far less often. [ 33378] In Perl_sv_usepvn_flags(), with MYMALLOC, use the actual malloc()ed size for SvLEN(), rather than an estimate. [ 33379] 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. [ 33380] Fix preprocessor syntax [ 33383] Comment on why I don't think changing Perl_safesysmalloc_size() in av.c analagous to the change in sv.c is a good idea. [It's not a language design issue, so sadly I can't get a talk out of it. Or is that fortunately? :-)] [ 33389] 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().) [ 33390] Use malloc_good_size() to round up the size of requested arenas to the size that will actually be allocated, to squeeze last few bytes into use. p4raw-link: @33390 on //depot/perl: d8fca4022b56f335fb492e336b5d155376eb1bf7 p4raw-link: @33389 on //depot/perl: 641071807211a3969bcad26ac3f2a39f4550a11c p4raw-link: @33383 on //depot/perl: e050cc0e6db974512bccc84746c68ba4ed3e4079 p4raw-link: @33380 on //depot/perl: cfe5289891381086cbb4d57f93a59ba02c2cd726 p4raw-link: @33379 on //depot/perl: ca7c1a2998b2bece800791e0ee5cce600e2f647a p4raw-link: @33378 on //depot/perl: 5d487c263b0c0c7fb6c50dee3540f1838c4ab067 p4raw-link: @33377 on //depot/perl: 98653f182f8d34d630c65229237c0d55f664e886 p4raw-link: @33369 on //depot/perl: c427f4d2d4575fbc8a5190932fe321136c7597b3 p4raw-link: @33367 on //depot/perl: 5fa9f95182cd3e9dfed1f750408ef8b876d6a9c6 p4raw-link: @33363 on //depot/perl: c13076132a20419dab956060b96f9d3ef3b25ad7 p4raw-link: @33342 on //depot/perl: 50edf520be9fa4c0e7982006bec3a6939b2f61a7 p4raw-link: @33337 on //depot/perl: 1518d620d80f21c46a5f3757b2ebf28b92c1d602 p4raw-id: //depot/maint-5.10/perl@33942 p4raw-integrated: from //depot/perl@33941 'copy in' t/lib/warnings/7fatal (@30124..) t/mro/next_edgecases.t (@30998..) ext/B/B/Debug.pm (@33230..) 'edit in' opcode.h (@33356..) 'merge in' makedef.pl (@32835..) handy.h (@33045..) p4raw-integrated: from //depot/perl@33390 'edit in' sv.c (@33385..) 'merge in' hv.c (@33291..) p4raw-integrated: from //depot/perl@33389 'merge in' malloc.c (@33291..) embed.h (@33365..) embed.fnc proto.h (@33384..) p4raw-integrated: from //depot/perl@33383 'edit in' av.c (@33379..) p4raw-integrated: from //depot/perl@33379 'edit in' perl.h (@33376..) p4raw-integrated: from //depot/perl@33369 'merge in' op.c (@33368..) p4raw-integrated: from //depot/perl@33367 'merge in' mro.c (@33291..) p4raw-integrated: from //depot/perl@33342 'merge in' t/lib/warnings/9uninit (@33310..) p4raw-integrated: from //depot/perl@33337 'edit in' opcode.pl (@33267..)
Diffstat (limited to 'malloc.c')
-rw-r--r--malloc.c50
1 files changed, 34 insertions, 16 deletions
diff --git a/malloc.c b/malloc.c
index 7c78913fbd..43f5d50da6 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,
@@ -2373,6 +2384,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