Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make newSV_type() an inline function #19414

Merged
merged 3 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -5551,6 +5551,7 @@ scope.h Scope entry and exit header
SECURITY.md Add Security Policy for GitHub
sv.c Scalar value code
sv.h Scalar value header
sv_inline.h Perl_newSV_type and required defs
t/base/cond.t See if conditionals work
t/base/if.t See if if works
t/base/lex.t See if lexical items work
Expand Down
9 changes: 4 additions & 5 deletions av.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ Perl_av_fetch(pTHX_ AV *av, SSize_t key, I32 lval)
return NULL;
}

sv = sv_newmortal();
sv_upgrade(sv, SVt_PVLV);
sv = newSV_type_mortal(SVt_PVLV);
mg_copy(MUTABLE_SV(av), sv, 0, key);
if (!tied_magic) /* for regdata, force leavesub to make copies */
SvTEMP_off(sv);
Expand All @@ -292,7 +291,7 @@ Perl_av_fetch(pTHX_ AV *av, SSize_t key, I32 lval)

if (!AvARRAY(av)[key]) {
emptyness:
return lval ? av_store(av,key,newSV(0)) : NULL;
return lval ? av_store(av,key,newSV_type(SVt_NULL)) : NULL;
}

return &AvARRAY(av)[key];
Expand Down Expand Up @@ -473,7 +472,7 @@ Perl_av_make(pTHX_ SSize_t size, SV **strp)

