From e15888669ebd5c1db19f2bae1e163b4e30702dc9 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Sat, 30 Aug 2014 10:26:58 -0700 Subject: [PATCH] op.c: Calculate hash for CvNAME_HEK I assumed when I wrote that code that share_hek would calculate the hash, like most hash functions; but this internal function assumes the caller does it. Hence, CVs were not sharing their heks with other types of thingies that have heks. A CV named foo and a GV named foo would cause two heks of the same name to be present in the shared string table. --- op.c | 18 +++++++++++------- pad.c | 5 ++++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/op.c b/op.c index 1e4e980..85a0f0b 100644 --- a/op.c +++ b/op.c @@ -7353,10 +7353,12 @@ Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block) if (CvNAMED(*spot)) hek = CvNAME_HEK(*spot); else { + U32 hash; + PERL_HASH(hash, PadnamePV(name)+1, PadnameLEN(name)-1); CvNAME_HEK_set(*spot, hek = share_hek( PadnamePV(name)+1, - PadnameLEN(name)-1 * (PadnameUTF8(name) ? -1 : 1), 0 + PadnameLEN(name)-1 * (PadnameUTF8(name) ? -1 : 1), hash ) ); } @@ -7486,13 +7488,15 @@ Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block) } setname: if (!CvNAME_HEK(cv)) { - CvNAME_HEK_set(cv, - hek - ? share_hek_hek(hek) - : share_hek(PadnamePV(name)+1, + if (hek) share_hek_hek(hek); + else { + U32 hash; + PERL_HASH(hash, PadnamePV(name)+1, PadnameLEN(name)-1); + hek = share_hek(PadnamePV(name)+1, PadnameLEN(name)-1 * (PadnameUTF8(name) ? -1 : 1), - 0) - ); + hash); + } + CvNAME_HEK_set(cv, hek); } if (const_sv) goto clone; diff --git a/pad.c b/pad.c index 42f3734..68e1078 100644 --- a/pad.c +++ b/pad.c @@ -2092,13 +2092,16 @@ S_cv_clone_pad(pTHX_ CV *proto, CV *cv, CV *outside, bool newcv) /* my sub */ /* Just provide a stub, but name it. It will be upgrade to the real thing on scope entry. */ + U32 hash; + PERL_HASH(hash, SvPVX_const(namesv)+1, + SvCUR(namesv) - 1); sv = newSV_type(SVt_PVCV); CvNAME_HEK_set( sv, share_hek(SvPVX_const(namesv)+1, SvCUR(namesv) - 1 * (SvUTF8(namesv) ? -1 : 1), - 0) + hash) ); } else sv = SvREFCNT_inc(ppad[ix]); -- 1.8.3.1