Ticket #520 (assigned defect)
Wrap C++ iterators as PHP iterators
| Reported by: | Daniel.Menard | Owned by: | olly |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.2.x |
| Component: | Xapian-bindings (PHP) | Version: | 1.2.3 |
| Severity: | minor | Keywords: | |
| Cc: | Blocked By: | ||
| Operating System: | All | Blocking: |
Description
Hi,
I'm not sure if this is a bug or just a precision to add to the documentation, but it is not possible to call XapianTermIterator::get_term() (or get_termfreq) if a previous call to skip_to() or next() has positioned the internal pointer after the last term of the database.
For example, this php script generates a GPF on my machine (windows, php bindings from flax.co.uk, php 5.3.3, Xapian 1.2.3):
<?php $db = Xapian::inmemory_open(); $it = $db->allterms_begin(); $it->skip_to('term'); $it->get_term(); // or $it->get_term_freq(); ?>
The same apply with a not-empty database: skip_to(last term) + next() + get_term() = fault.
Of course, I'm the culprit: I should test for "eof" before trying to dereference my iterator.
This is what I do, now, and it works well:
if (!$it->equals($db->allterms_end()) $it->get_term();
But I was surprised about Xapian generating a GPF and not an Exception, so I thought it was worth reporting.
Cheers,
Daniel
PS: I tested with Xapian 1.2.3, but the behavior is the same with version 1.0.16.
