Commit a0f0cb72 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #1152 from kmod/refcounting

Fix another raise-before-stealing-argument bug
parents 9e7817ed 5deae4d4
...@@ -48,6 +48,17 @@ static void _dictSetStolen(BoxedDict* self, BoxAndHash k, STOLEN(Box*) v) { ...@@ -48,6 +48,17 @@ static void _dictSetStolen(BoxedDict* self, BoxAndHash k, STOLEN(Box*) v) {
} }
} }
static void _dictSetStolen(BoxedDict* self, Box* k, STOLEN(Box*) v) {
BoxAndHash hashed_key;
try {
hashed_key = BoxAndHash(k);
} catch (ExcInfo e) {
Py_DECREF(v);
throw e;
}
return _dictSetStolen(self, hashed_key, v);
}
static void _dictSet(BoxedDict* self, BoxAndHash k, Box* v) { static void _dictSet(BoxedDict* self, BoxAndHash k, Box* v) {
_dictSetStolen(self, k, incref(v)); _dictSetStolen(self, k, incref(v));
} }
......
...@@ -920,6 +920,7 @@ struct BoxAndHash { ...@@ -920,6 +920,7 @@ struct BoxAndHash {
Box* value; Box* value;
size_t hash; size_t hash;
BoxAndHash() {}
BoxAndHash(Box* value) : value(value), hash(PyHasher()(value)) {} BoxAndHash(Box* value) : value(value), hash(PyHasher()(value)) {}
BoxAndHash(Box* value, size_t hash) : value(value), hash(hash) {} BoxAndHash(Box* value, size_t hash) : value(value), hash(hash) {}
......
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