summaryrefslogtreecommitdiff
path: root/pp_hot.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2021-09-12 10:42:25 +0000
committerCraig A. Berry <craigberry@mac.com>2021-09-12 15:54:41 -0500
commit00164771421225a404b0f24a96ce9a65e76b4215 (patch)
tree5940debbabe873a71de256e0b07eda699636b59f /pp_hot.c
parent62a725033d9327b2e97960ce74aba9fdf2f5c5bf (diff)
downloadperl-00164771421225a404b0f24a96ce9a65e76b4215.tar.gz
On VMS, %ENV in scalar context must call prime_env_iter()
Otherwise it will return wrong results, unless other code happens to have iterated over %ENV. This bug has probably existed forever.
Diffstat (limited to 'pp_hot.c')
-rw-r--r--pp_hot.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/pp_hot.c b/pp_hot.c
index acb2616dda..45f16c6be2 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -1813,6 +1813,19 @@ S_padhv_rv2hv_common(pTHX_ HV *hv, U8 gimme, bool is_keys, bool has_targ)
}
}
else {
+#if defined(DYNAMIC_ENV_FETCH) && defined(VMS)
+ /* maybe nothing set up %ENV for iteration yet...
+ do this always (not just if HvUSEDKEYS(hv) is currently 0) because
+ we ought to give a *consistent* answer to "how many keys?"
+ whether we ask this op in scalar context, or get the list of all
+ keys then check its length, and whether we do either with or without
+ an %ENV lookup first. prime_env_iter() returns quickly if nothing
+ needs doing. */
+ if (SvRMAGICAL((const SV *)hv)
+ && mg_find((const SV *)hv, PERL_MAGIC_env)) {
+ prime_env_iter();
+ }
+#endif
i = HvUSEDKEYS(hv);
if (is_bool) {
sv = i ? &PL_sv_yes : &PL_sv_zero;