From 6a3d5e3dbfbb290a39e3787450653a41f07f3b5d Mon Sep 17 00:00:00 2001 From: Jarkko Hietaniemi Date: Sun, 17 Dec 2006 17:17:34 -0500 Subject: [PATCH] Re: [PATCH] do not meddle in the affairs of PERL_TRACK_MEMPOOL Message-ID: <4586084E.8040706@iki.fi> Introduce CopLABEL() macro to deal with labels attached to COPs. p4raw-id: //depot/perl@29585 --- cop.h | 11 +++++++++++ op.c | 16 ++-------------- scope.h | 4 ++++ 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/cop.h b/cop.h index d75d2f1..722e135 100644 --- a/cop.h +++ b/cop.h @@ -186,12 +186,20 @@ struct cop { ? gv_stashpv(CopSTASHPV(c),GV_ADD) : NULL) # define CopSTASH_set(c,hv) CopSTASHPV_set(c, (hv) ? HvNAME_get(hv) : NULL) # define CopSTASH_eq(c,hv) ((hv) && stashpv_hvname_match(c,hv)) +# define CopLABEL(c) ((c)->cop_label) +# ifdef NETWARE +# define CopLABEL_set(c,pv) ((CopLABEL(c) = ((pv) ? savepv(pv) : NULL)), Safefree(pv), ((pv) = NULL)) +# else +# define CopLABEL_set(c,pv) ((CopLABEL(c) = savesharedpv(pv)), Safefree(pv), ((pv) = NULL)) +# endif # ifdef NETWARE # define CopSTASH_free(c) SAVECOPSTASH_FREE(c) # define CopFILE_free(c) SAVECOPFILE_FREE(c) +# define CopLABEL_free(c) SAVECOPLABEL_FREE(c) # else # define CopSTASH_free(c) PerlMemShared_free(CopSTASHPV(c)) # define CopFILE_free(c) (PerlMemShared_free(CopFILE(c)),(CopFILE(c) = NULL)) +# define CopLABEL_free(c) (PerlMemShared_free(CopLABEL(c)),(CopLABEL(c) = NULL)) # endif #else # define CopFILEGV(c) ((c)->cop_filegv) @@ -206,13 +214,16 @@ struct cop { # endif # define CopFILE(c) (CopFILESV(c) ? SvPVX(CopFILESV(c)) : NULL) # define CopSTASH(c) ((c)->cop_stash) +# define CopLABEL(c) ((c)->cop_label) # define CopSTASH_set(c,hv) ((c)->cop_stash = (hv)) # define CopSTASHPV(c) (CopSTASH(c) ? HvNAME_get(CopSTASH(c)) : NULL) /* cop_stash is not refcounted */ # define CopSTASHPV_set(c,pv) CopSTASH_set((c), gv_stashpv(pv,GV_ADD)) # define CopSTASH_eq(c,hv) (CopSTASH(c) == (hv)) +# define CopLABEL_set(c,pv) (CopLABEL(c) = (pv)) # define CopSTASH_free(c) # define CopFILE_free(c) (SvREFCNT_dec(CopFILEGV(c)),(CopFILEGV(c) = NULL)) +# define CopLABEL_free(c) #endif /* USE_ITHREADS */ diff --git a/op.c b/op.c index 2ed2198..2c10b2b 100644 --- a/op.c +++ b/op.c @@ -514,19 +514,7 @@ clear_pmop: STATIC void S_cop_free(pTHX_ COP* cop) { - if (cop->cop_label) { -#ifdef PERL_TRACK_MEMPOOL - Malloc_t ptr = (Malloc_t)(cop->cop_label - sTHX); - struct perl_memory_debug_header *const header - = (struct perl_memory_debug_header *)ptr; - /* Only the thread that allocated us can free us. */ - if (header->interpreter == aTHX) -#endif - { - Safefree(cop->cop_label); - cop->cop_label = NULL; - } - } + CopLABEL_free(cop); CopFILE_free(cop); CopSTASH_free(cop); if (! specialWARN(cop->cop_warnings)) @@ -4004,7 +3992,7 @@ Perl_newSTATEOP(pTHX_ I32 flags, char *label, OP *o) cop->op_next = (OP*)cop; if (label) { - cop->cop_label = label; + CopLABEL_set(cop, label); PL_hints |= HINT_BLOCK_SCOPE; } cop->cop_seq = seq; diff --git a/scope.h b/scope.h index 377a8b4..c804300 100644 --- a/scope.h +++ b/scope.h @@ -219,11 +219,15 @@ Closing bracket on a callback. See C and L. # define SAVECOPSTASH_FREE(c) SAVESHAREDPV(CopSTASHPV(c)) # define SAVECOPFILE(c) SAVEPPTR(CopFILE(c)) # define SAVECOPFILE_FREE(c) SAVESHAREDPV(CopFILE(c)) +# define SAVECOPLABEL(c) SAVEPPTR(CopLABEL(c)) +# define SAVECOPLABEL_FREE(c) SAVESHAREDPV(CopLABEL(c)) #else # define SAVECOPSTASH(c) SAVESPTR(CopSTASH(c)) # define SAVECOPSTASH_FREE(c) SAVECOPSTASH(c) /* XXX not refcounted */ # define SAVECOPFILE(c) SAVESPTR(CopFILEGV(c)) # define SAVECOPFILE_FREE(c) SAVEGENERICSV(CopFILEGV(c)) +# define SAVECOPLABEL(c) SAVEPPTR(CopLABEL(c)) +# define SAVECOPLABEL_FREE(c) SAVEPPTR(CopLABEL(c)) #endif #define SAVECOPLINE(c) SAVEI32(CopLINE(c)) -- 2.7.4