From: Nicholas Clark Date: Fri, 23 Dec 2005 15:27:10 +0000 (+0000) Subject: Create a struct to use as the header with PERL_TRACK_MEMPOOL, so that X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=731dcb42dfb65caf9942d70e5db009f245ecbefe;p=p5sagit%2Fp5-mst-13.2.git Create a struct to use as the header with PERL_TRACK_MEMPOOL, so that other information can be stored in it. p4raw-id: //depot/perl@26474 --- diff --git a/perl.h b/perl.h index 4d8e719..b314184 100644 --- a/perl.h +++ b/perl.h @@ -138,6 +138,8 @@ #define pVAR register struct perl_vars* my_vars PERL_UNUSED_DECL +typedef struct interpreter PerlInterpreter; + #ifdef PERL_GLOBAL_STRUCT # define dVAR pVAR = (struct perl_vars*)PERL_GET_VARS() #else @@ -149,7 +151,14 @@ # define MULTIPLICITY # endif # define tTHX PerlInterpreter* -# define sTHX (sizeof(tTHX) + (MEM_ALIGNBYTES - sizeof(tTHX)%MEM_ALIGNBYTES) % MEM_ALIGNBYTES) + +struct perl_memory_debug_header { + tTHX interpreter; +}; + +# define sTHX (sizeof(struct perl_memory_debug_header) + \ + (MEM_ALIGNBYTES - sizeof(struct perl_memory_debug_header) \ + %MEM_ALIGNBYTES) % MEM_ALIGNBYTES) # define pTHX register tTHX my_perl PERL_UNUSED_DECL # define aTHX my_perl # ifdef PERL_GLOBAL_STRUCT @@ -2155,8 +2164,6 @@ typedef struct padop PADOP; typedef struct pvop PVOP; typedef struct loop LOOP; -typedef struct interpreter PerlInterpreter; - /* Amdahl's has struct sv */ /* SGI's has struct sv */ #if defined(UTS) || defined(__sgi) diff --git a/util.c b/util.c index 5e5ba78..34bf4bb 100644 --- a/util.c +++ b/util.c @@ -93,7 +93,7 @@ Perl_safesysmalloc(MEM_SIZE size) DEBUG_m(PerlIO_printf(Perl_debug_log, "0x%"UVxf": (%05ld) malloc %ld bytes\n",PTR2UV(ptr),(long)PL_an++,(long)size)); if (ptr != Nullch) { #ifdef PERL_TRACK_MEMPOOL - *(tTHX*)ptr = aTHX; + ((struct perl_memory_debug_header *)ptr)->interpreter = aTHX; ptr = (Malloc_t)((char*)ptr+sTHX); #endif return ptr; @@ -134,7 +134,7 @@ Perl_safesysrealloc(Malloc_t where,MEM_SIZE size) #ifdef PERL_TRACK_MEMPOOL where = (Malloc_t)((char*)where-sTHX); size += sTHX; - if (*(tTHX*)where != aTHX) { + if (((struct perl_memory_debug_header *)where)->interpreter != aTHX) { /* int *nowhere = NULL; *nowhere = 0; */ Perl_croak_nocontext("panic: realloc from wrong pool"); } @@ -176,7 +176,7 @@ Perl_safesysfree(Malloc_t where) if (where) { #ifdef PERL_TRACK_MEMPOOL where = (Malloc_t)((char*)where-sTHX); - if (*(tTHX*)where != aTHX) { + if (((struct perl_memory_debug_header *)where)->interpreter != aTHX) { /* int *nowhere = NULL; *nowhere = 0; */ Perl_croak_nocontext("panic: free from wrong pool"); } @@ -214,7 +214,7 @@ Perl_safesyscalloc(MEM_SIZE count, MEM_SIZE size) if (ptr != Nullch) { memset((void*)ptr, 0, size); #ifdef PERL_TRACK_MEMPOOL - *(tTHX*)ptr = aTHX; + ((struct perl_memory_debug_header *)ptr)->interpreter = aTHX; ptr = (Malloc_t)((char*)ptr+sTHX); #endif return ptr;