This is an automated email from the ASF dual-hosted git repository.
silver pushed a commit to branch cpp-more-operation
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
The following commit(s) were added to refs/heads/cpp-more-operation by this
push:
new eddee4487 fix missing consume in seek function
eddee4487 is described below
commit eddee44870d21763e504af989c5335a0cc3e7367
Author: silver-ymz <[email protected]>
AuthorDate: Sun Sep 3 23:39:29 2023 +0800
fix missing consume in seek function
Signed-off-by: silver-ymz <[email protected]>
---
bindings/cpp/src/opendal.cpp | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/bindings/cpp/src/opendal.cpp b/bindings/cpp/src/opendal.cpp
index 21be52758..6f545a3b3 100644
--- a/bindings/cpp/src/opendal.cpp
+++ b/bindings/cpp/src/opendal.cpp
@@ -93,6 +93,12 @@ ReaderStream Operator::reader(std::string_view path) {
// Reader
+// Development Note:
+// Because rust side can't get current pointer info of c++, sowe delay the
+// `consume` operation to the next `fill_buf`. Please pay attention to call
+// `consume` and update c++ pointers before each `seek` and `fill_buf`
+// operation.
+
ffi::SeekDir to_rust_seek_dir(std::ios_base::seekdir dir);
ReaderStreamBuf::pos_type
@@ -103,6 +109,11 @@ ReaderStreamBuf::seekoff(ReaderStreamBuf::off_type off,
return -1;
}
+ if (gptr() != nullptr) {
+ reader_->consume(gptr() - eback());
+ setg(gptr(), gptr(), egptr());
+ }
+
if (dir == std::ios_base::cur) {
off += gptr() - eback();
}
@@ -127,6 +138,7 @@ ReaderStreamBuf::seekpos(ReaderStreamBuf::pos_type pos,
ReaderStreamBuf::int_type ReaderStreamBuf::underflow() {
if (gptr() != nullptr) {
reader_->consume(gptr() - eback());
+ setg(gptr(), gptr(), egptr());
}
auto buffer = reader_->fill_buf();
auto gbeg = (char *)(buffer.data());