X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=malloc.c;h=00c387ed6c6a95f760fd49430a29ebbb886f3eda;hb=345d73cfd9677ddcbcfc43412ba14d8c2d2004dd;hp=f73e22dfd433cd0b632f57edc89d4f652f364d4c;hpb=516a5887ee93ac51c15492c01bb2e52bafd5bfaf;p=p5sagit%2Fp5-mst-13.2.git diff --git a/malloc.c b/malloc.c index f73e22d..00c387e 100644 --- a/malloc.c +++ b/malloc.c @@ -3,6 +3,10 @@ */ /* + * "'The Chamber of Records,' said Gimli. 'I guess that is where we now stand.'" + */ + +/* Here are some notes on configuring Perl's malloc. (For non-perl usage see below.) @@ -255,7 +259,6 @@ # include # include # include -# define _(arg) arg # ifndef Malloc_t # define Malloc_t void * # endif @@ -305,7 +308,7 @@ # define pTHX void # define pTHX_ # ifdef HASATTRIBUTE -# define dTHX extern int Perl___notused __attribute__ ((unused)) +# define dTHX extern int Perl___notused PERL_UNUSED_DECL # else # define dTHX extern int Perl___notused # endif @@ -353,9 +356,16 @@ #ifdef DEBUGGING # undef DEBUG_m -# define DEBUG_m(a) \ +# define DEBUG_m(a) \ STMT_START { \ - if (PERL_GET_INTERP) { dTHX; if (DEBUG_m_TEST) { a; } } \ + if (PERL_GET_INTERP) { \ + dTHX; \ + if (DEBUG_m_TEST) { \ + PL_debug &= ~DEBUG_m_FLAG; \ + a; \ + PL_debug |= DEBUG_m_FLAG; \ + } \ + } \ } STMT_END #endif @@ -920,7 +930,7 @@ static u_int goodsbrk; static char *emergency_buffer; static MEM_SIZE emergency_buffer_size; -static int no_mem; /* 0 if the last request for more memory succeeded. +static MEM_SIZE no_mem; /* 0 if the last request for more memory succeeded. Otherwise the size of the failing request. */ static Malloc_t @@ -1100,11 +1110,6 @@ Perl_malloc(register size_t nbytes) return (NULL); } - DEBUG_m(PerlIO_printf(Perl_debug_log, - "0x%"UVxf": (%05lu) malloc %ld bytes\n", - PTR2UV(p), (unsigned long)(PL_an++), - (long)size)); - /* remove from linked list */ #if defined(RCHECK) if ((PTR2UV(p)) & (MEM_ALIGNBYTES - 1)) { @@ -1125,6 +1130,11 @@ Perl_malloc(register size_t nbytes) MALLOC_UNLOCK; + DEBUG_m(PerlIO_printf(Perl_debug_log, + "0x%"UVxf": (%05lu) malloc %ld bytes\n", + PTR2UV(p), (unsigned long)(PL_an++), + (long)size)); + #ifdef IGNORE_SMALL_BAD_FREE if (bucket >= FIRST_BUCKET_WITH_CHECK) #endif @@ -1157,7 +1167,7 @@ Perl_malloc(register size_t nbytes) static char *last_sbrk_top; static char *last_op; /* This arena can be easily extended. */ -static int sbrked_remains; +static MEM_SIZE sbrked_remains; static int sbrk_good = SBRK_ALLOW_FAILURES * SBRK_FAILURE_PRICE; #ifdef DEBUGGING_MSTATS @@ -1592,12 +1602,12 @@ Perl_mfree(void *mp) { dTHX; if (!PERL_IS_ALIVE || !PL_curcop || ckWARN_d(WARN_MALLOC)) - Perl_warner(aTHX_ WARN_MALLOC, "%s free() ignored", + Perl_warner(aTHX_ packWARN(WARN_MALLOC), "%s free() ignored (RMAGIC, PERL_CORE)", ovp->ov_rmagic == RMAGIC - 1 ? "Duplicate" : "Bad"); } #else - warn("%s free() ignored", + warn("%s free() ignored (RMAGIC)", ovp->ov_rmagic == RMAGIC - 1 ? "Duplicate" : "Bad"); #endif #else @@ -1605,7 +1615,7 @@ Perl_mfree(void *mp) { dTHX; if (!PERL_IS_ALIVE || !PL_curcop || ckWARN_d(WARN_MALLOC)) - Perl_warner(aTHX_ WARN_MALLOC, "%s", "Bad free() ignored"); + Perl_warner(aTHX_ packWARN(WARN_MALLOC), "%s", "Bad free() ignored (PERL_CORE)"); } #else warn("%s", "Bad free() ignored"); @@ -1692,7 +1702,7 @@ Perl_realloc(void *mp, size_t nbytes) { dTHX; if (!PERL_IS_ALIVE || !PL_curcop || ckWARN_d(WARN_MALLOC)) - Perl_warner(aTHX_ WARN_MALLOC, "%srealloc() %signored", + Perl_warner(aTHX_ packWARN(WARN_MALLOC), "%srealloc() %signored", (ovp->ov_rmagic == RMAGIC - 1 ? "" : "Bad "), ovp->ov_rmagic == RMAGIC - 1 ? "of freed memory " : ""); @@ -1707,7 +1717,7 @@ Perl_realloc(void *mp, size_t nbytes) { dTHX; if (!PERL_IS_ALIVE || !PL_curcop || ckWARN_d(WARN_MALLOC)) - Perl_warner(aTHX_ WARN_MALLOC, "%s", + Perl_warner(aTHX_ packWARN(WARN_MALLOC), "%s", "Bad realloc() ignored"); } #else