Skip to content

Commit

Permalink
compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
paleolimbot committed Apr 9, 2024
1 parent 31379e8 commit a8f5880
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 84 deletions.
8 changes: 4 additions & 4 deletions dev/benchmarks/c/array_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ static void BenchmarkArrayViewGetString(benchmark::State& state) {

int64_t n_alphabets = n_values / alphabet.size() + 1;
std::vector<char> data(alphabet.size() * n_alphabets);
for (int64_t data_pos = 0; data_pos < data.size(); data_pos += alphabet.size()) {
for (size_t data_pos = 0; data_pos < data.size(); data_pos += alphabet.size()) {
memcpy(data.data() + data_pos, alphabet.data(), alphabet.size());
}

Expand Down Expand Up @@ -262,7 +262,7 @@ static ArrowErrorCode CreateAndAppendToArrayInt(ArrowArray* array,
NANOARROW_RETURN_NOT_OK(ArrowArrayInitFromType(array, type));
NANOARROW_RETURN_NOT_OK(ArrowArrayStartAppending(array));

for (int64_t i = 0; i < values.size(); i++) {
for (size_t i = 0; i < values.size(); i++) {
NANOARROW_RETURN_NOT_OK(ArrowArrayAppendInt(array, values[i]));
}

Expand Down Expand Up @@ -293,7 +293,7 @@ static void BenchmarkArrayAppendString(benchmark::State& state) {
int64_t value_size = 7;

std::vector<std::string> values(n_values);
int64_t alphabet_pos = 0;
size_t alphabet_pos = 0;
for (std::string& value : values) {
if ((alphabet_pos + value_size) >= kAlphabet.size()) {
alphabet_pos = 0;
Expand Down Expand Up @@ -361,7 +361,7 @@ static ArrowErrorCode CreateAndAppendIntWithNulls(ArrowArray* array,
NANOARROW_RETURN_NOT_OK(ArrowArrayStartAppending(array));
CType non_null_value = std::numeric_limits<CType>::max() / 2;

for (int64_t i = 0; i < validity.size(); i++) {
for (size_t i = 0; i < validity.size(); i++) {
if (validity[i]) {
NANOARROW_RETURN_NOT_OK(ArrowArrayAppendInt(array, non_null_value));
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/nanoarrow/array_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -848,9 +848,9 @@ TEST(ArrayTest, ArrayTestAppendToFixedSizeBinaryArray) {
ASSERT_EQ(ArrowArrayReserve(&array, 5), NANOARROW_OK);
EXPECT_EQ(ArrowArrayBuffer(&array, 1)->capacity_bytes, 5 * 5);

EXPECT_EQ(ArrowArrayAppendBytes(&array, {"12345", 5}), NANOARROW_OK);
EXPECT_EQ(ArrowArrayAppendBytes(&array, {{"12345"}, 5}), NANOARROW_OK);
EXPECT_EQ(ArrowArrayAppendNull(&array, 2), NANOARROW_OK);
EXPECT_EQ(ArrowArrayAppendBytes(&array, {"67890", 5}), NANOARROW_OK);
EXPECT_EQ(ArrowArrayAppendBytes(&array, {{"67890"}, 5}), NANOARROW_OK);
EXPECT_EQ(ArrowArrayAppendEmpty(&array, 1), NANOARROW_OK);
EXPECT_EQ(ArrowArrayFinishBuildingDefault(&array, nullptr), NANOARROW_OK);

Expand Down
21 changes: 12 additions & 9 deletions src/nanoarrow/buffer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
static uint8_t* TestAllocatorReallocate(struct ArrowBufferAllocator* allocator,
uint8_t* ptr, int64_t old_size,
int64_t new_size) {
NANOARROW_UNUSED(allocator);
uint8_t* new_ptr = reinterpret_cast<uint8_t*>(malloc(new_size));

int64_t copy_size = std::min<int64_t>(old_size, new_size);
Expand All @@ -45,6 +46,8 @@ static uint8_t* TestAllocatorReallocate(struct ArrowBufferAllocator* allocator,

static void TestAllocatorFree(struct ArrowBufferAllocator* allocator, uint8_t* ptr,
int64_t size) {
NANOARROW_UNUSED(allocator);
NANOARROW_UNUSED(size);
free(ptr);
}

Expand Down Expand Up @@ -188,31 +191,31 @@ TEST(BufferTest, BufferTestAppendHelpers) {
ArrowBufferReset(&buffer);

EXPECT_EQ(ArrowBufferAppendUInt8(&buffer, 123), NANOARROW_OK);
EXPECT_EQ(reinterpret_cast<uint8_t*>(buffer.data)[0], 123);
EXPECT_EQ(reinterpret_cast<uint8_t*>(buffer.data)[0], 123U);
ArrowBufferReset(&buffer);

EXPECT_EQ(ArrowBufferAppendInt16(&buffer, 123), NANOARROW_OK);
EXPECT_EQ(reinterpret_cast<int16_t*>(buffer.data)[0], 123);
ArrowBufferReset(&buffer);

EXPECT_EQ(ArrowBufferAppendUInt16(&buffer, 123), NANOARROW_OK);
EXPECT_EQ(reinterpret_cast<uint16_t*>(buffer.data)[0], 123);
EXPECT_EQ(reinterpret_cast<uint16_t*>(buffer.data)[0], 123U);
ArrowBufferReset(&buffer);

EXPECT_EQ(ArrowBufferAppendInt32(&buffer, 123), NANOARROW_OK);
EXPECT_EQ(reinterpret_cast<int32_t*>(buffer.data)[0], 123);
ArrowBufferReset(&buffer);

EXPECT_EQ(ArrowBufferAppendUInt32(&buffer, 123), NANOARROW_OK);
EXPECT_EQ(reinterpret_cast<uint32_t*>(buffer.data)[0], 123);
EXPECT_EQ(reinterpret_cast<uint32_t*>(buffer.data)[0], 123U);
ArrowBufferReset(&buffer);

EXPECT_EQ(ArrowBufferAppendInt64(&buffer, 123), NANOARROW_OK);
EXPECT_EQ(reinterpret_cast<int64_t*>(buffer.data)[0], 123);
ArrowBufferReset(&buffer);

EXPECT_EQ(ArrowBufferAppendUInt64(&buffer, 123), NANOARROW_OK);
EXPECT_EQ(reinterpret_cast<uint64_t*>(buffer.data)[0], 123);
EXPECT_EQ(reinterpret_cast<uint64_t*>(buffer.data)[0], 123U);
ArrowBufferReset(&buffer);

EXPECT_EQ(ArrowBufferAppendDouble(&buffer, 123), NANOARROW_OK);
Expand Down Expand Up @@ -241,7 +244,7 @@ TEST(BitmapTest, BitmapTestElement) {
uint8_t bitmap[10];

memset(bitmap, 0xff, sizeof(bitmap));
for (int i = 0; i < sizeof(bitmap) * 8; i++) {
for (size_t i = 0; i < sizeof(bitmap) * 8; i++) {
EXPECT_EQ(ArrowBitGet(bitmap, i), 1);
}

Expand All @@ -256,7 +259,7 @@ TEST(BitmapTest, BitmapTestElement) {
EXPECT_EQ(ArrowBitGet(bitmap, 16 + 7), 1);

memset(bitmap, 0x00, sizeof(bitmap));
for (int i = 0; i < sizeof(bitmap) * 8; i++) {
for (size_t i = 0; i < sizeof(bitmap) * 8; i++) {
EXPECT_EQ(ArrowBitGet(bitmap, i), 0);
}

Expand All @@ -271,7 +274,7 @@ TEST(BitmapTest, BitmapTestElement) {
EXPECT_EQ(ArrowBitGet(bitmap, 16 + 7), 0);
}

template <int offset, int length>
template <int offset, size_t length>
void TestArrowBitmapUnpackUnsafe(const uint8_t* bitmap, std::vector<int8_t> expected) {
int8_t out[length];
int32_t out32[length];
Expand All @@ -281,12 +284,12 @@ void TestArrowBitmapUnpackUnsafe(const uint8_t* bitmap, std::vector<int8_t> expe
ASSERT_EQ(length, expected.size());

ArrowBitsUnpackInt8(bitmap, offset, length, out);
for (int i = 0; i < length; i++) {
for (size_t i = 0; i < length; i++) {
EXPECT_EQ(out[i], expected[i]);
}

ArrowBitsUnpackInt32(bitmap, offset, length, out32);
for (int i = 0; i < length; i++) {
for (size_t i = 0; i < length; i++) {
EXPECT_EQ(out32[i], expected[i]);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/nanoarrow/integration/c_data_integration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static int64_t kBytesAllocated = 0;

static uint8_t* IntegrationTestReallocate(ArrowBufferAllocator* allocator, uint8_t* ptr,
int64_t old_size, int64_t new_size) {
NANOARROW_UNUSED(allocator);
ArrowBufferAllocator default_allocator = ArrowBufferAllocatorDefault();
kBytesAllocated -= old_size;
uint8_t* out =
Expand All @@ -41,6 +42,7 @@ static uint8_t* IntegrationTestReallocate(ArrowBufferAllocator* allocator, uint8

static void IntegrationTestFree(struct ArrowBufferAllocator* allocator, uint8_t* ptr,
int64_t size) {
NANOARROW_UNUSED(allocator);
ArrowBufferAllocator default_allocator = ArrowBufferAllocatorDefault();
kBytesAllocated -= size;
default_allocator.free(&default_allocator, ptr, size);
Expand Down
2 changes: 2 additions & 0 deletions src/nanoarrow/nanoarrow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ class Unique {
template <typename T>
static inline void DeallocateWrappedBuffer(struct ArrowBufferAllocator* allocator,
uint8_t* ptr, int64_t size) {
NANOARROW_UNUSED(ptr);
NANOARROW_UNUSED(size);
auto obj = reinterpret_cast<T*>(allocator->private_data);
delete obj;
}
Expand Down
22 changes: 13 additions & 9 deletions src/nanoarrow/nanoarrow_testing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ class TestingJSONReader {
} else if (num_batch == kNumBatchReadAll) {
batch_ids.resize(batches.size());
std::iota(batch_ids.begin(), batch_ids.end(), 0);
} else if (num_batch >= 0 && num_batch < batches.size()) {
} else if (num_batch >= 0 && static_cast<size_t>(num_batch) < batches.size()) {
batch_ids.push_back(num_batch);
} else {
ArrowErrorSet(error, "Expected num_batch between 0 and %d but got %d",
Expand Down Expand Up @@ -1887,8 +1887,9 @@ class TestingJSONReader {
const auto& columns = value["columns"];
NANOARROW_RETURN_NOT_OK(
Check(columns.is_array(), error, "RecordBatch columns must be array"));
NANOARROW_RETURN_NOT_OK(Check(columns.size() == array_view->n_children, error,
"RecordBatch children has incorrect size"));
NANOARROW_RETURN_NOT_OK(
Check(columns.size() == static_cast<size_t>(array_view->n_children), error,
"RecordBatch children has incorrect size"));

for (int64_t i = 0; i < array_view->n_children; i++) {
NANOARROW_RETURN_NOT_OK(SetArrayColumn(columns[i], schema->children[i],
Expand Down Expand Up @@ -1987,8 +1988,9 @@ class TestingJSONReader {
const auto& children = value["children"];
NANOARROW_RETURN_NOT_OK(
Check(children.is_array(), error, error_prefix + "children must be array"));
NANOARROW_RETURN_NOT_OK(Check(children.size() == array_view->n_children, error,
error_prefix + "children has incorrect size"));
NANOARROW_RETURN_NOT_OK(
Check(children.size() == static_cast<size_t>(array_view->n_children), error,
error_prefix + "children has incorrect size"));

for (int64_t i = 0; i < array_view->n_children; i++) {
NANOARROW_RETURN_NOT_OK(SetArrayColumn(children[i], schema->children[i],
Expand Down Expand Up @@ -2272,7 +2274,8 @@ class TestingJSONReader {
// Check offsets against values
const T* expected_offset = reinterpret_cast<const T*>(offsets->data);
NANOARROW_RETURN_NOT_OK(Check(
offsets->size_bytes == ((value.size() + 1) * sizeof(T)), error,
static_cast<size_t>(offsets->size_bytes) == ((value.size() + 1) * sizeof(T)),
error,
"Expected offset buffer with " + std::to_string(value.size()) + " elements"));
NANOARROW_RETURN_NOT_OK(
Check(*expected_offset++ == 0, error, "first offset must be zero"));
Expand Down Expand Up @@ -2310,7 +2313,8 @@ class TestingJSONReader {
// Check offsets against values if not fixed size
const T* expected_offset = reinterpret_cast<const T*>(offsets->data);
NANOARROW_RETURN_NOT_OK(Check(
offsets->size_bytes == ((value.size() + 1) * sizeof(T)), error,
static_cast<size_t>(offsets->size_bytes) == ((value.size() + 1) * sizeof(T)),
error,
"Expected offset buffer with " + std::to_string(value.size()) + " elements"));
NANOARROW_RETURN_NOT_OK(
Check(*expected_offset++ == 0, error, "first offset must be zero"));
Expand Down Expand Up @@ -2355,7 +2359,7 @@ class TestingJSONReader {
Check(item.is_string(), error, "binary data buffer item must be string"));
auto item_str = item.get<std::string>();

int64_t item_size_bytes = item_str.size() / 2;
size_t item_size_bytes = item_str.size() / 2;
NANOARROW_RETURN_NOT_OK(Check((item_size_bytes * 2) == item_str.size(), error,
"binary data buffer item must have even size"));

Expand Down Expand Up @@ -2502,7 +2506,7 @@ class TestingJSONComparison {

public:
/// \brief Returns the number of differences found by the previous call
size_t num_differences() const { return differences_.size(); }
int64_t num_differences() const { return differences_.size(); }

/// \brief Dump a human-readable summary of differences to out
void WriteDifferences(std::ostream& out) {
Expand Down
Loading

0 comments on commit a8f5880

Please sign in to comment.