Skip to content

Commit 6cd3426

Browse files
committed
avoid dangling references
1 parent a21def9 commit 6cd3426

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

Framework/Core/include/Framework/ASoA.h

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,12 @@ struct unwrap<std::vector<T>> {
471471
using type = T;
472472
};
473473

474+
template <typename T, int N>
475+
struct unwrap<T[N]> {
476+
using type = T[N];
477+
using base_type = T;
478+
};
479+
474480
template <>
475481
struct unwrap<bool> {
476482
using type = char;
@@ -560,15 +566,15 @@ class ColumnIterator : ChunkingPolicy
560566
mLast = mCurrent + array->length() + (mFirstIndex >> SCALE_FACTOR);
561567
}
562568

563-
decltype(auto) operator*() const
569+
auto operator*() const
564570
requires std::same_as<bool, std::decay_t<T>>
565571
{
566572
checkSkipChunk();
567573
return (*(mCurrent - (mOffset >> SCALE_FACTOR) + ((*mCurrentPos + mOffset) >> SCALE_FACTOR)) & (1 << ((*mCurrentPos + mOffset) & 0x7))) != 0;
568574
}
569575

570-
decltype(auto) operator*() const
571-
requires((!std::same_as<bool, std::decay_t<T>>) && std::same_as<arrow_array_for_t<T>, arrow::ListArray>)
576+
auto operator*() const
577+
requires((!std::same_as<bool, std::decay_t<T>>) && std::same_as<arrow_array_for_t<T>, arrow::ListArray> && !std::same_as<arrow_array_for_t<T>, arrow::FixedSizeListArray>)
572578
{
573579
checkSkipChunk();
574580
auto list = std::static_pointer_cast<arrow::ListArray>(mColumn->chunk(mCurrentChunk));
@@ -577,8 +583,15 @@ class ColumnIterator : ChunkingPolicy
577583
return std::span{mCurrent + mFirstIndex + offset, mCurrent + mFirstIndex + (offset + length)};
578584
}
579585

580-
decltype(auto) operator*() const
581-
requires((!std::same_as<bool, std::decay_t<T>>) && !std::same_as<arrow_array_for_t<T>, arrow::ListArray>)
586+
auto operator*() const
587+
requires((!std::same_as<bool, std::decay_t<T>>) && !std::same_as<arrow_array_for_t<T>, arrow::ListArray> && std::same_as<arrow_array_for_t<T>, arrow::FixedSizeListArray>)
588+
{
589+
checkSkipChunk();
590+
return std::span{reinterpret_cast<const unwrap<T>::base_type*>(mCurrent + (*mCurrentPos >> SCALE_FACTOR)), arrow_array_for<T>::width};
591+
}
592+
593+
auto operator*() const
594+
requires((!std::same_as<bool, std::decay_t<T>>) && !std::same_as<arrow_array_for_t<T>, arrow::ListArray> && !std::same_as<arrow_array_for_t<T>, arrow::FixedSizeListArray>)
582595
{
583596
checkSkipChunk();
584597
return *(mCurrent + (*mCurrentPos >> SCALE_FACTOR));

Framework/Core/include/Framework/ArrowTypes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,31 @@ struct arrow_array_for<double> {
6464
};
6565
template <int N>
6666
struct arrow_array_for<float[N]> {
67+
static constexpr size_t width = N;
6768
using type = arrow::FixedSizeListArray;
6869
using value_type = float;
6970
};
7071
template <int N>
7172
struct arrow_array_for<int[N]> {
73+
static constexpr size_t width = N;
7274
using type = arrow::FixedSizeListArray;
7375
using value_type = int;
7476
};
7577
template <int N>
7678
struct arrow_array_for<short[N]> {
79+
static constexpr size_t width = N;
7780
using type = arrow::FixedSizeListArray;
7881
using value_type = short;
7982
};
8083
template <int N>
8184
struct arrow_array_for<double[N]> {
85+
static constexpr size_t width = N;
8286
using type = arrow::FixedSizeListArray;
8387
using value_type = double;
8488
};
8589
template <int N>
8690
struct arrow_array_for<int8_t[N]> {
91+
static constexpr size_t width = N;
8792
using type = arrow::FixedSizeListArray;
8893
using value_type = int8_t;
8994
};

Framework/Core/test/test_ASoA.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ DECLARE_SOA_COLUMN(One, one, int);
13321332
DECLARE_SOA_COLUMN(Two, two, float);
13331333
DECLARE_SOA_COLUMN(Three, three, double);
13341334
DECLARE_SOA_COLUMN(Four, four, int[2]);
1335-
DECLARE_SOA_DYNAMIC_COLUMN(Five, five, [](const int in[2]) -> float { return (float)in[0] / (float)in[1]; });
1335+
DECLARE_SOA_DYNAMIC_COLUMN(Five, five, [](std::span<const int> in) -> float { return (float)in[0] / (float)in[1]; });
13361336
} // namespace table
13371337

13381338
DECLARE_SOA_TABLE(MixTest, "AOD", "MIXTST",

0 commit comments

Comments
 (0)