summaryrefslogtreecommitdiff
path: root/hv.h
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2013-03-18 00:28:03 +0100
committerYves Orton <demerphq@gmail.com>2013-03-19 00:23:12 +0100
commita7b39f85d7caac0822fdcd78400e131a95f11148 (patch)
tree98e120c5fda1104125ad53cdd500e2e8f6c2f05c /hv.h
parentd5fc06cbb416442b7c14833a0e107aa24005a47b (diff)
downloadperl-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.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/hv.h b/hv.h
index f2dd8e131f..e6b9bb8288 100644
--- a/hv.h
+++ b/hv.h
@@ -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: */