Indeed, it does seem to work without the lhs type declaration, but I've hit
another show stopper. I have modified my code somewhat since the original
message, so let me include the relevant parts.
cdef class TermIterator:
cdef xapianlib.Document * _doc
cdef xapianlib.TermIterator * _current
cdef _advance(self):
if self._doc == NULL:
raise StopIteration
if self._current == NULL:
# Turn reference into pointer.
self._current = new xapianlib.TermIterator(
self._doc.termlist_begin())
end = self._doc.termlist_end()
if deref(self._current) != end:
postinc(self._current)
else:
raise StopIteration
def __next__(self):
self._advance()
Error compiling Cython file:
------------------------------------------------------------
...
raise StopIteration
if self._current == NULL:
self._current = new xapianlib.TermIterator(
self._doc.termlist_begin())
end = self._doc.termlist_end()
if deref(self._current) != end:
^
------------------------------------------------------------
xapian.pyx:264:32: Invalid types for '!=' (TermIterator, TermIterator)
The problem is that equivalent C++ code looks something like this:
serialise_document(const Xapian::Document &doc)
{
// ...
Xapian::TermIterator term;
for (term = doc.termlist_begin(); term != doc.termlist_end(); ++term) {
// ...
}
You can see that the conditional in the for-loop is comparing two
Xapian::TermIterator objects. doc.termlist.end() returns the same type as
doc.termlist_begin(), i.e. a Xapian::TermIterator[1]. I don't know how to
translate that into the equivalent Cython code. I thought there might be a
cython.operator.equality operator or somesuch, but there's not.
Is this possible?
Cheers,
-Barry
[1]
http://xapian.org/docs/apidoc/html/classXapian_1_1Document.html