develooper Front page | perl.perl5.changes | Postings from September 2021

[Perl/perl5] e893e1: Test that %ENV iteration with prime_env_iter()is ...

Nicholas Clark via perl5-changes
September 15, 2021 21:24
[Perl/perl5] e893e1: Test that %ENV iteration with prime_env_iter()is ...
Message ID:
  Branch: refs/heads/blead
  Commit: e893e12ccfed2a8d5f0649a8cc133249ca7373ff
  Author: Nicholas Clark <>
  Date:   2021-09-15 (Wed, 15 Sep 2021)

  Changed paths:
    M t/op/each.t

  Log Message:
  Test that %ENV iteration with prime_env_iter() is consistent

  Commit: d5a0a5dd15db7407246717e8c3e8891b9ba7c53c
  Author: Nicholas Clark <>
  Date:   2021-09-15 (Wed, 15 Sep 2021)

  Changed paths:
    M hv.c
    M win32/win32.h

  Log Message:
  Simplify the code related to prime_env_iter().

Of the platforms that define DYNAMIC_ENV_FETCH, prime_env_iter() is only
needed on VMS, so only call it on VMS. Previously we defined a dummy stub on
Win32 (with PERL_IMPLICIT_SYS defined), and did something different again
for __riscos__.

Remove the dummy definition for win32, and change the conditional compilation
to only call prime_env_iter() on VMS. This removes a call to mg_find() on
Win32, which likely can't be optimised away, as the compiler cannot know that
it has no side effects.

Because`iter` points to a structure immediately after of HvARRAY(), it needs
updating if HvARRAY() has moved because it has been expanded.

Code was added for VMS in Aug 2005 to address this bug with commit
    [patch@25334] hv.c vms environment fix.
    From: "John E. Malmberg" <>
    Message-ID: <>


However, the comment added in that code wasn't entirely accurate. The
iteration count doesn't need to be *reset* because prior to that first call
to prime_env_iter() there would be no entries in the hash. In fact, the
iterator *had* to be in its "reset" state - entry == NULL - to enter the
if block. Also, as prime_env_iter() only adds hash values but does not
change the hash's iterator state, it can't change iter->xhv_eiter. Hence
there's no need to re-read *that* value, is it will still be NULL.

Hence the only action needed is to re-initialise iter from HvAUX(), as the
structure it needs to point to has likely been moved in memory by the hash
stores performed by prime_env_iter().

Compare: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About