X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=malloc.c;h=6f8f548f1efd60e88783847696688829d04b9d01;hb=f1c0db8dbc906cad6c85874be33c7969497df1cd;hp=4794e08447f17bfd9ac7eac548d51f3c235ee234;hpb=d58bf5aa3d3631a46847733b1ff1985b30140228;p=p5sagit%2Fp5-mst-13.2.git diff --git a/malloc.c b/malloc.c index 4794e08..6f8f548 100644 --- a/malloc.c +++ b/malloc.c @@ -178,7 +178,7 @@ static u_short blk_shift[11 - 3] = {256, 128, 64, 32, static char *emergency_buffer; static MEM_SIZE emergency_buffer_size; -static char * +static Malloc_t emergency_sbrk(size) MEM_SIZE size; { @@ -189,6 +189,7 @@ emergency_sbrk(size) } if (!emergency_buffer) { + dTHR; /* First offense, give a possibility to recover by dieing. */ /* No malloc involved here: */ GV **gvp = (GV**)hv_fetch(defstash, "^M", 2, 0); @@ -236,9 +237,15 @@ static union overhead *nextf[NBUCKETS]; #ifdef USE_PERL_SBRK #define sbrk(a) Perl_sbrk(a) -char * Perl_sbrk _((int size)); +Malloc_t Perl_sbrk _((int size)); +#else +#ifdef DONT_DECLARE_STD +#ifdef I_UNISTD +#include +#endif #else -extern char *sbrk(); +extern Malloc_t sbrk(int); +#endif #endif #ifdef DEBUGGING_MSTATS @@ -255,19 +262,17 @@ static u_int start_slack; #ifdef DEBUGGING #define ASSERT(p) if (!(p)) botch(STRINGIFY(p)); else static void -botch(s) - char *s; +botch(char *s) { PerlIO_printf(PerlIO_stderr(), "assertion botched: %s\n", s); - abort(); + PerlProc_abort(); } #else #define ASSERT(p) #endif Malloc_t -malloc(nbytes) - register MEM_SIZE nbytes; +malloc(register size_t nbytes) { register union overhead *p; register int bucket = 0; @@ -368,8 +373,7 @@ malloc(nbytes) * Allocate more memory to the indicated bucket. */ static void -morecore(bucket) - register int bucket; +morecore(register int bucket) { register union overhead *ovp; register int rnu; /* 2^rnu bytes will be requested */ @@ -481,8 +485,7 @@ morecore(bucket) } Free_t -free(mp) - Malloc_t mp; +free(void *mp) { register MEM_SIZE size; register union overhead *ovp; @@ -505,7 +508,7 @@ free(mp) if (OV_MAGIC(ovp, bucket) != MAGIC) { static int bad_free_warn = -1; if (bad_free_warn == -1) { - char *pbf = getenv("PERL_BADFREE"); + char *pbf = PerlEnv_getenv("PERL_BADFREE"); bad_free_warn = (pbf) ? atoi(pbf) : 1; } if (!bad_free_warn) @@ -546,9 +549,7 @@ free(mp) int reall_srchlen = 4; /* 4 should be plenty, -1 =>'s whole list */ Malloc_t -realloc(mp, nbytes) - Malloc_t mp; - MEM_SIZE nbytes; +realloc(void *mp, size_t nbytes) { register MEM_SIZE onb; union overhead *ovp; @@ -672,9 +673,7 @@ realloc(mp, nbytes) * Return bucket number, or -1 if not found. */ static int -findbucket(freep, srchlen) - union overhead *freep; - int srchlen; +findbucket(union overhead *freep, int srchlen) { register union overhead *p; register int i, j; @@ -691,9 +690,7 @@ findbucket(freep, srchlen) } Malloc_t -calloc(elements, size) - register MEM_SIZE elements; - register MEM_SIZE size; +calloc(register size_t elements, register size_t size) { long sz = elements * size; Malloc_t p = malloc(sz); @@ -713,8 +710,7 @@ calloc(elements, size) * frees for each size category. */ void -dump_mstats(s) - char *s; +dump_mstats(char *s) { register int i, j; register union overhead *p; @@ -746,8 +742,7 @@ dump_mstats(s) } #else void -dump_mstats(s) - char *s; +dump_mstats(char *s) { } #endif @@ -782,7 +777,7 @@ static long Perl_sbrk_oldsize; # define PERLSBRK_32_K (1<<15) # define PERLSBRK_64_K (1<<16) -char * +Malloc_t Perl_sbrk(size) int size; {