Skip to content

Commit

Permalink
[FIX] libc++: tellg invalidates I/O buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Nov 12, 2023
1 parent 6948b70 commit 285f8e8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
8 changes: 5 additions & 3 deletions include/seqan3/io/sequence_file/format_embl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ class format_embl
id_type & id,
qual_type & SEQAN3_DOXYGEN_ONLY(qualities))
{
// Store current position in buffer
// Must happen before construction the view.
// With libc++, tellg invalidates the I/O buffer.
position_buffer = stream.tellg();

auto stream_view = detail::istreambuf(stream);
auto stream_it = std::ranges::begin(stream_view);

// Store current position in buffer.
position_buffer = stream.tellg();

std::string idbuffer;
std::ranges::copy(stream_view | detail::take_until_or_throw(is_cntrl || is_blank),
std::back_inserter(idbuffer));
Expand Down
6 changes: 4 additions & 2 deletions include/seqan3/io/sequence_file/format_fasta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,13 @@ class format_fasta
id_type & id,
qual_type & SEQAN3_DOXYGEN_ONLY(qualities))
{
auto stream_view = detail::istreambuf(stream);

// Store current position in buffer
// Must happen before construction the view.
// With libc++, tellg invalidates the I/O buffer.
position_buffer = stream.tellg();

auto stream_view = detail::istreambuf(stream);

// ID
read_id(stream_view, options, id);

Expand Down
6 changes: 5 additions & 1 deletion include/seqan3/io/sequence_file/format_fastq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ class format_fastq
id_type & id,
qual_type & qualities)
{
// Store current position in buffer
// Must happen before construction the view.
// With libc++, tellg invalidates the I/O buffer.
position_buffer = stream.tellg();

auto stream_view = detail::istreambuf(stream);
auto stream_it = std::ranges::begin(stream_view);

Expand All @@ -117,7 +122,6 @@ class format_fastq
size_t sequence_size_after = 0;
if constexpr (!detail::decays_to_ignore_v<seq_type>)
sequence_size_before = size(sequence);
position_buffer = stream.tellg();

/* ID */
if (*stream_it != '@') // [[unlikely]]
Expand Down
8 changes: 5 additions & 3 deletions include/seqan3/io/sequence_file/format_genbank.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@ class format_genbank
id_type & id,
qual_type & SEQAN3_DOXYGEN_ONLY(qualities))
{
// Store current position in buffer
// Must happen before construction the view.
// With libc++, tellg invalidates the I/O buffer.
position_buffer = stream.tellg();

auto stream_view = detail::istreambuf(stream);
auto stream_it = std::ranges::begin(stream_view);

// Store current position in buffer.
position_buffer = stream.tellg();

if (!(std::ranges::equal(stream_view | detail::take_until_or_throw(is_cntrl || is_blank),
std::string{"LOCUS"})))
throw parse_error{"An entry has to start with the code word LOCUS."};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ class fast_istreambuf_iterator
reference operator*() const
{
assert(stream_buf != nullptr);
assert(stream_buf->gptr() != stream_buf->egptr());
return *stream_buf->gptr();
}

Expand Down

0 comments on commit 285f8e8

Please sign in to comment.