Skip to content

Commit

Permalink
apacheGH-38090: [C++][Emscripten] compute/kernels/scalar: Suppress sh…
Browse files Browse the repository at this point in the history
…orten-64-to-32 warnings

We need explicit cast to use `int64_t` for `size_t` on Emscripten.

Explicit casts.
  • Loading branch information
kou committed Oct 6, 2023
1 parent 3697bcd commit 97d738c
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 22 deletions.
3 changes: 2 additions & 1 deletion cpp/src/arrow/compute/kernels/scalar_cast_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ struct CastPrimitive<OutType, InType, enable_if_t<std::is_same<OutType, InType>:
// memcpy output
static void Exec(const ArraySpan& arr, ArraySpan* out) {
using T = typename InType::c_type;
std::memcpy(out->GetValues<T>(1), arr.GetValues<T>(1), arr.length * sizeof(T));
std::memcpy(out->GetValues<T>(1), arr.GetValues<T>(1),
static_cast<size_t>(arr.length) * sizeof(T));
}
};

Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/compute/kernels/scalar_cast_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ Status CastBinaryToBinaryOffsets<int32_t, int64_t>(KernelContext* ctx,
output->buffers[1],
ctx->Allocate((output->length + output->offset + 1) * sizeof(output_offset_type)));
memset(output->buffers[1]->mutable_data(), 0,
output->offset * sizeof(output_offset_type));
static_cast<size_t>(output->offset) * sizeof(output_offset_type));
::arrow::internal::CastInts(input.GetValues<input_offset_type>(1),
output->GetMutableValues<output_offset_type>(1),
output->length + 1);
Expand Down Expand Up @@ -275,7 +275,7 @@ Status CastBinaryToBinaryOffsets<int64_t, int32_t>(KernelContext* ctx,
ctx->Allocate((output->length + output->offset + 1) *
sizeof(output_offset_type)));
memset(output->buffers[1]->mutable_data(), 0,
output->offset * sizeof(output_offset_type));
static_cast<size_t>(output->offset) * sizeof(output_offset_type));
::arrow::internal::CastInts(input_offsets,
output->GetMutableValues<output_offset_type>(1),
output->length + 1);
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/compute/kernels/scalar_compare.cc
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ struct BinaryScalarMinMax {
bit_util::GetBit(array.buffers[0].data, array.offset + row)) {
const auto offsets = array.GetValues<offset_type>(1);
const auto data = array.GetValues<uint8_t>(2, /*absolute_offset=*/0);
const int64_t length = offsets[row + 1] - offsets[row];
const auto length = static_cast<size_t>(offsets[row + 1] - offsets[row]);
visit_value(
string_view(reinterpret_cast<const char*>(data + offsets[row]), length));
} else if (!options.skip_nulls) {
Expand Down
7 changes: 4 additions & 3 deletions cpp/src/arrow/compute/kernels/scalar_set_lookup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ struct SetLookupState : public SetLookupStateBase {
this->null_matching_behavior = options.GetNullMatchingBehavior();
if (options.value_set.is_array()) {
const ArrayData& value_set = *options.value_set.array();
memo_index_to_value_index.reserve(value_set.length);
memo_index_to_value_index.reserve(static_cast<size_t>(value_set.length));
lookup_table =
MemoTable(memory_pool,
::arrow::internal::HashTable<char>::kLoadFactor * value_set.length);
RETURN_NOT_OK(AddArrayValueSet(options, *options.value_set.array()));
} else if (options.value_set.kind() == Datum::CHUNKED_ARRAY) {
const ChunkedArray& value_set = *options.value_set.chunked_array();
memo_index_to_value_index.reserve(value_set.length());
memo_index_to_value_index.reserve(static_cast<size_t>(value_set.length()));
lookup_table =
MemoTable(memory_pool,
::arrow::internal::HashTable<char>::kLoadFactor * value_set.length());
Expand Down Expand Up @@ -290,7 +290,8 @@ struct IndexInVisitor {

// Set all values to 0, which will be unmasked only if null is in the value_set
// and null_matching_behavior is equal to MATCH
std::memset(out->GetValues<int32_t>(1), 0x00, out->length * sizeof(int32_t));
std::memset(out->GetValues<int32_t>(1), 0x00,
static_cast<size_t>(out->length) * sizeof(int32_t));
}
return Status::OK();
}
Expand Down
27 changes: 15 additions & 12 deletions cpp/src/arrow/compute/kernels/scalar_string_ascii.cc
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ Status StringDataTransform(KernelContext* ctx, const ExecSpan& batch,
} else {
RETURN_NOT_OK(ctx->Allocate(offset_nbytes).Value(&out_arr->buffers[1]));
std::memcpy(out_arr->buffers[1]->mutable_data(), input.buffers[1].data,
offset_nbytes);
static_cast<size_t>(offset_nbytes));
}
} else {
// We must allocate new space for the offsets and shift the existing offsets
Expand Down Expand Up @@ -1238,8 +1238,9 @@ struct PlainSubstringMatcher {
for (size_t pos = 0; pos < pattern_length; ++pos) {
// The prefix cannot be expanded, reset.
while (prefix_length >= 0 &&
options_.pattern[pos] != options_.pattern[prefix_length]) {
prefix_length = prefix_table[prefix_length];
options_.pattern[pos] !=
options_.pattern[static_cast<size_t>(prefix_length)]) {
prefix_length = prefix_table[static_cast<size_t>(prefix_length)];
}
prefix_length++;
prefix_table[pos + 1] = prefix_length;
Expand All @@ -1253,8 +1254,9 @@ struct PlainSubstringMatcher {
int64_t pos = 0;
if (pattern_length == 0) return 0;
for (const auto c : current) {
while ((pattern_pos >= 0) && (options_.pattern[pattern_pos] != c)) {
pattern_pos = prefix_table[pattern_pos];
while ((pattern_pos >= 0) &&
(options_.pattern[static_cast<size_t>(pattern_pos)] != c)) {
pattern_pos = prefix_table[static_cast<size_t>(pattern_pos)];
}
pattern_pos++;
if (static_cast<size_t>(pattern_pos) == pattern_length) {
Expand Down Expand Up @@ -1344,7 +1346,8 @@ struct MatchSubstringImpl {
for (int64_t i = 0; i < length; ++i) {
const char* current_data = reinterpret_cast<const char*>(data + offsets[i]);
int64_t current_length = offsets[i + 1] - offsets[i];
if (matcher->Match(std::string_view(current_data, current_length))) {
if (matcher->Match(std::string_view(current_data,
static_cast<size_t>(current_length)))) {
bitmap_writer.Set();
}
bitmap_writer.Next();
Expand Down Expand Up @@ -1805,7 +1808,7 @@ struct CountSubstring {
uint64_t start = 0;
const auto pattern_size = std::max<uint64_t>(1, matcher_.options_.pattern.size());
while (start <= val.size()) {
const int64_t index = matcher_.Find(val.substr(start));
const int64_t index = matcher_.Find(val.substr(static_cast<size_t>(start)));
if (index >= 0) {
count++;
start += index + pattern_size;
Expand Down Expand Up @@ -3076,7 +3079,7 @@ struct BinaryJoinElementWise {
bit_util::GetBit(array.buffers[0].data, array.offset + row)) {
const offset_type* offsets = array.GetValues<offset_type>(1);
const uint8_t* data = array.GetValues<uint8_t>(2, /*absolute_offset=*/0);
const int64_t length = offsets[row + 1] - offsets[row];
const auto length = static_cast<size_t>(offsets[row + 1] - offsets[row]);
valid_cols[col] = std::string_view(
reinterpret_cast<const char*>(data + offsets[row]), length);
if (col < batch.num_values() - 1) num_valid++;
Expand Down Expand Up @@ -3305,7 +3308,7 @@ struct BinaryRepeatTransform : public StringBinaryTransformBase<Type1, Type2> {
const int64_t num_repeats, uint8_t* output) {
uint8_t* output_start = output;
for (int64_t i = 0; i < num_repeats; ++i) {
std::memcpy(output, input, input_string_ncodeunits);
std::memcpy(output, input, static_cast<size_t>(input_string_ncodeunits));
output += input_string_ncodeunits;
}
return output - output_start;
Expand All @@ -3318,18 +3321,18 @@ struct BinaryRepeatTransform : public StringBinaryTransformBase<Type1, Type2> {
uint8_t* output_start = output;
// Repeated doubling of string
// NB: This implementation expects `num_repeats > 0`.
std::memcpy(output, input, input_string_ncodeunits);
std::memcpy(output, input, static_cast<size_t>(input_string_ncodeunits));
output += input_string_ncodeunits;
int64_t irep = 1;
for (int64_t ilen = input_string_ncodeunits; irep <= (num_repeats / 2);
irep *= 2, ilen *= 2) {
std::memcpy(output, output_start, ilen);
std::memcpy(output, output_start, static_cast<size_t>(ilen));
output += ilen;
}

// Epilogue remainder
int64_t rem = (num_repeats - irep) * input_string_ncodeunits;
std::memcpy(output, output_start, rem);
std::memcpy(output, output_start, static_cast<size_t>(rem));
output += rem;
return output - output_start;
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/compute/kernels/scalar_string_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ struct StringSplitExec {
// we will record the parts in reverse order
parts.clear();
if (max_splits > -1) {
parts.reserve(max_splits + 1);
parts.reserve(static_cast<size_t>(max_splits + 1));
}
while (max_splits != 0) {
const uint8_t *separator_begin, *separator_end;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/compute/kernels/scalar_string_utf8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -558,12 +558,12 @@ struct Utf8NormalizeBase {
ARROW_ASSIGN_OR_RAISE(const auto n_codepoints, DecomposeIntoScratch(v));
// Encode normalized codepoints directly into the output
int64_t n_bytes = 0;
for (int64_t i = 0; i < n_codepoints; ++i) {
for (size_t i = 0; i < static_cast<size_t>(n_codepoints); ++i) {
n_bytes += ::arrow::util::UTF8EncodedLength(codepoints_[i]);
}
RETURN_NOT_OK(data_builder->Reserve(n_bytes));
uint8_t* out = data_builder->mutable_data() + data_builder->length();
for (int64_t i = 0; i < n_codepoints; ++i) {
for (size_t i = 0; i < static_cast<size_t>(n_codepoints); ++i) {
out = ::arrow::util::UTF8Encode(out, codepoints_[i]);
}
DCHECK_EQ(out - data_builder->mutable_data(), data_builder->length() + n_bytes);
Expand Down

0 comments on commit 97d738c

Please sign in to comment.