From 6d7f7486537059af47e15bffa7ca9edf91e83966 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sun, 18 Sep 2016 19:09:36 -0500 Subject: [PATCH] buffer: rename iterator copy() to copy_deep() Current callers expect a deep copy; be explicit about it. Signed-off-by: Sage Weil --- src/auth/Crypto.cc | 2 +- src/common/buffer.cc | 14 +++++++++++--- src/include/buffer.h | 4 ++-- src/include/small_encoding.h | 2 +- src/test/bufferlist.cc | 4 ++-- src/test/librados_test_stub/TestMemIoCtxImpl.cc | 2 +- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/auth/Crypto.cc b/src/auth/Crypto.cc index 5ed9e88052ece..4b758711e6a00 100644 --- a/src/auth/Crypto.cc +++ b/src/auth/Crypto.cc @@ -384,7 +384,7 @@ void CryptoKey::decode(bufferlist::iterator& bl) __u16 len; ::decode(len, bl); bufferptr tmp; - bl.copy(len, tmp); + bl.copy_deep(len, tmp); if (_set_secret(type, tmp) < 0) throw buffer::malformed_input("malformed secret"); } diff --git a/src/common/buffer.cc b/src/common/buffer.cc index f941428ec8407..c3ce4f199403f 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -1149,8 +1149,11 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; } template - void buffer::list::iterator_impl::copy(unsigned len, ptr &dest) + void buffer::list::iterator_impl::copy_deep(unsigned len, ptr &dest) { + if (p == ls->end()) + throw end_of_buffer(); + assert(p->length() > 0); dest = create(len); copy(len, dest.c_str()); } @@ -1298,9 +1301,14 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; return buffer::list::iterator_impl::copy(len, dest); } - void buffer::list::iterator::copy(unsigned len, ptr &dest) + void buffer::list::iterator::copy_deep(unsigned len, ptr &dest) { - buffer::list::iterator_impl::copy(len, dest); + buffer::list::iterator_impl::copy_deep(len, dest); + } + + void buffer::list::iterator::copy_shallow(unsigned len, ptr &dest) + { + buffer::list::iterator_impl::copy_shallow(len, dest); } void buffer::list::iterator::copy(unsigned len, list &dest) diff --git a/src/include/buffer.h b/src/include/buffer.h index ef0ccc15aefb1..6a23feca730ab 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -320,7 +320,7 @@ namespace buffer CEPH_BUFFER_API { // copy data out. // note that these all _append_ to dest! void copy(unsigned len, char *dest); - void copy(unsigned len, ptr &dest); + void copy_deep(unsigned len, ptr &dest); void copy(unsigned len, list &dest); void copy(unsigned len, std::string &dest); void copy_all(list &dest); @@ -360,7 +360,7 @@ namespace buffer CEPH_BUFFER_API { // copy data out void copy(unsigned len, char *dest); - void copy(unsigned len, ptr &dest); + void copy_deep(unsigned len, ptr &dest); void copy(unsigned len, list &dest); void copy(unsigned len, std::string &dest); void copy_all(list &dest); diff --git a/src/include/small_encoding.h b/src/include/small_encoding.h index e07afaf381e0c..874bfa2f80a65 100644 --- a/src/include/small_encoding.h +++ b/src/include/small_encoding.h @@ -251,7 +251,7 @@ template inline void small_decode_buf_lowz(T& bp, bufferlist::iterator& p) { size_t l; small_decode_varint_lowz(l, p); - p.copy(l, bp); + p.copy_deep(l, bp); } // STL containers diff --git a/src/test/bufferlist.cc b/src/test/bufferlist.cc index e67760f35066e..63f174358c3b2 100644 --- a/src/test/bufferlist.cc +++ b/src/test/bufferlist.cc @@ -1216,12 +1216,12 @@ TEST(BufferListIterator, copy) { EXPECT_EQ(0, ::memcmp(copy, expected, 3)); } // - // void buffer::list::iterator::copy(unsigned len, ptr &dest) + // void buffer::list::iterator::copy_deep(unsigned len, ptr &dest) // { bufferptr ptr; bufferlist::iterator i(&bl); - i.copy(2, ptr); + i.copy_deep(2, ptr); EXPECT_EQ((unsigned)2, ptr.length()); EXPECT_EQ('A', ptr[0]); EXPECT_EQ('B', ptr[1]); diff --git a/src/test/librados_test_stub/TestMemIoCtxImpl.cc b/src/test/librados_test_stub/TestMemIoCtxImpl.cc index 6c522e8e2aa5c..ae04c86971e96 100644 --- a/src/test/librados_test_stub/TestMemIoCtxImpl.cc +++ b/src/test/librados_test_stub/TestMemIoCtxImpl.cc @@ -550,7 +550,7 @@ void TestMemIoCtxImpl::append_clone(bufferlist& src, bufferlist* dest) { if (src.length() > 0) { bufferlist::iterator iter = src.begin(); buffer::ptr ptr; - iter.copy(src.length(), ptr); + iter.copy_deep(src.length(), ptr); dest->append(ptr); } } -- 2.39.5