Apd |HV* |gv_stashpvn |NN const char* name|U32 namelen|I32 create
Apd |HV* |gv_stashsv |NULLOK SV* sv|I32 create
Apd |void |hv_clear |NULLOK HV* tb
+poM |HV * |hv_copy_hints_hv|NN HV *const ohv
Ap |void |hv_delayfree_ent|NN HV* hv|NULLOK HE* entry
Apd |SV* |hv_delete |NULLOK HV* tb|NN const char* key|I32 klen|I32 flags
Apd |SV* |hv_delete_ent |NULLOK HV* tb|NN SV* key|I32 flags|U32 hash
#define gv_stashpvn(a,b,c) Perl_gv_stashpvn(aTHX_ a,b,c)
#define gv_stashsv(a,b) Perl_gv_stashsv(aTHX_ a,b)
#define hv_clear(a) Perl_hv_clear(aTHX_ a)
+#ifdef PERL_CORE
+#endif
#define hv_delayfree_ent(a,b) Perl_hv_delayfree_ent(aTHX_ a,b)
#define hv_delete(a,b,c,d) Perl_hv_delete(aTHX_ a,b,c,d)
#define hv_delete_ent(a,b,c,d) Perl_hv_delete_ent(aTHX_ a,b,c,d)
return hv;
}
+/* A rather specialised version of newHVhv for copying %^H, ensuring all the
+ magic stays on it. */
+HV *
+Perl_hv_copy_hints_hv(pTHX_ HV *const ohv)
+{
+ HV * const hv = newHV();
+ STRLEN hv_fill;
+
+ if (ohv && (hv_fill = HvFILL(ohv))) {
+ STRLEN hv_max = HvMAX(ohv);
+ HE *entry;
+ const I32 riter = HvRITER_get(ohv);
+ HE * const eiter = HvEITER_get(ohv);
+
+ while (hv_max && hv_max + 1 >= hv_fill * 2)
+ hv_max = hv_max / 2;
+ HvMAX(hv) = hv_max;
+
+ hv_iterinit(ohv);
+ while ((entry = hv_iternext_flags(ohv, 0))) {
+ SV *const sv = newSVsv(HeVAL(entry));
+ sv_magic(sv, NULL, PERL_MAGIC_hintselem,
+ (char *)newSVhek (HeKEY_hek(entry)), HEf_SVKEY);
+ hv_store_flags(hv, HeKEY(entry), HeKLEN(entry),
+ sv, HeHASH(entry), HeKFLAGS(entry));
+ }
+ HvRITER_set(ohv, riter);
+ HvEITER_set(ohv, eiter);
+ }
+ hv_magic(hv, NULL, PERL_MAGIC_hints);
+ return hv;
+}
+
void
Perl_hv_free_ent(pTHX_ HV *hv, register HE *entry)
{
package feature;
our $VERSION = '1.00';
-$feature::hint_bits = 0x00020000; # HINT_LOCALIZE_HH
# (feature name) => (internal name, used in %^H)
my %feature = (
=cut
sub import {
- $^H |= $feature::hint_bits; # Need this or %^H won't work
-
my $class = shift;
if (@_ == 0) {
require Carp;
# The hints for pp_sort are now stored in $^H{sort}; older versions
# of perl used the global variable $sort::hints. -- rjh 2005-12-19
-$sort::hint_bits = 0x00020000; # HINT_LOCALIZE_HH
-
$sort::quicksort_bit = 0x00000001;
$sort::mergesort_bit = 0x00000002;
$sort::sort_bits = 0x000000FF; # allow 256 different ones
it's NULL. If needed for threads, the alternative could lock a mutex,
or take other more complex action. */
+ /* Something changed in %^H, so it will need to be restored on scope exit.
+ Doing this here saves a lot of doing it manually in perl code (and
+ forgetting to do it, and consequent subtle errors. */
+ PL_hints |= HINT_LOCALIZE_HH;
PL_compiling.cop_hints
= Perl_refcounted_he_new(aTHX_ PL_compiling.cop_hints,
(SV *)mg->mg_ptr, newSVsv(sv));
dVAR;
assert(mg->mg_len == HEf_SVKEY);
+ PL_hints |= HINT_LOCALIZE_HH;
PL_compiling.cop_hints
= Perl_refcounted_he_new(aTHX_ PL_compiling.cop_hints,
(SV *)mg->mg_ptr, &PL_sv_placeholder);
o->op_targ = (PADOFFSET)PL_hints;
if ((PL_hints & HINT_LOCALIZE_HH) != 0 && GvHV(PL_hintgv)) {
/* Store a copy of %^H that pp_entereval can pick up */
- OP *hhop = newSVOP(OP_CONST, 0, (SV*)newHVhv(GvHV(PL_hintgv)));
+ OP *hhop = newSVOP(OP_CONST, 0,
+ (SV*)Perl_hv_copy_hints_hv(aTHX_ GvHV(PL_hintgv)));
cUNOPo->op_first->op_sibling = hhop;
o->op_private |= OPpEVAL_HAS_HH;
}
PERL_CALLCONV HV* Perl_gv_stashsv(pTHX_ SV* sv, I32 create);
PERL_CALLCONV void Perl_hv_clear(pTHX_ HV* tb);
+PERL_CALLCONV HV * Perl_hv_copy_hints_hv(pTHX_ HV *const ohv)
+ __attribute__nonnull__(pTHX_1);
+
PERL_CALLCONV void Perl_hv_delayfree_ent(pTHX_ HV* hv, HE* entry)
__attribute__nonnull__(pTHX_1);
if (PL_hints & HINT_LOCALIZE_HH) {
SvREFCNT_dec((SV*)GvHV(PL_hintgv));
GvHV(PL_hintgv) = (HV*)SSPOPPTR;
+ assert(GvHV(PL_hintgv));
+ } else if (!GvHV(PL_hintgv)) {
+ /* Need to add a new one manually, else gv_fetchpv() can
+ add one in this code:
+
+ if (SvTYPE(gv) == SVt_PVGV) {
+ if (add) {
+ GvMULTI_on(gv);
+ gv_init_sv(gv, sv_type);
+ if (*name=='!' && sv_type == SVt_PVHV && len==1)
+ require_errno(gv);
+ }
+ return gv;
+ }
+
+ and it won't have the magic set. */
+
+ HV *const hv = newHV();
+ hv_magic(hv, NULL, PERL_MAGIC_hints);
+ GvHV(PL_hintgv) = hv;
}
-
+ assert(GvHV(PL_hintgv));
break;
case SAVEt_COMPPAD:
PL_comppad = (PAD*)SSPOPPTR;
SSCHECK(4); \
if (PL_hints & HINT_LOCALIZE_HH) { \
SSPUSHPTR(GvHV(PL_hintgv)); \
- GvHV(PL_hintgv) = newHVhv(GvHV(PL_hintgv)); \
+ GvHV(PL_hintgv) = Perl_hv_copy_hints_hv(aTHX_ GvHV(PL_hintgv)); \
} \
if (PL_compiling.cop_hints) { \
PL_compiling.cop_hints->refcounted_he_refcnt++; \
sub import {
$^H{mypragma} = 1;
- $^H |= 0x00020000;
}
sub unimport {