Commit 1874cddc authored by Kevin Modzelewski's avatar Kevin Modzelewski Committed by Kevin Modzelewski

Another setAddStolen issue

This time it was if __eq__ throws.
parent 968cd670
# expected: reffail
# - leaked refs
import unittest
from test import test_support
import gc
......
......@@ -36,10 +36,16 @@ BoxedClass* dictiteritem_cls = NULL;
}
static void _dictSetStolen(BoxedDict* self, BoxAndHash k, STOLEN(Box*) v) {
Box*& slot = self->d[k];
Box* old_val = slot;
Box** slot = NULL;
try {
slot = &self->d[k];
} catch (ExcInfo e) {
Py_DECREF(v);
throw e;
}
Box* old_val = *slot;
slot = v;
*slot = v;
if (old_val) {
Py_DECREF(old_val);
......
......@@ -25,10 +25,21 @@ extern "C" Box* createSet() {
}
static void _setAddStolen(BoxedSet* self, STOLEN(BoxAndHash) val) {
auto&& p = self->s.insert(val);
if (!p.second /* already exists */) {
// keep the original key
try {
auto&& p = self->s.insert(val);
// Is there a nicer way to represent try-else?
try {
if (!p.second /* already exists */) {
// keep the original key
Py_DECREF(val.value);
}
} catch (ExcInfo e) {
abort();
}
} catch (ExcInfo e) {
Py_DECREF(val.value);
throw e;
}
}
......
......@@ -55,3 +55,18 @@ d = {}
for i in xrange(1000):
d[C(i)] = i
print len(d)
class NonEq(object):
def __eq__(self, rhs):
1/0
def __hash__(self):
return 0
d = {}
d[NonEq()] = 1
try:
d[NonEq()] = 2
except ZeroDivisionError as e:
print e
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