From 0631f3b1099360c04214363a9b72a9dfe3001223 Mon Sep 17 00:00:00 2001 From: Bob Nystrom Date: Thu, 6 Aug 2015 06:55:30 -0700 Subject: [PATCH] Fix deadlock bug in map insertion. --- src/vm/wren_value.c | 11 +++-------- test/core/map/churn.wren | 11 +++++++++++ 2 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 test/core/map/churn.wren diff --git a/src/vm/wren_value.c b/src/vm/wren_value.c index 843d6589..5fab71c7 100644 --- a/src/vm/wren_value.c +++ b/src/vm/wren_value.c @@ -388,14 +388,9 @@ static bool addEntry(MapEntry* entries, uint32_t capacity, // If we found an open slot, the key is not in the table. if (IS_UNDEFINED(entry->key)) { - // Don't stop at a tombstone, though, because the key may be found after - // it. - if (IS_FALSE(entry->value)) - { - entry->key = key; - entry->value = value; - return true; - } + entry->key = key; + entry->value = value; + return true; } else if (wrenValuesEqual(entry->key, key)) { diff --git a/test/core/map/churn.wren b/test/core/map/churn.wren new file mode 100644 index 00000000..97674638 --- /dev/null +++ b/test/core/map/churn.wren @@ -0,0 +1,11 @@ +// This is a regression test for a bug where inserting in a map would not +// correctly reuse tombstone entries, eventually deadlocking on insert. +var map = {} + +for (i in 0...100) { + map[i] = i + + if (i >= 10) map.remove(i - 10) +} + +IO.print(map.count) // expect: 10