From: Nicholas Clark Date: Tue, 2 May 2006 11:15:26 +0000 (+0000) Subject: De-duplicate the code that creates new GPs into Perl_newGP(). X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=128165928a7fa68e9b3adbdf3695141c97adb115;p=p5sagit%2Fp5-mst-13.2.git De-duplicate the code that creates new GPs into Perl_newGP(). p4raw-id: //depot/perl@28058 --- diff --git a/embed.fnc b/embed.fnc index 55f65fb..9e32b5e 100644 --- a/embed.fnc +++ b/embed.fnc @@ -282,6 +282,7 @@ Ap |GV* |gv_fetchpv |NN const char* name|I32 add|I32 sv_type Ap |void |gv_fullname |NN SV* sv|NN const GV* gv Apmb |void |gv_fullname3 |NN SV* sv|NN const GV* gv|NULLOK const char* prefix Ap |void |gv_fullname4 |NN SV* sv|NN const GV* gv|NULLOK const char* prefix|bool keepmain +pMox |GP * |newGP |NN GV *const gv Ap |void |gv_init |NN GV* gv|NULLOK HV* stash|NN const char* name|STRLEN len|int multi Ap |void |gv_name_set |NN GV* gv|NN const char *name|U32 len|U32 flags Apd |HV* |gv_stashpv |NN const char* name|I32 create diff --git a/embed.h b/embed.h index 8476916..7000eb0 100644 --- a/embed.h +++ b/embed.h @@ -2430,6 +2430,8 @@ #define gv_fetchpv(a,b,c) Perl_gv_fetchpv(aTHX_ a,b,c) #define gv_fullname(a,b) Perl_gv_fullname(aTHX_ a,b) #define gv_fullname4(a,b,c,d) Perl_gv_fullname4(aTHX_ a,b,c,d) +#ifdef PERL_CORE +#endif #define gv_init(a,b,c,d,e) Perl_gv_init(aTHX_ a,b,c,d,e) #define gv_name_set(a,b,c,d) Perl_gv_name_set(aTHX_ a,b,c,d) #define gv_stashpv(a,b) Perl_gv_stashpv(aTHX_ a,b) diff --git a/gv.c b/gv.c index 32a3aa6..b57060c 100644 --- a/gv.c +++ b/gv.c @@ -157,11 +157,30 @@ Perl_gv_const_sv(pTHX_ GV *gv) return SvROK(gv) ? SvRV(gv) : NULL; } +GP * +Perl_newGP(pTHX_ GV *const gv) +{ + GP *gp; + Newxz(gp, 1, GP); + +#ifndef PERL_DONT_CREATE_GVSV + gp->gv_sv = newSV(0); +#endif + + gp->gp_line = CopLINE(PL_curcop); + /* XXX Ideally this cast would be replaced with a change to const char* + in the struct. */ + gp->gp_file = CopFILE(PL_curcop) ? CopFILE(PL_curcop) : (char *) ""; + gp->gp_egv = gv; + gp->gp_refcnt = 1; + + return gp; +} + void Perl_gv_init(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len, int multi) { dVAR; - register GP *gp; const U32 old_type = SvTYPE(gv); const bool doproto = old_type > SVt_NULL; const char * const proto = (doproto && SvPOK(gv)) ? SvPVX_const(gv) : NULL; @@ -198,20 +217,9 @@ Perl_gv_init(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len, int multi) } else Safefree(SvPVX_mutable(gv)); } - Newxz(gp, 1, GP); SvSCREAM_on(gv); - GvGP(gv) = gp_ref(gp); -#ifdef PERL_DONT_CREATE_GVSV - GvSV(gv) = NULL; -#else - GvSV(gv) = newSV(0); -#endif - GvLINE(gv) = CopLINE(PL_curcop); - /* XXX Ideally this cast would be replaced with a change to const char* - in the struct. */ - GvFILE(gv) = CopFILE(PL_curcop) ? CopFILE(PL_curcop) : (char *) ""; - GvCVGEN(gv) = 0; - GvEGV(gv) = gv; + + GvGP(gv) = Perl_newGP(aTHX_ gv); GvSTASH(gv) = stash; if (stash) Perl_sv_add_backref(aTHX_ (SV*)stash, (SV*)gv); diff --git a/proto.h b/proto.h index bd5d285..ed3faea 100644 --- a/proto.h +++ b/proto.h @@ -645,6 +645,9 @@ PERL_CALLCONV void Perl_gv_fullname4(pTHX_ SV* sv, const GV* gv, const char* pre __attribute__nonnull__(pTHX_1) __attribute__nonnull__(pTHX_2); +PERL_CALLCONV GP * Perl_newGP(pTHX_ GV *const gv) + __attribute__nonnull__(pTHX_1); + PERL_CALLCONV void Perl_gv_init(pTHX_ GV* gv, HV* stash, const char* name, STRLEN len, int multi) __attribute__nonnull__(pTHX_1) __attribute__nonnull__(pTHX_3); diff --git a/scope.c b/scope.c index 8e40e8e..c0f3428 100644 --- a/scope.c +++ b/scope.c @@ -267,9 +267,7 @@ Perl_save_gp(pTHX_ GV *gv, I32 empty) SSPUSHINT(SAVEt_GP); if (empty) { - register GP *gp; - - Newxz(gp, 1, GP); + GP *gp = Perl_newGP(aTHX_ gv); if (GvCVu(gv)) PL_sub_generation++; /* taking a method out of circulation */ @@ -277,15 +275,7 @@ Perl_save_gp(pTHX_ GV *gv, I32 empty) gp->gp_io = newIO(); IoFLAGS(gp->gp_io) |= IOf_ARGV|IOf_START; } - GvGP(gv) = gp_ref(gp); -#ifndef PERL_DONT_CREATE_GVSV - GvSV(gv) = newSV(0); -#endif - GvLINE(gv) = CopLINE(PL_curcop); - /* XXX Ideally this cast would be replaced with a change to const char* - in the struct. */ - GvFILE(gv) = CopFILE(PL_curcop) ? CopFILE(PL_curcop) : (char *) ""; - GvEGV(gv) = gv; + GvGP(gv) = gp; } else { gp_ref(GvGP(gv));