This is an automated email from the ASF dual-hosted git repository.
wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 8167472 ARROW-2275: [C++] Guard against bad use of
Buffer.mutable_data()
8167472 is described below
commit 816747208c31625f9b198ab3d29c2c3185ba3c25
Author: Antoine Pitrou <[email protected]>
AuthorDate: Fri Mar 9 10:24:15 2018 -0500
ARROW-2275: [C++] Guard against bad use of Buffer.mutable_data()
Also disambiguate the Tensor API on this front.
Author: Antoine Pitrou <[email protected]>
Closes #1717 from pitrou/ARROW-2275-bad-mutable-data and squashes the
following commits:
fabd7b9f <Antoine Pitrou> ARROW-2275: Guard against bad use of
Buffer.mutable_data()
---
cpp/src/arrow/buffer.cc | 8 ++++++++
cpp/src/arrow/buffer.h | 10 +++++++++-
cpp/src/arrow/tensor.h | 2 +-
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/cpp/src/arrow/buffer.cc b/cpp/src/arrow/buffer.cc
index 29e2c24..e32e02c 100644
--- a/cpp/src/arrow/buffer.cc
+++ b/cpp/src/arrow/buffer.cc
@@ -70,6 +70,14 @@ Status Buffer::FromString(const std::string& data,
std::shared_ptr<Buffer>* out)
return FromString(data, default_memory_pool(), out);
}
+#ifndef NDEBUG
+// DCHECK macros aren't allowed in public include files
+uint8_t* Buffer::mutable_data() {
+ DCHECK(is_mutable());
+ return mutable_data_;
+}
+#endif
+
PoolBuffer::PoolBuffer(MemoryPool* pool) : ResizableBuffer(nullptr, 0) {
if (pool == nullptr) {
pool = default_memory_pool();
diff --git a/cpp/src/arrow/buffer.h b/cpp/src/arrow/buffer.h
index cf25ccd..ad11ff9 100644
--- a/cpp/src/arrow/buffer.h
+++ b/cpp/src/arrow/buffer.h
@@ -54,7 +54,11 @@ class ARROW_EXPORT Buffer {
///
/// \note The passed memory must be kept alive through some other means
Buffer(const uint8_t* data, int64_t size)
- : is_mutable_(false), data_(data), size_(size), capacity_(size) {}
+ : is_mutable_(false),
+ data_(data),
+ mutable_data_(NULLPTR),
+ size_(size),
+ capacity_(size) {}
/// \brief Construct from std::string without copying memory
///
@@ -113,7 +117,11 @@ class ARROW_EXPORT Buffer {
int64_t capacity() const { return capacity_; }
const uint8_t* data() const { return data_; }
+#ifdef NDEBUG
uint8_t* mutable_data() { return mutable_data_; }
+#else
+ uint8_t* mutable_data();
+#endif
int64_t size() const { return size_; }
diff --git a/cpp/src/arrow/tensor.h b/cpp/src/arrow/tensor.h
index 4e4c6b8..699dc03 100644
--- a/cpp/src/arrow/tensor.h
+++ b/cpp/src/arrow/tensor.h
@@ -71,7 +71,7 @@ class ARROW_EXPORT Tensor {
std::shared_ptr<Buffer> data() const { return data_; }
const uint8_t* raw_data() const { return data_->data(); }
- uint8_t* raw_data() { return data_->mutable_data(); }
+ uint8_t* raw_mutable_data() { return data_->mutable_data(); }
const std::vector<int64_t>& shape() const { return shape_; }
const std::vector<int64_t>& strides() const { return strides_; }
--
To stop receiving notification emails like this one, please contact
[email protected].