summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--op.c11
-rw-r--r--pp.c5
-rw-r--r--sv.c10
-rw-r--r--toke.c12
4 files changed, 17 insertions, 21 deletions
diff --git a/op.c b/op.c
index 949d8f427e..b5946fa576 100644
--- a/op.c
+++ b/op.c
@@ -1534,10 +1534,7 @@ S_apply_attrs(pTHX_ HV *stash, SV *target, OP *attrs, bool for_my)
/* fake up C<use attributes $pkg,$rv,@attrs> */
ENTER; /* need to protect against side-effects of 'use' */
SAVEINT(PL_expect);
- if (stash)
- stashsv = newSVpvn(HvNAME_get(stash), HvNAMELEN_get(stash));
- else
- stashsv = &PL_sv_no;
+ stashsv = stash ? newSVhek(HvNAME_HEK(stash)) : &PL_sv_no;
#define ATTRSMODULE "attributes"
#define ATTRSMODULE_PM "attributes.pm"
@@ -1587,10 +1584,8 @@ S_apply_attrs_my(pTHX_ HV *stash, OP *target, OP *attrs, OP **imopsp)
pack = newSVOP(OP_CONST, 0, newSVpvn(ATTRSMODULE, sizeof(ATTRSMODULE)-1));
/* Build up the real arg-list. */
- if (stash)
- stashsv = newSVpvn(HvNAME_get(stash), HvNAMELEN_get(stash));
- else
- stashsv = &PL_sv_no;
+ stashsv = stash ? newSVhek(HvNAME_HEK(stash)) : &PL_sv_no;
+
arg = newOP(OP_PADSV, 0);
arg->op_targ = target->op_targ;
arg = prepend_elem(OP_LIST,
diff --git a/pp.c b/pp.c
index 97a5cfba8a..2014f6f525 100644
--- a/pp.c
+++ b/pp.c
@@ -600,9 +600,8 @@ PP(pp_gelem)
break;
case 'P':
if (strEQ(elem2, "ACKAGE")) {
- const char *name = HvNAME_get(GvSTASH(gv));
- sv = newSVpvn(name ? name : "__ANON__",
- name ? HvNAMELEN_get(GvSTASH(gv)) : 8);
+ const HEK *hek = HvNAME_HEK(GvSTASH(gv));
+ sv = hek ? newSVhek(hek) : newSVpvn("__ANON__", 8);
}
break;
case 'S':
diff --git a/sv.c b/sv.c
index 546df0ac12..bb7f037205 100644
--- a/sv.c
+++ b/sv.c
@@ -7606,7 +7606,8 @@ Perl_newSVpvn(pTHX_ const char *s, STRLEN len)
=for apidoc newSVpv_hek
Creates a new SV from the hash key structure. It will generate scalars that
-point to the shared string table where possible.
+point to the shared string table where possible. Returns a new (undefined)
+SV if the hek is NULL.
=cut
*/
@@ -7614,6 +7615,13 @@ point to the shared string table where possible.
SV *
Perl_newSVhek(pTHX_ const HEK *hek)
{
+ if (!hek) {
+ SV *sv;
+
+ new_SV(sv);
+ return sv;
+ }
+
if (HEK_LEN(hek) == HEf_SVKEY) {
return newSVsv(*(SV**)HEK_KEY(hek));
} else {
diff --git a/toke.c b/toke.c
index 26b7f3dc68..d09d19143b 100644
--- a/toke.c
+++ b/toke.c
@@ -4346,8 +4346,7 @@ Perl_yylex(pTHX)
case KEY___PACKAGE__:
yylval.opval = (OP*)newSVOP(OP_CONST, 0,
(PL_curstash
- ? newSVpvn(HvNAME_get(PL_curstash),
- HvNAMELEN_get(PL_curstash))
+ ? newSVhek(HvNAME_HEK(PL_curstash))
: &PL_sv_undef));
TERM(THING);
@@ -5540,9 +5539,7 @@ S_pending_ident(pTHX)
/* build ops for a bareword */
HV *stash = PAD_COMPNAME_OURSTASH(tmp);
HEK *stashname = HvNAME_HEK(stash);
- SV *sym = stashname
- ? newSVpvn(HEK_KEY(stashname), HEK_LEN(stashname))
- : newSVpvn(0, 0);
+ SV *sym = newSVhek(stashname);
sv_catpvn(sym, "::", 2);
sv_catpv(sym, PL_tokenbuf+1);
yylval.opval = (OP*)newSVOP(OP_CONST, 0, sym);
@@ -9744,10 +9741,7 @@ S_scan_inputsymbol(pTHX_ char *start)
if (PAD_COMPNAME_FLAGS(tmp) & SVpad_OUR) {
HV *stash = PAD_COMPNAME_OURSTASH(tmp);
HEK *stashname = HvNAME_HEK(stash);
- SV *sym = sv_2mortal(stashname
- ? newSVpvn(HEK_KEY(stashname),
- HEK_LEN(stashname))
- : newSVpvn(0, 0));
+ SV *sym = sv_2mortal(newSVhek(stashname));
sv_catpvn(sym, "::", 2);
sv_catpv(sym, d+1);
d = SvPVX(sym);