From d29e471f1db2b53d135427c74dcaa0f7cb198dc6 Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Fri, 5 Mar 2021 14:33:01 -0500 Subject: [PATCH] Fix small bug in StreamBuffer --- luprex/core/cpp/luasnap.cpp | 1 + luprex/core/cpp/streambuffer.cpp | 10 +++++----- luprex/core/cpp/streambuffer.hpp | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/luprex/core/cpp/luasnap.cpp b/luprex/core/cpp/luasnap.cpp index 6c30cde9..d745b5a3 100644 --- a/luprex/core/cpp/luasnap.cpp +++ b/luprex/core/cpp/luasnap.cpp @@ -134,6 +134,7 @@ void LuaSnap::snapshot() { void LuaSnap::rollback() { assert(snapshot_.write_count() != 0); deserialize(&snapshot_); + assert(snapshot_.at_eof()); snapshot_.clear(); } diff --git a/luprex/core/cpp/streambuffer.cpp b/luprex/core/cpp/streambuffer.cpp index a64a5791..d3551627 100644 --- a/luprex/core/cpp/streambuffer.cpp +++ b/luprex/core/cpp/streambuffer.cpp @@ -54,6 +54,11 @@ void StreamBuffer::make_space_slow(int64_t bytes) { int64_t existing_size = (buf_hi_ - buf_lo_); int64_t desired_size = 8192 + ((data_size + bytes) * 2); + // Update some simple things. + pre_read_count_ += (read_cursor_ - buf_lo_); + lua_reader_data_ = 0; + lua_reader_size_ = 0; + // Move the data to the beginning of the buffer, or to // the beginning of a new buffer. if (fixed_size_) { @@ -70,13 +75,8 @@ void StreamBuffer::make_space_slow(int64_t bytes) { } // Update the pointers to the data region. - pre_read_count_ += (read_cursor_ - buf_lo_); read_cursor_ = buf_lo_; write_cursor_ = buf_lo_ + data_size; - - // Flush the lua reader data, if any. - lua_reader_data_ = 0; - lua_reader_size_ = 0; } char *StreamBuffer::get_overwrite(int64_t size, int64_t write_count_after) { diff --git a/luprex/core/cpp/streambuffer.hpp b/luprex/core/cpp/streambuffer.hpp index 8467f4bf..2c671995 100644 --- a/luprex/core/cpp/streambuffer.hpp +++ b/luprex/core/cpp/streambuffer.hpp @@ -344,7 +344,7 @@ public: // Rewind the read cursor to a previous position. void unread_to(int64_t read_count); - + // Use the stream buffer as a lua_Writer. static int lua_writer(lua_State *L, const void* p, size_t sz, void* ud); void *lua_writer_ud();