Skip to content

Commit

Permalink
Merge pull request #343 from joka921/f.batchReadingError
Browse files Browse the repository at this point in the history
Fix a tricky error
  • Loading branch information
niklas88 committed Aug 15, 2020
2 parents 491f23b + 314b4b3 commit c93e090
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/parser/TurtleParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@ TurtleStreamParser<T>::backupState() const {
// _______________________________________________________________
template <class T>
bool TurtleStreamParser<T>::resetStateAndRead(
const TurtleStreamParser::TurtleParserBackupState b) {
TurtleStreamParser::TurtleParserBackupState* bPtr) {
auto& b = *bPtr;
auto nextBytesOpt = _fileBuffer->getNextBlock();
if (!nextBytesOpt || nextBytesOpt.value().empty()) {
// there are no more decompressed bytes, just continue with what we've got
Expand All @@ -457,6 +458,9 @@ bool TurtleStreamParser<T>::resetStateAndRead(

LOG(TRACE) << "Succesfully decompressed next batch of " << nextBytes.size()
<< " << bytes to parser\n";

// important: our tokenizer may have a new position
b = backupState();
return true;
}

Expand Down Expand Up @@ -561,7 +565,7 @@ bool TurtleStreamParser<T>::getLine(std::array<string, 3>* triple) {
// we read chunks of memories in a buffered way
// try to parse with a larger buffer and repeat the reading process
// (maybe the failure was due to statements crossing our block).
if (resetStateAndRead(b)) {
if (resetStateAndRead(&b)) {
// we have succesfully extended our buffer
if (_byteVec.size() > BZIP2_MAX_TOTAL_BUFFER_SIZE) {
auto d = _tok.view();
Expand Down
3 changes: 2 additions & 1 deletion src/parser/TurtleParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class TurtleParser {
public:
ParseException() = default;
explicit ParseException(string msg) : _msg(std::move(msg)) {}

[[nodiscard]] const char* what() const noexcept override {
return _msg.c_str();
}
Expand Down Expand Up @@ -337,7 +338,7 @@ class TurtleStreamParser : public TurtleParser<Tokenizer_T> {
// Reset the parser to the state indicated by the argument
// Must be called on the same parser object that was used to create the backup
// state (the actual triples are not backed up)
bool resetStateAndRead(TurtleParserBackupState state);
bool resetStateAndRead(TurtleParserBackupState* state);

// stores the current batch of bytes we have to parse.
// Might end in the middle of a statement or even a multibyte utf8 character,
Expand Down

0 comments on commit c93e090

Please sign in to comment.