SvGETMAGIC(*strp); /* before newSV, in case it dies */
AvFILLp(av)++;
ary[i] = newSV(0);
ary[i] = newSV_type(SVt_NULL);
sv_setsv_flags(ary[i], *strp,
SV_DO_COW_SVSETSV|SV_NOSTEAL);
strp++;
Expand Down Expand Up @@ -1124,7 +1123,7 @@ Perl_av_iter_p(pTHX_ AV *av) {

SV *
Perl_av_nonelem(pTHX_ AV *av, SSize_t ix) {
SV * const sv = newSV(0);
SV * const sv = newSV_type(SVt_NULL);
PERL_ARGS_ASSERT_AV_NONELEM;
if (!av_store(av,ix,sv))
return sv_2mortal(sv); /* has tie magic */
Expand Down
2 changes: 1 addition & 1 deletion doop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ Perl_do_kv(pTHX)

if (gimme == G_SCALAR) {
if (PL_op->op_flags & OPf_MOD || LVRET) { /* lvalue */
SV * const ret = sv_2mortal(newSV_type(SVt_PVLV)); /* Not TARG RT#67838 */
SV * const ret = newSV_type_mortal(SVt_PVLV); /* Not TARG RT#67838 */
sv_magic(ret, NULL, PERL_MAGIC_nkeys, NULL, 0);
LvTYPE(ret) = 'k';
LvTARG(ret) = SvREFCNT_inc_simple(keys);
Expand Down
2 changes: 1 addition & 1 deletion dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -2674,7 +2674,7 @@ S_append_gv_name(pTHX_ GV *gv, SV *out)
sv_catpvs_nomg(out, "<NULLGV>");
return;
}
sv = newSV(0);
sv = newSV_type(SVt_NULL);
gv_fullname4(sv, gv, NULL, FALSE);
Perl_sv_catpvf(aTHX_ out, "$%" SVf, SVfARG(sv));
SvREFCNT_dec_NN(sv);
Expand Down
7 changes: 4 additions & 3 deletions embed.fnc
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,8 @@ Apd |SV* |newSVrv |NN SV *const rv|NULLOK const char *const classname
ApMbdR |SV* |newSVsv |NULLOK SV *const old
AmdR |SV* |newSVsv_nomg |NULLOK SV *const old
AdpR |SV* |newSVsv_flags |NULLOK SV *const old|I32 flags
ApdR |SV* |newSV_type |const svtype type
ApdiR |SV* |newSV_type |const svtype type
ApdIR |SV* |newSV_type_mortal|const svtype type
ApdR |OP* |newUNOP |I32 type|I32 flags|NULLOK OP* first
ApdR |OP* |newUNOP_AUX |I32 type|I32 flags|NULLOK OP* first \
|NULLOK UNOP_AUX_item *aux
Expand Down Expand Up @@ -3165,7 +3166,7 @@ S |STRLEN |sv_pos_b2u_midway|NN const U8 *const s|NN const U8 *const target \
S |void |assert_uft8_cache_coherent|NN const char *const func \
|STRLEN from_cache|STRLEN real|NN SV *const sv
ST |char * |F0convert |NV nv|NN char *const endbuf|NN STRLEN *const len
S |SV * |more_sv
Cp |SV * |more_sv
S |bool |sv_2iuv_common |NN SV *const sv
S |void |glob_assign_glob|NN SV *const dsv|NN SV *const ssv \
|const int dtype
Expand All @@ -3174,7 +3175,7 @@ S |void |anonymise_cv_maybe |NN GV *gv|NN CV *cv
#endif

: Used in sv.c and hv.c
po |void * |more_bodies |const svtype sv_type|const size_t body_size \
Cpo |void * |more_bodies |const svtype sv_type|const size_t body_size \
|const size_t arena_size
EXpR |SV* |get_and_check_backslash_N_name|NN const char* s \
|NN const char* e \
Expand Down
5 changes: 4 additions & 1 deletion embed.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@
#define newSVOP(a,b,c) Perl_newSVOP(aTHX_ a,b,c)
#define newSVREF(a) Perl_newSVREF(aTHX_ a)
#define newSV_type(a) Perl_newSV_type(aTHX_ a)
#define newSV_type_mortal(a) Perl_newSV_type_mortal(aTHX_ a)
#define newSVhek(a) Perl_newSVhek(aTHX_ a)
#define newSViv(a) Perl_newSViv(aTHX_ a)
#define newSVnv(a) Perl_newSVnv(aTHX_ a)
Expand Down Expand Up @@ -880,6 +881,9 @@
#define dump_mstats(a) Perl_dump_mstats(aTHX_ a)
#define get_mstats(a,b,c) Perl_get_mstats(aTHX_ a,b,c)
#endif
#if defined(PERL_IN_SV_C)
#define more_sv() Perl_more_sv(aTHX)
#endif
#if defined(PERL_USE_3ARG_SIGHANDLER)
#define csighandler Perl_csighandler
#endif
Expand Down Expand Up @@ -1929,7 +1933,6 @@
#define find_uninit_var(a,b,c,d) S_find_uninit_var(aTHX_ a,b,c,d)
#define glob_2number(a) S_glob_2number(aTHX_ a)
#define glob_assign_glob(a,b,c) S_glob_assign_glob(aTHX_ a,b,c)
#define more_sv() S_more_sv(aTHX)
#define not_a_number(a) S_not_a_number(aTHX_ a)
#define not_incrementable(a) S_not_incrementable(aTHX_ a)
#define ptr_table_find S_ptr_table_find
Expand Down
12 changes: 6 additions & 6 deletions gv.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ Perl_newGP(pTHX_ GV *const gv)
Newxz(gp, 1, GP);
gp->gp_egv = gv; /* allow compiler to reuse gv after this */
#ifndef PERL_DONT_CREATE_GVSV
gp->gp_sv = newSV(0);
gp->gp_sv = newSV_type(SVt_NULL);
#endif

/* PL_curcop may be null here. E.g.,
Expand Down Expand Up @@ -294,7 +294,7 @@ Perl_cvgv_from_hek(pTHX_ CV *cv)
if (!CvSTASH(cv)) return NULL;
ASSUME(CvNAME_HEK(cv));
svp = hv_fetchhek(CvSTASH(cv), CvNAME_HEK(cv), 0);
gv = MUTABLE_GV(svp && *svp ? *svp : newSV(0));
gv = MUTABLE_GV(svp && *svp ? *svp : newSV_type(SVt_NULL));
if (!isGV(gv))
gv_init_pvn(gv, CvSTASH(cv), HEK_KEY(CvNAME_HEK(cv)),
HEK_LEN(CvNAME_HEK(cv)),
Expand Down Expand Up @@ -580,7 +580,7 @@ S_maybe_add_coresub(pTHX_ HV * const stash, GV *gv,
ampable = FALSE;
}
if (!gv) {
gv = (GV *)newSV(0);
gv = (GV *)newSV_type(SVt_NULL);
gv_init(gv, stash, name, len, TRUE);
}
GvMULTI_on(gv);
Expand Down Expand Up @@ -1359,7 +1359,7 @@ Perl_gv_autoload_pvn(pTHX_ HV *stash, const char *name, STRLEN len, U32 flags)
if (!isGV(vargv)) {
gv_init_pvn(vargv, varstash, S_autoload, S_autolen, 0);
#ifdef PERL_DONT_CREATE_GVSV
GvSV(vargv) = newSV(0);
GvSV(vargv) = newSV_type(SVt_NULL);
#endif
}
LEAVE;
Expand Down Expand Up @@ -2516,7 +2516,7 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
/* By this point we should have a stash and a name */
gvp = (GV**)hv_fetch(stash,name,is_utf8 ? -(I32)len : (I32)len,add);
if (!gvp || *gvp == (const GV *)&PL_sv_undef) {
if (addmg) gv = (GV *)newSV(0); /* tentatively */
if (addmg) gv = (GV *)newSV_type(SVt_NULL); /* tentatively */
else return NULL;
}
else gv = *gvp, addmg = 0;
Expand Down Expand Up @@ -3801,7 +3801,7 @@ Perl_amagic_call(pTHX_ SV *left, SV *right, int method, int flags)
break;
case G_LIST:
if (flags & AMGf_want_list) {
res = sv_2mortal((SV *)newAV());
res = newSV_type_mortal(SVt_PVAV);
av_extend((AV *)res, nret);
while (nret--)
av_store((AV *)res, nret, POPs);
Expand Down
32 changes: 23 additions & 9 deletions hv.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ static void
S_hv_notallowed(pTHX_ int flags, const char *key, I32 klen,
const char *msg)
{
SV * const sv = sv_newmortal();
/* Straight to SVt_PVN here, as needed by sv_setpvn_fresh and
* sv_usepvn would otherwise call it */
SV * const sv = newSV_type_mortal(SVt_PV);

PERL_ARGS_ASSERT_HV_NOTALLOWED;

sv_upgrade(sv, SVt_PV); /* Needed by sv_setpvn_fresh and
* sv_usepvn would otherwise call it */
if (!(flags & HVhek_FREEKEY)) {
sv_setpvn_fresh(sv, key, klen);
}
Expand Down Expand Up @@ -480,7 +480,7 @@ Perl_hv_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
HV_FETCH_ISSTORE
| HV_DISABLE_UVAR_XKEY
| return_svp,
newSV(0), hash);
newSV_type(SVt_NULL), hash);
} else {
if (flags & HVhek_FREEKEY)
Safefree(key);
Expand Down Expand Up @@ -739,7 +739,7 @@ Perl_hv_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
break;
}
/* LVAL fetch which actually needs a store. */
val = newSV(0);
val = newSV_type(SVt_NULL);
HvPLACEHOLDERS(hv)--;
} else {
/* store */
Expand Down Expand Up @@ -793,7 +793,7 @@ Perl_hv_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
return NULL;
}
if (action & HV_FETCH_LVALUE) {
val = action & HV_FETCH_EMPTY_HE ? NULL : newSV(0);
val = action & HV_FETCH_EMPTY_HE ? NULL : newSV_type(SVt_NULL);
if (SvMAGICAL(hv)) {
/* At this point the old hv_fetch code would call to hv_store,
which in turn might do some tied magic. So we need to make that
Expand Down Expand Up @@ -968,6 +968,7 @@ SV *
Perl_hv_scalar(pTHX_ HV *hv)
{
SV *sv;
UV u;

PERL_ARGS_ASSERT_HV_SCALAR;

Expand All @@ -977,8 +978,21 @@ Perl_hv_scalar(pTHX_ HV *hv)
return magic_scalarpack(hv, mg);
}

sv = sv_newmortal();
sv_setuv(sv, HvUSEDKEYS(hv));
sv = newSV_type_mortal(SVt_IV);

/* Inlined sv_setuv(sv, HvUSEDKEYS(hv)) follows:*/
u = HvUSEDKEYS(hv);

if (u <= (UV)IV_MAX) {
SvIV_set(sv, (IV)u);
(void)SvIOK_only(sv);
SvTAINT(sv);
} else {
SvIV_set(sv, 0);
SvUV_set(sv, u);
(void)SvIOK_only_UV(sv);
SvTAINT(sv);
}

return sv;
}
Expand Down Expand Up @@ -3247,7 +3261,7 @@ S_refcounted_he_value(pTHX_ const struct refcounted_he *he)

switch(he->refcounted_he_data[0] & HVrhek_typemask) {
case HVrhek_undef:
value = newSV(0);
value = newSV_type(SVt_NULL);
break;
case HVrhek_delete:
value = &PL_sv_placeholder;
Expand Down
2 changes: 1 addition & 1 deletion inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Perl_av_fetch_simple(pTHX_ AV *av, SSize_t key, I32 lval)
assert(key > -1);

if ( (key > AvFILLp(av)) || !AvARRAY(av)[key]) {
return lval ? av_store_simple(av,key,newSV(0)) : NULL;
return lval ? av_store_simple(av,key,newSV_type(SVt_NULL)) : NULL;
} else {
return &AvARRAY(av)[key];
}
Expand Down
2 changes: 1 addition & 1 deletion mg.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ Perl_sv_string_from_errnum(pTHX_ int errnum, SV *tgtsv)
{
char const *errstr;
if(!tgtsv)
tgtsv = sv_newmortal();
tgtsv = newSV_type_mortal(SVt_PV);
errstr = my_strerror(errnum);
if(errstr) {
sv_setpv(tgtsv, errstr);
Expand Down
22 changes: 11 additions & 11 deletions mro_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ S_mro_get_linear_isa_dfs(pTHX_ HV *stash, U32 level)

/* not in cache, make a new one */

retval = MUTABLE_AV(sv_2mortal(MUTABLE_SV(newAV())));
retval = MUTABLE_AV(newSV_type_mortal(SVt_PVAV));
/* We use this later in this function, but don't need a reference to it
beyond the end of this function, so reference count is fine. */
our_name = newSVhek(stashhek);
Expand Down Expand Up @@ -347,7 +347,7 @@ S_mro_get_linear_isa_dfs(pTHX_ HV *stash, U32 level)
} else {
/* They have no stash. So create ourselves an ->isa cache
as if we'd copied it from what theirs should be. */
stored = MUTABLE_HV(sv_2mortal(MUTABLE_SV(newHV())));
stored = MUTABLE_HV(newSV_type_mortal(SVt_PVHV));
(void) hv_stores(stored, "UNIVERSAL", &PL_sv_undef);
av_push(retval,
newSVhek(HeKEY_hek(hv_store_ent(stored, sv,
Expand All @@ -357,7 +357,7 @@ S_mro_get_linear_isa_dfs(pTHX_ HV *stash, U32 level)
}
} else {
/* We have no parents. */
stored = MUTABLE_HV(sv_2mortal(MUTABLE_SV(newHV())));
stored = MUTABLE_HV(newSV_type_mortal(SVt_PVHV));
(void) hv_stores(stored, "UNIVERSAL", &PL_sv_undef);
}

Expand Down Expand Up @@ -428,7 +428,7 @@ Perl_mro_get_linear_isa(pTHX_ HV *stash)
SV **svp;
SV **ovp = AvARRAY(old);
SV * const * const oend = ovp + AvFILLp(old) + 1;
isa = (AV *)sv_2mortal((SV *)newAV());
isa = (AV *)newSV_type_mortal(SVt_PVAV);
av_extend(isa, AvFILLp(isa) = AvFILLp(old)+1);
*AvARRAY(isa) = namesv;
svp = AvARRAY(isa)+1;
Expand Down Expand Up @@ -570,7 +570,7 @@ Perl_mro_isa_changed_in(pTHX_ HV* stash)
if(hv_iterinit(isarev)) {
/* Only create the hash if we need it; i.e., if isarev has
any elements. */
isa_hashes = (HV *)sv_2mortal((SV *)newHV());
isa_hashes = (HV *)newSV_type_mortal(SVt_PVHV);
}
while((iter = hv_iternext(isarev))) {
HV* revstash = gv_stashsv(hv_iterkeysv(iter), 0);
Expand Down Expand Up @@ -817,7 +817,7 @@ Perl_mro_package_moved(pTHX_ HV * const stash, HV * const oldstash,
}
else {
SV *aname;
namesv = sv_2mortal((SV *)newAV());
namesv = newSV_type_mortal(SVt_PVAV);
while (name_count--) {
if(memEQs(HEK_KEY(*namep), HEK_LEN(*namep), "main")){
aname = GvNAMELEN(gv) == 1
Expand Down Expand Up @@ -854,9 +854,9 @@ Perl_mro_package_moved(pTHX_ HV * const stash, HV * const oldstash,
wrong name. The names must be set on *all* affected stashes before
we do anything else. (And linearisations must be cleared, too.)
*/
stashes = (HV *) sv_2mortal((SV *)newHV());
stashes = (HV *) newSV_type_mortal(SVt_PVHV);
mro_gather_and_rename(
stashes, (HV *) sv_2mortal((SV *)newHV()),
stashes, (HV *) newSV_type_mortal(SVt_PVHV),
stash, oldstash, namesv
);

Expand Down Expand Up @@ -1119,7 +1119,7 @@ S_mro_gather_and_rename(pTHX_ HV * const stashes, HV * const seen_stashes,
/* Skip the entire loop if the hash is empty. */
if(oldstash && HvTOTALKEYS(oldstash)) {
xhv = (XPVHV*)SvANY(oldstash);
seen = (HV *) sv_2mortal((SV *)newHV());
seen = (HV *) newSV_type_mortal(SVt_PVHV);

/* Iterate through entries in the oldstash, adding them to the
list, meanwhile doing the equivalent of $seen{$key} = 1.
Expand Down Expand Up @@ -1164,7 +1164,7 @@ S_mro_gather_and_rename(pTHX_ HV * const stashes, HV * const seen_stashes,
SV *aname;
items = AvFILLp((AV *)namesv) + 1;
svp = AvARRAY((AV *)namesv);
subname = sv_2mortal((SV *)newAV());
subname = newSV_type_mortal(SVt_PVAV);
while (items--) {
aname = newSVsv(*svp++);
if (len == 1)
Expand Down Expand Up @@ -1247,7 +1247,7 @@ S_mro_gather_and_rename(pTHX_ HV * const stashes, HV * const seen_stashes,
SV *aname;
items = AvFILLp((AV *)namesv) + 1;
svp = AvARRAY((AV *)namesv);
subname = sv_2mortal((SV *)newAV());
subname = newSV_type_mortal(SVt_PVAV);
while (items--) {
aname = newSVsv(*svp++);
if (len == 1)
Expand Down
6 changes: 3 additions & 3 deletions op.c
Original file line number Diff line number Diff line change
Expand Up @@ -10964,7 +10964,7 @@ S_op_const_sv(pTHX_ const OP *o, CV *cv, bool allow_lex)
if (type == OP_CONST && cSVOPo->op_sv)
sv = cSVOPo->op_sv;
else if (type == OP_UNDEF && !o->op_private) {
sv = newSV(0);
sv = newSV_type(SVt_NULL);
SAVEFREESV(sv);
}
else if (allow_lex && type == OP_PADSV) {
Expand Down Expand Up @@ -13623,7 +13623,7 @@ Perl_ck_glob(pTHX_ OP *o)
LEAVE;
}
#endif /* !PERL_EXTERNAL_GLOB */
gv = (GV *)newSV(0);
gv = (GV *)newSV_type(SVt_NULL);
gv_init(gv, 0, "", 0, 0);
gv_IOadd(gv);
op_append_elem(OP_GLOB, o, newGVOP(OP_GV, 0, gv));
Expand Down Expand Up @@ -13689,7 +13689,7 @@ Perl_ck_index(pTHX_ OP *o)
if ( (!SvPOK(sv) || SvNIOKp(sv) || isREGEXP(sv))
&& SvOK(sv) && !SvROK(sv))
{
sv = newSV(0);
sv = newSV_type(SVt_NULL);
sv_copypv(sv, kSVOP->op_sv);
SvREFCNT_dec_NN(kSVOP->op_sv);
kSVOP->op_sv = sv;
Expand Down
Loading