Commit 63711818 authored by Xavier Thompson's avatar Xavier Thompson

Fix cypclass dict item deletion invalidating active iterators

parent 84e0507e
...@@ -286,13 +286,17 @@ cdef cypclass cypdict[K, V]: ...@@ -286,13 +286,17 @@ cdef cypclass cypdict[K, V]:
it = self._indices.find(key) it = self._indices.find(key)
end = self._indices.end() end = self._indices.end()
if it != end: if it != end:
index = dereference(it).second if self._active_iterators == 0:
Cy_DECREF(self._items[index].first) index = dereference(it).second
Cy_DECREF(self._items[index].second) Cy_DECREF(self._items[index].first)
self._indices.erase(it) Cy_DECREF(self._items[index].second)
if index < self._items.size() - 1: self._indices.erase(it)
self._items[index] = self._items[self._indices.size() - 1] if index < self._items.size() - 1:
self._items.pop_back() self._items[index] = self._items[self._indices.size() - 1]
self._items.pop_back()
else:
with gil:
raise RuntimeError("Modifying a dictionary with active iterators")
else: else:
with gil: with gil:
raise KeyError("Deleting nonexistent item") raise KeyError("Deleting nonexistent item")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment