Commit 583c6a3a authored by Kevin Modzelewski's avatar Kevin Modzelewski Committed by Kevin Modzelewski

Get some internal iterator logic working

parent 4db15e2a
...@@ -541,7 +541,16 @@ public: ...@@ -541,7 +541,16 @@ public:
BoxIteratorImpl* impl; BoxIteratorImpl* impl;
BoxIterator(BoxIteratorImpl* impl) : impl(impl) {} BoxIterator(BoxIteratorImpl* impl) : impl(impl) {}
~BoxIterator() = default; BoxIterator(const BoxIterator& rhs) = default;
BoxIterator(BoxIterator&& rhs) {
impl = rhs.impl;
rhs.impl = NULL;
}
~BoxIterator() {
if (impl)
impl->~BoxIteratorImpl();
}
static llvm::iterator_range<BoxIterator> getRange(Box* container); static llvm::iterator_range<BoxIterator> getRange(Box* container);
bool operator==(BoxIterator const& rhs) const { return impl->isSame(rhs.impl); } bool operator==(BoxIterator const& rhs) const { return impl->isSame(rhs.impl); }
......
...@@ -135,7 +135,10 @@ public: ...@@ -135,7 +135,10 @@ public:
static void dealloc(Box* b) noexcept { static void dealloc(Box* b) noexcept {
BoxedXrangeIterator* self = static_cast<BoxedXrangeIterator*>(b); BoxedXrangeIterator* self = static_cast<BoxedXrangeIterator*>(b);
_PyObject_GC_UNTRACK(self);
Py_DECREF(self->xrange); Py_DECREF(self->xrange);
self->cls->tp_free(self);
} }
static int traverse(Box* s, visitproc visit, void *arg) noexcept { static int traverse(Box* s, visitproc visit, void *arg) noexcept {
BoxedXrangeIterator* self = static_cast<BoxedXrangeIterator*>(s); BoxedXrangeIterator* self = static_cast<BoxedXrangeIterator*>(s);
......
...@@ -38,14 +38,21 @@ public: ...@@ -38,14 +38,21 @@ public:
} }
} }
~BoxIteratorGeneric() {
assert(!value);
Py_XDECREF(iterator);
}
void next() override { void next() override {
STAT_TIMER(t0, "us_timer_iteratorgeneric_next", 0); STAT_TIMER(t0, "us_timer_iteratorgeneric_next", 0);
assert(!value);
Box* next = PyIter_Next(iterator); Box* next = PyIter_Next(iterator);
if (next) { if (next) {
value = next; value = next;
} else { } else {
checkAndThrowCAPIException(); checkAndThrowCAPIException();
Py_CLEAR(iterator);
*this = *end(); *this = *end();
} }
} }
......
...@@ -809,7 +809,7 @@ Box* listIAdd(BoxedList* self, Box* _rhs) { ...@@ -809,7 +809,7 @@ Box* listIAdd(BoxedList* self, Box* _rhs) {
RELEASE_ASSERT(_rhs != self, "unsupported"); RELEASE_ASSERT(_rhs != self, "unsupported");
for (auto* b : _rhs->pyElements()) for (auto* b : _rhs->pyElements())
listAppendInternal(self, b); listAppendInternalStolen(self, b);
Py_INCREF(self); Py_INCREF(self);
return self; return self;
......
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