Skip to content

Commit

Permalink
ARROW-13493 [C++] Anonymous structs in an anonymous union are a GNU e…
Browse files Browse the repository at this point in the history
…xtension

Closes apache#10833 from nirandaperera/ARROW-13493

Authored-by: niranda perera <niranda.perera@gmail.com>
Signed-off-by: Neal Richardson <neal.p.richardson@gmail.com>
  • Loading branch information
nirandaperera authored and nealrichardson committed Aug 5, 2021
1 parent f50e04e commit 0e41d80
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
20 changes: 10 additions & 10 deletions cpp/src/arrow/util/bitmap_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,16 @@ class BitmapWordReader {
trailing_bytes_ = static_cast<int>(BitUtil::BytesForBits(trailing_bits_));

if (nwords_ > 0) {
current_word_ = load<Word>(bitmap_);
current_data.word_ = load<Word>(bitmap_);
} else if (length > 0) {
current_byte_ = load<uint8_t>(bitmap_);
current_data.epi.byte_ = load<uint8_t>(bitmap_);
}
}

Word NextWord() {
bitmap_ += sizeof(Word);
const Word next_word = load<Word>(bitmap_);
Word word = current_word_;
Word word = current_data.word_;
if (may_have_byte_offset && offset_) {
// combine two adjacent words into one word
// |<------ next ----->|<---- current ---->|
Expand All @@ -188,7 +188,7 @@ class BitmapWordReader {
word >>= offset_;
word |= next_word << (sizeof(Word) * 8 - offset_);
}
current_word_ = next_word;
current_data.word_ = next_word;
return word;
}

Expand All @@ -213,12 +213,12 @@ class BitmapWordReader {
} else {
++bitmap_;
const uint8_t next_byte = load<uint8_t>(bitmap_);
byte = current_byte_;
byte = current_data.epi.byte_;
if (may_have_byte_offset && offset_) {
byte >>= offset_;
byte |= next_byte << (8 - offset_);
}
current_byte_ = next_byte;
current_data.epi.byte_ = next_byte;
trailing_bits_ -= 8;
trailing_bytes_--;
valid_bits = 8;
Expand All @@ -238,14 +238,14 @@ class BitmapWordReader {
int trailing_bits_;
int trailing_bytes_;
union {
Word current_word_;
Word word_;
struct {
#if ARROW_LITTLE_ENDIAN == 0
uint8_t padding_bytes_[sizeof(Word) - 1];
#endif
uint8_t current_byte_;
};
};
uint8_t byte_;
} epi;
} current_data;

template <typename DType>
DType load(const uint8_t* bitmap) {
Expand Down
24 changes: 12 additions & 12 deletions cpp/src/arrow/util/bitmap_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ class BitmapWordWriter {
mask_((1U << offset_) - 1) {
if (offset_) {
if (length >= static_cast<int>(sizeof(Word) * 8)) {
current_word_ = load<Word>(bitmap_);
current_data.word_ = load<Word>(bitmap_);
} else if (length > 0) {
current_byte_ = load<uint8_t>(bitmap_);
current_data.epi.byte_ = load<uint8_t>(bitmap_);
}
}
}
Expand All @@ -213,11 +213,11 @@ class BitmapWordWriter {
// |<------ next ----->|<---- current ---->|
word = (word << offset_) | (word >> (sizeof(Word) * 8 - offset_));
Word next_word = load<Word>(bitmap_ + sizeof(Word));
current_word_ = (current_word_ & mask_) | (word & ~mask_);
current_data.word_ = (current_data.word_ & mask_) | (word & ~mask_);
next_word = (next_word & ~mask_) | (word & mask_);
store<Word>(bitmap_, current_word_);
store<Word>(bitmap_, current_data.word_);
store<Word>(bitmap_ + sizeof(Word), next_word);
current_word_ = next_word;
current_data.word_ = next_word;
} else {
store<Word>(bitmap_, word);
}
Expand All @@ -229,11 +229,11 @@ class BitmapWordWriter {
if (may_have_byte_offset && offset_) {
byte = (byte << offset_) | (byte >> (8 - offset_));
uint8_t next_byte = load<uint8_t>(bitmap_ + 1);
current_byte_ = (current_byte_ & mask_) | (byte & ~mask_);
current_data.epi.byte_ = (current_data.epi.byte_ & mask_) | (byte & ~mask_);
next_byte = (next_byte & ~mask_) | (byte & mask_);
store<uint8_t>(bitmap_, current_byte_);
store<uint8_t>(bitmap_, current_data.epi.byte_);
store<uint8_t>(bitmap_ + 1, next_byte);
current_byte_ = next_byte;
current_data.epi.byte_ = next_byte;
} else {
store<uint8_t>(bitmap_, byte);
}
Expand All @@ -259,14 +259,14 @@ class BitmapWordWriter {
const uint8_t* bitmap_end_;
uint64_t mask_;
union {
Word current_word_;
Word word_;
struct {
#if ARROW_LITTLE_ENDIAN == 0
uint8_t padding_bytes_[sizeof(Word) - 1];
#endif
uint8_t current_byte_;
};
};
uint8_t byte_;
} epi;
} current_data;

template <typename DType>
DType load(const uint8_t* bitmap) {
Expand Down

0 comments on commit 0e41d80

Please sign in to comment.