Commit ce4fe4f9 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #1132 from Daetalus/ref_nexedi_set

add refcounting annotation to some set function
parents c96527c6 815d054b
...@@ -276,8 +276,12 @@ static Box* setRepr(BoxedSet* self) { ...@@ -276,8 +276,12 @@ static Box* setRepr(BoxedSet* self) {
} }
static void _setSymmetricDifferenceUpdate(BoxedSet* self, Box* other) { static void _setSymmetricDifferenceUpdate(BoxedSet* self, Box* other) {
if (!PyAnySet_Check(other)) if (!PyAnySet_Check(other)) {
other = makeNewSet(self->cls, other); other = makeNewSet(self->cls, other);
} else {
Py_INCREF(other);
}
AUTO_DECREF(other);
BoxedSet* other_set = static_cast<BoxedSet*>(other); BoxedSet* other_set = static_cast<BoxedSet*>(other);
...@@ -298,8 +302,7 @@ static BoxedSet* setIntersection2(BoxedSet* self, Box* container) { ...@@ -298,8 +302,7 @@ static BoxedSet* setIntersection2(BoxedSet* self, Box* container) {
BoxedSet* rtn = makeNewSet(self->cls, NULL); BoxedSet* rtn = makeNewSet(self->cls, NULL);
for (auto elt : container->pyElements()) { for (auto elt : container->pyElements()) {
if (self->s.count(elt)) { if (self->s.count(elt)) {
rtn->s.insert(elt); _setAddStolen(rtn, elt);
// steal the ref
} else { } else {
Py_DECREF(elt); Py_DECREF(elt);
} }
...@@ -612,6 +615,7 @@ static Box* setIntersection(BoxedSet* self, BoxedTuple* args) { ...@@ -612,6 +615,7 @@ static Box* setIntersection(BoxedSet* self, BoxedTuple* args) {
static Box* setIntersectionUpdate(BoxedSet* self, BoxedTuple* args) { static Box* setIntersectionUpdate(BoxedSet* self, BoxedTuple* args) {
Box* tmp = setIntersection(self, args); Box* tmp = setIntersection(self, args);
AUTO_DECREF(tmp);
std::swap(self->s, ((BoxedSet*)tmp)->s); std::swap(self->s, ((BoxedSet*)tmp)->s);
return incref(None); return incref(None);
} }
...@@ -660,6 +664,7 @@ Box* setEq(BoxedSet* self, BoxedSet* rhs) { ...@@ -660,6 +664,7 @@ Box* setEq(BoxedSet* self, BoxedSet* rhs) {
Box* setNe(BoxedSet* self, BoxedSet* rhs) { Box* setNe(BoxedSet* self, BoxedSet* rhs) {
Box* r = setEq(self, rhs); Box* r = setEq(self, rhs);
AUTO_DECREF(r);
assert(r->cls == bool_cls); assert(r->cls == bool_cls);
return boxBool(r == False); return boxBool(r == False);
} }
......
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