Skip to content

Commit

Permalink
ARROW-1134: [C++] Support for C++/CLI compilation, add NULLPTR define…
Browse files Browse the repository at this point in the history
… to avoid using nullptr in public headers

cc @TobyShaw. Can you test this?

Close #1098

Author: Wes McKinney <wes.mckinney@twosigma.com>

Closes #1228 from wesm/ARROW-1134 and squashes the following commits:

bf18158 [Wes McKinney] Only define NULLPTR if not already defined
a51dd88 [Wes McKinney] Add NULLPTR macro to avoid using nullptr in public headers for C++/CLI users
  • Loading branch information
wesm committed Oct 25, 2017
1 parent b08f7e3 commit ecb7605
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 65 deletions.
5 changes: 3 additions & 2 deletions cpp/src/arrow/allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "arrow/memory_pool.h"
#include "arrow/status.h"
#include "arrow/util/macros.h"

namespace arrow {

Expand All @@ -49,13 +50,13 @@ class stl_allocator {
template <class U>
stl_allocator(const stl_allocator<U>& rhs) noexcept : pool_(rhs.pool_) {}

~stl_allocator() { pool_ = nullptr; }
~stl_allocator() { pool_ = NULLPTR; }

pointer address(reference r) const noexcept { return std::addressof(r); }

const_pointer address(const_reference r) const noexcept { return std::addressof(r); }

pointer allocate(size_type n, const void* /*hint*/ = nullptr) {
pointer allocate(size_type n, const void* /*hint*/ = NULLPTR) {
uint8_t* data;
Status s = pool_->Allocate(n * sizeof(T), &data);
if (!s.ok()) throw std::bad_alloc();
Expand Down
36 changes: 18 additions & 18 deletions cpp/src/arrow/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ class ARROW_EXPORT Array {

/// \brief Return true if value at index is null. Does not boundscheck
bool IsNull(int64_t i) const {
return null_bitmap_data_ != nullptr &&
return null_bitmap_data_ != NULLPTR &&
BitUtil::BitNotSet(null_bitmap_data_, i + data_->offset);
}

/// \brief Return true if value at index is valid (not null). Does not
/// boundscheck
bool IsValid(int64_t i) const {
return null_bitmap_data_ != nullptr &&
return null_bitmap_data_ != NULLPTR &&
BitUtil::GetBit(null_bitmap_data_, i + data_->offset);
}

Expand All @@ -212,13 +212,13 @@ class ARROW_EXPORT Array {

/// Buffer for the null bitmap.
///
/// Note that for `null_count == 0`, this can be a `nullptr`.
/// Note that for `null_count == 0`, this can be null.
/// This buffer does not account for any slice offset
std::shared_ptr<Buffer> null_bitmap() const { return data_->buffers[0]; }

/// Raw pointer to the null bitmap.
///
/// Note that for `null_count == 0`, this can be a `nullptr`.
/// Note that for `null_count == 0`, this can be null.
/// This buffer does not account for any slice offset
const uint8_t* null_bitmap_data() const { return null_bitmap_data_; }

Expand Down Expand Up @@ -270,7 +270,7 @@ class ARROW_EXPORT Array {
if (data->buffers.size() > 0 && data->buffers[0]) {
null_bitmap_data_ = data->buffers[0]->data();
} else {
null_bitmap_data_ = nullptr;
null_bitmap_data_ = NULLPTR;
}
data_ = data;
}
Expand Down Expand Up @@ -299,7 +299,7 @@ class ARROW_EXPORT NullArray : public FlatArray {

private:
inline void SetData(const std::shared_ptr<ArrayData>& data) {
null_bitmap_data_ = nullptr;
null_bitmap_data_ = NULLPTR;
data->null_count = data->length;
data_ = data;
}
Expand All @@ -310,7 +310,7 @@ class ARROW_EXPORT PrimitiveArray : public FlatArray {
public:
PrimitiveArray(const std::shared_ptr<DataType>& type, int64_t length,
const std::shared_ptr<Buffer>& data,
const std::shared_ptr<Buffer>& null_bitmap = nullptr,
const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
int64_t null_count = 0, int64_t offset = 0);

/// Does not account for any slice offset
Expand All @@ -325,7 +325,7 @@ class ARROW_EXPORT PrimitiveArray : public FlatArray {
inline void SetData(const std::shared_ptr<ArrayData>& data) {
auto values = data->buffers[1];
this->Array::SetData(data);
raw_values_ = values == nullptr ? nullptr : values->data();
raw_values_ = values == NULLPTR ? NULLPTR : values->data();
}

explicit inline PrimitiveArray(const std::shared_ptr<ArrayData>& data) {
Expand All @@ -349,7 +349,7 @@ class ARROW_EXPORT NumericArray : public PrimitiveArray {
NumericArray(
typename std::enable_if<TypeTraits<T1>::is_parameter_free, int64_t>::type length,
const std::shared_ptr<Buffer>& data,
const std::shared_ptr<Buffer>& null_bitmap = nullptr, int64_t null_count = 0,
const std::shared_ptr<Buffer>& null_bitmap = NULLPTR, int64_t null_count = 0,
int64_t offset = 0)
: PrimitiveArray(TypeTraits<T1>::type_singleton(), length, data, null_bitmap,
null_count, offset) {}
Expand All @@ -371,7 +371,7 @@ class ARROW_EXPORT BooleanArray : public PrimitiveArray {
explicit BooleanArray(const std::shared_ptr<ArrayData>& data);

BooleanArray(int64_t length, const std::shared_ptr<Buffer>& data,
const std::shared_ptr<Buffer>& null_bitmap = nullptr,
const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
int64_t null_count = 0, int64_t offset = 0);

bool Value(int64_t i) const {
Expand All @@ -395,7 +395,7 @@ class ARROW_EXPORT ListArray : public Array {
ListArray(const std::shared_ptr<DataType>& type, int64_t length,
const std::shared_ptr<Buffer>& value_offsets,
const std::shared_ptr<Array>& values,
const std::shared_ptr<Buffer>& null_bitmap = nullptr, int64_t null_count = 0,
const std::shared_ptr<Buffer>& null_bitmap = NULLPTR, int64_t null_count = 0,
int64_t offset = 0);

/// \brief Construct ListArray from array of offsets and child value array
Expand Down Expand Up @@ -451,7 +451,7 @@ class ARROW_EXPORT BinaryArray : public FlatArray {

BinaryArray(int64_t length, const std::shared_ptr<Buffer>& value_offsets,
const std::shared_ptr<Buffer>& data,
const std::shared_ptr<Buffer>& null_bitmap = nullptr,
const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
int64_t null_count = 0, int64_t offset = 0);

// Return the pointer to the given elements bytes
Expand Down Expand Up @@ -503,7 +503,7 @@ class ARROW_EXPORT BinaryArray : public FlatArray {
BinaryArray(const std::shared_ptr<DataType>& type, int64_t length,
const std::shared_ptr<Buffer>& value_offsets,
const std::shared_ptr<Buffer>& data,
const std::shared_ptr<Buffer>& null_bitmap = nullptr,
const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
int64_t null_count = 0, int64_t offset = 0);

const int32_t* raw_value_offsets_;
Expand All @@ -518,7 +518,7 @@ class ARROW_EXPORT StringArray : public BinaryArray {

StringArray(int64_t length, const std::shared_ptr<Buffer>& value_offsets,
const std::shared_ptr<Buffer>& data,
const std::shared_ptr<Buffer>& null_bitmap = nullptr,
const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
int64_t null_count = 0, int64_t offset = 0);

// Construct a std::string
Expand All @@ -541,7 +541,7 @@ class ARROW_EXPORT FixedSizeBinaryArray : public PrimitiveArray {

FixedSizeBinaryArray(const std::shared_ptr<DataType>& type, int64_t length,
const std::shared_ptr<Buffer>& data,
const std::shared_ptr<Buffer>& null_bitmap = nullptr,
const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
int64_t null_count = 0, int64_t offset = 0);

const uint8_t* GetValue(int64_t i) const;
Expand Down Expand Up @@ -583,7 +583,7 @@ class ARROW_EXPORT StructArray : public Array {

StructArray(const std::shared_ptr<DataType>& type, int64_t length,
const std::vector<std::shared_ptr<Array>>& children,
std::shared_ptr<Buffer> null_bitmap = nullptr, int64_t null_count = 0,
std::shared_ptr<Buffer> null_bitmap = NULLPTR, int64_t null_count = 0,
int64_t offset = 0);

// Return a shared pointer in case the requestor desires to share ownership
Expand All @@ -608,8 +608,8 @@ class ARROW_EXPORT UnionArray : public Array {
UnionArray(const std::shared_ptr<DataType>& type, int64_t length,
const std::vector<std::shared_ptr<Array>>& children,
const std::shared_ptr<Buffer>& type_ids,
const std::shared_ptr<Buffer>& value_offsets = nullptr,
const std::shared_ptr<Buffer>& null_bitmap = nullptr, int64_t null_count = 0,
const std::shared_ptr<Buffer>& value_offsets = NULLPTR,
const std::shared_ptr<Buffer>& null_bitmap = NULLPTR, int64_t null_count = 0,
int64_t offset = 0);

/// Note that this buffer does not account for any slice offset
Expand Down
12 changes: 6 additions & 6 deletions cpp/src/arrow/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class ARROW_EXPORT Buffer {
int64_t size_;
int64_t capacity_;

// nullptr by default, but may be set
// null by default, but may be set
std::shared_ptr<Buffer> parent_;

private:
Expand Down Expand Up @@ -145,7 +145,7 @@ class ARROW_EXPORT MutableBuffer : public Buffer {
const int64_t size);

protected:
MutableBuffer() : Buffer(nullptr, 0) {}
MutableBuffer() : Buffer(NULLPTR, 0) {}
};

class ARROW_EXPORT ResizableBuffer : public MutableBuffer {
Expand Down Expand Up @@ -180,7 +180,7 @@ class ARROW_EXPORT ResizableBuffer : public MutableBuffer {
/// A Buffer whose lifetime is tied to a particular MemoryPool
class ARROW_EXPORT PoolBuffer : public ResizableBuffer {
public:
explicit PoolBuffer(MemoryPool* pool = nullptr);
explicit PoolBuffer(MemoryPool* pool = NULLPTR);
virtual ~PoolBuffer();

Status Resize(const int64_t new_size, bool shrink_to_fit = true) override;
Expand All @@ -193,15 +193,15 @@ class ARROW_EXPORT PoolBuffer : public ResizableBuffer {
class ARROW_EXPORT BufferBuilder {
public:
explicit BufferBuilder(MemoryPool* pool)
: pool_(pool), data_(nullptr), capacity_(0), size_(0) {}
: pool_(pool), data_(NULLPTR), capacity_(0), size_(0) {}

/// Resizes the buffer to the nearest multiple of 64 bytes per Layout.md
Status Resize(const int64_t elements) {
// Resize(0) is a no-op
if (elements == 0) {
return Status::OK();
}
if (buffer_ == nullptr) {
if (buffer_ == NULLPTR) {
buffer_ = std::make_shared<PoolBuffer>(pool_);
}
int64_t old_capacity = capacity_;
Expand Down Expand Up @@ -264,7 +264,7 @@ class ARROW_EXPORT BufferBuilder {
}

void Reset() {
buffer_ = nullptr;
buffer_ = NULLPTR;
capacity_ = size_ = 0;
}

Expand Down
20 changes: 10 additions & 10 deletions cpp/src/arrow/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ class ARROW_EXPORT ArrayBuilder {
explicit ArrayBuilder(const std::shared_ptr<DataType>& type, MemoryPool* pool)
: type_(type),
pool_(pool),
null_bitmap_(nullptr),
null_bitmap_(NULLPTR),
null_count_(0),
null_bitmap_data_(nullptr),
null_bitmap_data_(NULLPTR),
length_(0),
capacity_(0) {}

Expand Down Expand Up @@ -188,7 +188,7 @@ class ARROW_EXPORT PrimitiveBuilder : public ArrayBuilder {
using value_type = typename Type::c_type;

explicit PrimitiveBuilder(const std::shared_ptr<DataType>& type, MemoryPool* pool)
: ArrayBuilder(type, pool), data_(nullptr), raw_data_(nullptr) {}
: ArrayBuilder(type, pool), data_(NULLPTR), raw_data_(NULLPTR) {}

using ArrayBuilder::Advance;

Expand All @@ -214,7 +214,7 @@ class ARROW_EXPORT PrimitiveBuilder : public ArrayBuilder {
/// indicates a valid (non-null) value
/// \return Status
Status Append(const value_type* values, int64_t length,
const uint8_t* valid_bytes = nullptr);
const uint8_t* valid_bytes = NULLPTR);

/// \brief Append a sequence of elements in one shot
/// \param[in] values a contiguous C array of values
Expand Down Expand Up @@ -430,7 +430,7 @@ class ARROW_EXPORT AdaptiveUIntBuilder : public internal::AdaptiveIntBuilderBase
/// indicates a valid (non-null) value
/// \return Status
Status Append(const uint64_t* values, int64_t length,
const uint8_t* valid_bytes = nullptr);
const uint8_t* valid_bytes = NULLPTR);

Status FinishInternal(std::shared_ptr<ArrayData>* out) override;

Expand Down Expand Up @@ -492,7 +492,7 @@ class ARROW_EXPORT AdaptiveIntBuilder : public internal::AdaptiveIntBuilderBase
/// indicates a valid (non-null) value
/// \return Status
Status Append(const int64_t* values, int64_t length,
const uint8_t* valid_bytes = nullptr);
const uint8_t* valid_bytes = NULLPTR);

Status FinishInternal(std::shared_ptr<ArrayData>* out) override;

Expand Down Expand Up @@ -557,7 +557,7 @@ class ARROW_EXPORT BooleanBuilder : public ArrayBuilder {
/// indicates a valid (non-null) value
/// \return Status
Status Append(const uint8_t* values, int64_t length,
const uint8_t* valid_bytes = nullptr);
const uint8_t* valid_bytes = NULLPTR);

/// \brief Append a sequence of elements in one shot
/// \param[in] values a contiguous C array of values
Expand Down Expand Up @@ -624,7 +624,7 @@ class ARROW_EXPORT ListBuilder : public ArrayBuilder {
/// Use this constructor to incrementally build the value array along with offsets and
/// null bitmap.
ListBuilder(MemoryPool* pool, std::unique_ptr<ArrayBuilder> value_builder,
const std::shared_ptr<DataType>& type = nullptr);
const std::shared_ptr<DataType>& type = NULLPTR);

Status Init(int64_t elements) override;
Status Resize(int64_t capacity) override;
Expand All @@ -635,7 +635,7 @@ class ARROW_EXPORT ListBuilder : public ArrayBuilder {
/// If passed, valid_bytes is of equal length to values, and any zero byte
/// will be considered as a null for that slot
Status Append(const int32_t* offsets, int64_t length,
const uint8_t* valid_bytes = nullptr);
const uint8_t* valid_bytes = NULLPTR);

/// \brief Start a new variable-length list slot
///
Expand Down Expand Up @@ -732,7 +732,7 @@ class ARROW_EXPORT FixedSizeBinaryBuilder : public ArrayBuilder {
}

Status Append(const uint8_t* data, int64_t length,
const uint8_t* valid_bytes = nullptr);
const uint8_t* valid_bytes = NULLPTR);
Status Append(const std::string& value);
Status AppendNull();

Expand Down
6 changes: 3 additions & 3 deletions cpp/src/arrow/io/hdfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ class ARROW_EXPORT HadoopFileSystem : public FileSystem {
/// Change
///
/// @param path file path to change
/// @param owner pass nullptr for no change
/// @param group pass nullptr for no change
/// @param owner pass null for no change
/// @param group pass null for no change
Status Chown(const std::string& path, const char* owner, const char* group);

/// Change path permissions
Expand Down Expand Up @@ -199,7 +199,7 @@ class ARROW_EXPORT HdfsReadableFile : public RandomAccessFile {
void set_memory_pool(MemoryPool* pool);

private:
explicit HdfsReadableFile(MemoryPool* pool = nullptr);
explicit HdfsReadableFile(MemoryPool* pool = NULLPTR);

class ARROW_NO_EXPORT HdfsReadableFileImpl;
std::unique_ptr<HdfsReadableFileImpl> impl_;
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/arrow/ipc/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ARROW_EXPORT Message {
/// \brief Create and validate a Message instance from two buffers
///
/// \param[in] metadata a buffer containing the Flatbuffer metadata
/// \param[in] body a buffer containing the message body, which may be nullptr
/// \param[in] body a buffer containing the message body, which may be null
/// \param[out] out the created message
/// \return Status
static Status Open(const std::shared_ptr<Buffer>& metadata,
Expand Down Expand Up @@ -98,7 +98,7 @@ class ARROW_EXPORT Message {

/// \brief the Message body, if any
///
/// \return buffer is nullptr if no body
/// \return buffer is null if no body
std::shared_ptr<Buffer> body() const;

/// \brief The Message type
Expand Down Expand Up @@ -179,7 +179,7 @@ Status ReadMessage(const int64_t offset, const int32_t metadata_length,

/// \brief Read encapulated RPC message (metadata and body) from InputStream
///
/// Read length-prefixed message with as-yet unknown length. Returns nullptr if
/// Read length-prefixed message with as-yet unknown length. Returns null if
/// there are not enough bytes available or the message length is 0 (e.g. EOS
/// in a stream)
ARROW_EXPORT
Expand Down
Loading

0 comments on commit ecb7605

Please sign in to comment.