diff options
author | Yves Orton <demerphq@gmail.com> | 2013-03-18 00:28:03 +0100 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2013-03-19 00:23:12 +0100 |
commit | a7b39f85d7caac0822fdcd78400e131a95f11148 (patch) | |
tree | 98e120c5fda1104125ad53cdd500e2e8f6c2f05c /hv.h | |
parent | d5fc06cbb416442b7c14833a0e107aa24005a47b (diff) | |
download | perl-a7b39f85d7caac0822fdcd78400e131a95f11148.tar.gz |
detect each() after insert and produce warnings when we do
Inserting into a hash that is being traversed with each()
has always produced undefined behavior. With hash traversal
randomization this is more pronounced, and at the same
time relatively easy to spot. At the cost of an extra U32
in the xpvhv_aux structure we can detect that the xhv_rand
has changed and then produce a warning if it has.
It was suggested on IRC that this should produce a fatal
error, but I couldn't see a clean way to manage that with
"strict", it was much easier to create a "severe" (internal)
warning, which is enabled by default but suppressible with
C<no warnings "internal";> if people /really/ wanted.
Diffstat (limited to 'hv.h')
-rw-r--r-- | hv.h | 2 |
1 files changed, 2 insertions, 0 deletions
@@ -93,6 +93,8 @@ struct xpvhv_aux { struct mro_meta *xhv_mro_meta; HV * xhv_super; /* SUPER method cache */ U32 xhv_rand; /* random value for hash traversal */ + U32 xhv_last_rand; /* last random value for hash traversal, + used to detect each() after insert for warnings */ }; /* hash structure: */ |