From: Nicholas Clark Date: Sat, 8 Aug 2009 11:05:40 +0000 (+0100) Subject: Merge gv_AVadd(), gv_HVadd() and gv_SVadd() into gv_add_by_type(). X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d5713896ecd1399c9c6c4076514a33eb2880d8c3;p=p5sagit%2Fp5-mst-13.2.git Merge gv_AVadd(), gv_HVadd() and gv_SVadd() into gv_add_by_type(). The "short" names become macro wrappers, and the Perl_* versions become mathoms. --- diff --git a/embed.fnc b/embed.fnc index 54389d5..3ada68a 100644 --- a/embed.fnc +++ b/embed.fnc @@ -339,8 +339,9 @@ p |char* |getenv_len |NN const char *env_elem|NN unsigned long *len pox |void |get_db_sub |NULLOK SV **svp|NN CV *cv Ap |void |gp_free |NULLOK GV* gv Ap |GP* |gp_ref |NULLOK GP* gp -Ap |GV* |gv_AVadd |NN GV* gv -Ap |GV* |gv_HVadd |NN GV* gv +Ap |GV* |gv_add_by_type |NN GV *gv|svtype type +Apmb |GV* |gv_AVadd |NN GV *gv +Apmb |GV* |gv_HVadd |NN GV *gv Ap |GV* |gv_IOadd |NULLOK GV* gv ApR |GV* |gv_autoload4 |NULLOK HV* stash|NN const char* name|STRLEN len|I32 method Ap |void |gv_check |NN const HV* stash @@ -2081,7 +2082,7 @@ p |void |dump_sv_child |NN SV *sv #endif #ifdef PERL_DONT_CREATE_GVSV -Ap |GV* |gv_SVadd |NN GV* gv +Apbm |GV* |gv_SVadd |NN GV *gv #endif Apo |bool |ckwarn |U32 w Apo |bool |ckwarn_d |U32 w diff --git a/embed.h b/embed.h index 0847c63..ae708d6 100644 --- a/embed.h +++ b/embed.h @@ -268,8 +268,7 @@ #endif #define gp_free Perl_gp_free #define gp_ref Perl_gp_ref -#define gv_AVadd Perl_gv_AVadd -#define gv_HVadd Perl_gv_HVadd +#define gv_add_by_type Perl_gv_add_by_type #define gv_IOadd Perl_gv_IOadd #define gv_autoload4 Perl_gv_autoload4 #define gv_check Perl_gv_check @@ -1877,7 +1876,6 @@ #endif #endif #ifdef PERL_DONT_CREATE_GVSV -#define gv_SVadd Perl_gv_SVadd #endif #ifdef PERL_CORE #define offer_nice_chunk Perl_offer_nice_chunk @@ -2599,8 +2597,7 @@ #endif #define gp_free(a) Perl_gp_free(aTHX_ a) #define gp_ref(a) Perl_gp_ref(aTHX_ a) -#define gv_AVadd(a) Perl_gv_AVadd(aTHX_ a) -#define gv_HVadd(a) Perl_gv_HVadd(aTHX_ a) +#define gv_add_by_type(a,b) Perl_gv_add_by_type(aTHX_ a,b) #define gv_IOadd(a) Perl_gv_IOadd(aTHX_ a) #define gv_autoload4(a,b,c,d) Perl_gv_autoload4(aTHX_ a,b,c,d) #define gv_check(a) Perl_gv_check(aTHX_ a) @@ -4228,7 +4225,6 @@ #endif #endif #ifdef PERL_DONT_CREATE_GVSV -#define gv_SVadd(a) Perl_gv_SVadd(aTHX_ a) #endif #if defined(PERL_CORE) || defined(PERL_EXT) #endif diff --git a/global.sym b/global.sym index de14a7b..115490a 100644 --- a/global.sym +++ b/global.sym @@ -126,6 +126,7 @@ Perl_vform Perl_free_tmps Perl_gp_free Perl_gp_ref +Perl_gv_add_by_type Perl_gv_AVadd Perl_gv_HVadd Perl_gv_IOadd diff --git a/gv.c b/gv.c index f16e0ac..d46b253 100644 --- a/gv.c +++ b/gv.c @@ -40,42 +40,26 @@ Perl stores its global variables. static const char S_autoload[] = "AUTOLOAD"; static const STRLEN S_autolen = sizeof(S_autoload)-1; - -#ifdef PERL_DONT_CREATE_GVSV GV * -Perl_gv_SVadd(pTHX_ GV *gv) +Perl_gv_add_by_type(pTHX_ GV *gv, svtype type) { - PERL_ARGS_ASSERT_GV_SVADD; - - if (!gv || SvTYPE((const SV *)gv) != SVt_PVGV) - Perl_croak(aTHX_ "Bad symbol for scalar"); - if (!GvSV(gv)) - GvSV(gv) = newSV(0); - return gv; -} -#endif + SV **where; -GV * -Perl_gv_AVadd(pTHX_ register GV *gv) -{ - PERL_ARGS_ASSERT_GV_AVADD; + PERL_ARGS_ASSERT_GV_ADD_BY_TYPE; if (!gv || SvTYPE((const SV *)gv) != SVt_PVGV) - Perl_croak(aTHX_ "Bad symbol for array"); - if (!GvAV(gv)) - GvAV(gv) = newAV(); - return gv; -} + Perl_croak(aTHX_ "Bad symbol for %s", type == SVt_PVAV ? "array" : type == SVt_PVHV ? "hash" : "scalar"); -GV * -Perl_gv_HVadd(pTHX_ register GV *gv) -{ - PERL_ARGS_ASSERT_GV_HVADD; + if (type == SVt_PVHV) { + where = (SV **)&GvHV(gv); + } else if (type == SVt_PVAV) { + where = (SV **)&GvAV(gv); + } else { + where = &GvSV(gv); + } - if (!gv || SvTYPE((const SV *)gv) != SVt_PVGV) - Perl_croak(aTHX_ "Bad symbol for hash"); - if (!GvHV(gv)) - GvHV(gv) = newHV(); + if (!*where) + *where = newSV_type(type); return gv; } diff --git a/gv.h b/gv.h index 8344997..d09a929 100644 --- a/gv.h +++ b/gv.h @@ -207,6 +207,10 @@ Return the SV from the GV. #define gv_efullname3(sv,gv,prefix) gv_efullname4(sv,gv,prefix,TRUE) #define gv_fetchmethod(stash, name) gv_fetchmethod_autoload(stash, name, TRUE) +#define gv_AVadd(gv) gv_add_by_type((gv), SVt_PVAV) +#define gv_HVadd(gv) gv_add_by_type((gv), SVt_PVHV) +#define gv_SVadd(gv) gv_add_by_type((gv), SVt_NULL) + /* * Local variables: * c-indentation-style: bsd diff --git a/mathoms.c b/mathoms.c index 7eae87e..5ae5d2d 100644 --- a/mathoms.c +++ b/mathoms.c @@ -1473,6 +1473,32 @@ Perl_save_op(pTHX) save_op(); } +#ifdef PERL_DONT_CREATE_GVSV +GV * +Perl_gv_SVadd(pTHX_ GV *gv) +{ + PERL_ARGS_ASSERT_GV_SVADD; + + return gv_SVadd(gv); +} +#endif + +GV * +Perl_gv_AVadd(pTHX_ GV *gv) +{ + PERL_ARGS_ASSERT_GV_AVADD; + + return gv_AVadd(gv); +} + +GV * +Perl_gv_HVadd(pTHX_ register GV *gv) +{ + PERL_ARGS_ASSERT_GV_HVADD; + + return gv_HVadd(gv); +} + #endif /* NO_MATHOMS */ /* diff --git a/proto.h b/proto.h index 8241132..aee22c0 100644 --- a/proto.h +++ b/proto.h @@ -832,13 +832,18 @@ PERL_CALLCONV void Perl_get_db_sub(pTHX_ SV **svp, CV *cv) PERL_CALLCONV void Perl_gp_free(pTHX_ GV* gv); PERL_CALLCONV GP* Perl_gp_ref(pTHX_ GP* gp); -PERL_CALLCONV GV* Perl_gv_AVadd(pTHX_ GV* gv) +PERL_CALLCONV GV* Perl_gv_add_by_type(pTHX_ GV *gv, svtype type) __attribute__nonnull__(pTHX_1); +#define PERL_ARGS_ASSERT_GV_ADD_BY_TYPE \ + assert(gv) + +/* PERL_CALLCONV GV* Perl_gv_AVadd(pTHX_ GV *gv) + __attribute__nonnull__(pTHX_1); */ #define PERL_ARGS_ASSERT_GV_AVADD \ assert(gv) -PERL_CALLCONV GV* Perl_gv_HVadd(pTHX_ GV* gv) - __attribute__nonnull__(pTHX_1); +/* PERL_CALLCONV GV* Perl_gv_HVadd(pTHX_ GV *gv) + __attribute__nonnull__(pTHX_1); */ #define PERL_ARGS_ASSERT_GV_HVADD \ assert(gv) @@ -6342,8 +6347,8 @@ PERL_CALLCONV void Perl_dump_sv_child(pTHX_ SV *sv) #endif #ifdef PERL_DONT_CREATE_GVSV -PERL_CALLCONV GV* Perl_gv_SVadd(pTHX_ GV* gv) - __attribute__nonnull__(pTHX_1); +/* PERL_CALLCONV GV* Perl_gv_SVadd(pTHX_ GV *gv) + __attribute__nonnull__(pTHX_1); */ #define PERL_ARGS_ASSERT_GV_SVADD \ assert(gv) diff --git a/t/pod/diag.t b/t/pod/diag.t index 5f378ae..cfe572f 100644 --- a/t/pod/diag.t +++ b/t/pod/diag.t @@ -191,7 +191,7 @@ Attempt to free unreferenced scalar: SV 0x%x Attempt to reload %s aborted. Compilation failed in require av_reify called on tied array Bad name after %s%s -Bad symbol for scalar +Bad symbol for %s bad top format reference Bizarre copy of %s Bizarre SvTYPE [%d]