X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=malloc.c;h=4f7289fa67d14a1dd07ea204b5ef8c866c965e7d;hb=918426be7f3660c63cebe082bf8eac82a38bf756;hp=fc37cb237dce2d7f3f40763ac69db08438333856;hpb=b022d2d27f9b150bfa61c150f89ab4147aeb4595;p=p5sagit%2Fp5-mst-13.2.git diff --git a/malloc.c b/malloc.c index fc37cb2..4f7289f 100644 --- a/malloc.c +++ b/malloc.c @@ -291,7 +291,7 @@ # ifndef warn # define warn(mess, arg) fprintf(stderr, (mess), (arg)) # endif -# ifndef warn +# ifndef warn2 # define warn2(mess, arg1) fprintf(stderr, (mess), (arg1), (arg2)) # endif # ifdef DEBUG_m @@ -458,6 +458,11 @@ union overhead { double strut; /* alignment problems */ #endif struct { +/* + * Keep the ovu_index and ovu_magic in this order, having a char + * field first gives alignment indigestion in some systems, such as + * MachTen. + */ u_char ovu_index; /* bucket # */ u_char ovu_magic; /* magic number */ #ifdef RCHECK @@ -855,11 +860,7 @@ static void* get_from_bigger_buckets(int bucket, MEM_SIZE size); static union overhead *getpages (MEM_SIZE needed, int *nblksp, int bucket); static int getpages_adjacent(MEM_SIZE require); -#if defined(PERL_EMERGENCY_SBRK) && defined(PERL_CORE) - -# ifndef BIG_SIZE -# define BIG_SIZE (1<<16) /* 64K */ -# endif +#ifdef PERL_CORE #ifdef I_MACH_CTHREADS # undef MUTEX_LOCK @@ -885,16 +886,12 @@ static union overhead *nextf[NBUCKETS]; #endif #ifdef USE_PERL_SBRK -#define sbrk(a) Perl_sbrk(a) +# define sbrk(a) Perl_sbrk(a) Malloc_t Perl_sbrk (int size); -#else -#ifdef DONT_DECLARE_STD -#ifdef I_UNISTD -#include -#endif #else +# ifndef HAS_SBRK_PROTO /* usually takes care of this */ extern Malloc_t sbrk(int); -#endif +# endif #endif #ifdef DEBUGGING_MSTATS @@ -911,6 +908,12 @@ static u_int start_slack; static u_int goodsbrk; +# ifdef PERL_EMERGENCY_SBRK + +# ifndef BIG_SIZE +# define BIG_SIZE (1<<16) /* 64K */ +# endif + static char *emergency_buffer; static MEM_SIZE emergency_buffer_size; static int no_mem; /* 0 if the last request for more memory succeeded. @@ -978,9 +981,10 @@ emergency_sbrk(MEM_SIZE size) return Nullch; } -#else /* !(defined(PERL_EMERGENCY_SBRK) && defined(PERL_CORE)) */ +# else /* !defined(PERL_EMERGENCY_SBRK) */ # define emergency_sbrk(size) -1 -#endif /* !(defined(PERL_EMERGENCY_SBRK) && defined(PERL_CORE)) */ +# endif +#endif /* ifdef PERL_CORE */ #ifdef DEBUGGING #undef ASSERT @@ -1057,6 +1061,9 @@ Perl_malloc(register size_t nbytes) { dTHX; if (!PL_nomemok) { +#if defined(PLAIN_MALLOC) && defined(NO_FANCY_MALLOC) + PerlIO_puts(PerlIO_stderr(),"Out of memory!\n"); +#else char buff[80]; char *eb = buff + sizeof(buff) - 1; char *s = eb; @@ -1079,6 +1086,7 @@ Perl_malloc(register size_t nbytes) } while (n /= 10); PerlIO_puts(PerlIO_stderr(),s); PerlIO_puts(PerlIO_stderr()," bytes!\n"); +#endif /* defined(PLAIN_MALLOC) && defined(NO_FANCY_MALLOC) */ my_exit(1); } } @@ -1088,7 +1096,7 @@ Perl_malloc(register size_t nbytes) DEBUG_m(PerlIO_printf(Perl_debug_log, "0x%"UVxf": (%05lu) malloc %ld bytes\n", - PTR2UV(p+1), (unsigned long)(PL_an++), + PTR2UV(p), (unsigned long)(PL_an++), (long)size)); /* remove from linked list */ @@ -1386,7 +1394,9 @@ getpages(MEM_SIZE needed, int *nblksp, int bucket) sbrked_remains = require - needed; last_op = cp; } +#if !defined(PLAIN_MALLOC) && !defined(NO_FANCY_MALLOC) no_mem = 0; +#endif last_sbrk_top = cp + require; #ifdef DEBUGGING_MSTATS goodsbrk += require;