Skip to content

Commit

Permalink
throw exception when nullptr iterator is provided
Browse files Browse the repository at this point in the history
Signed-off-by: Buqian Zheng <[email protected]>
  • Loading branch information
zhengbuqian committed Nov 22, 2023
1 parent d761bf6 commit 5352241
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions python/knowhere/knowhere.i
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,15 @@ class GILReleaser {
class AnnIteratorWrap {
public:
AnnIteratorWrap(std::shared_ptr<IndexNode::iterator> it = nullptr) : it_(it) {
if (it_ == nullptr) {
throw std::runtime_error("ann iterator must not be nullptr.");
}
}
~AnnIteratorWrap() {
}

bool HasNext() {
return it_ && it_->HasNext();
return it_->HasNext();
}

std::pair<int64_t, float> Next() {
Expand Down Expand Up @@ -182,12 +185,12 @@ class IndexWrap {
GetAnnIterator(knowhere::DataSetPtr dataset, const std::string& json, const knowhere::BitsetView& bitset, knowhere::Status& status) {
GILReleaser rel;
auto res = idx.AnnIterator(*dataset, knowhere::Json::parse(json), bitset);
std::vector<AnnIteratorWrap> result;
if (!res.has_value()) {
status = res.error();
return std::vector<AnnIteratorWrap>();
return result;
}
status = knowhere::Status::success;
std::vector<AnnIteratorWrap> result;
for (auto it : res.value()) {
result.emplace_back(it);
}
Expand Down

0 comments on commit 5352241

Please sign in to comment.