Skip to content

ByteString: Adjust bitfields for MSVC #1446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/internal/byte_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ ByteString ByteString::Concat(const ByteString& lhs, const ByteString& rhs,
result.rep_.medium.size = result_size;
result.rep_.medium.owner =
reinterpret_cast<uintptr_t>(arena) | kMetadataOwnerArenaBit;
result.rep_.medium.kind = ByteStringKind::kMedium;
result.rep_.header.kind = ByteStringKind::kMedium;
}
return result;
}
Expand Down
24 changes: 12 additions & 12 deletions common/internal/byte_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ inline std::ostream& operator<<(std::ostream& out, ByteStringKind kind) {
// Representation of small strings in ByteString, which are stored in place.
struct CEL_COMMON_INTERNAL_BYTE_STRING_TRIVIAL_ABI SmallByteStringRep final {
#ifdef _MSC_VER
#pragma push(pack, 1)
#pragma pack(push, 1)
#endif
struct ABSL_ATTRIBUTE_PACKED CEL_COMMON_INTERNAL_BYTE_STRING_TRIVIAL_ABI {
ByteStringKind kind : 2;
size_t size : 6;
std::uint8_t kind : 2;
std::uint8_t size : 6;
};
#ifdef _MSC_VER
#pragma pop(pack)
#pragma pack(pop)
#endif
char data[23 - sizeof(google::protobuf::Arena*)];
google::protobuf::Arena* ABSL_NULLABLE arena;
Expand All @@ -107,14 +107,14 @@ inline constexpr size_t kByteStringViewMaxSize =
// the same semantics as `cel::Owner`.
struct CEL_COMMON_INTERNAL_BYTE_STRING_TRIVIAL_ABI MediumByteStringRep final {
#ifdef _MSC_VER
#pragma push(pack, 1)
#pragma pack(push, 1)
#endif
struct ABSL_ATTRIBUTE_PACKED CEL_COMMON_INTERNAL_BYTE_STRING_TRIVIAL_ABI {
ByteStringKind kind : 2;
size_t kind : 2;
size_t size : kMediumByteStringSizeBits;
};
#ifdef _MSC_VER
#pragma pop(pack)
#pragma pack(pop)
#endif
const char* data;
uintptr_t owner;
Expand All @@ -124,28 +124,28 @@ struct CEL_COMMON_INTERNAL_BYTE_STRING_TRIVIAL_ABI MediumByteStringRep final {
// `absl::Cord` and never owned by an arena.
struct CEL_COMMON_INTERNAL_BYTE_STRING_TRIVIAL_ABI LargeByteStringRep final {
#ifdef _MSC_VER
#pragma push(pack, 1)
#pragma pack(push, 1)
#endif
struct ABSL_ATTRIBUTE_PACKED CEL_COMMON_INTERNAL_BYTE_STRING_TRIVIAL_ABI {
ByteStringKind kind : 2;
size_t kind : 2;
size_t padding : kMediumByteStringSizeBits;
};
#ifdef _MSC_VER
#pragma pop(pack)
#pragma pack(pop)
#endif
alignas(absl::Cord) std::byte data[sizeof(absl::Cord)];
};

// Representation of ByteString.
union CEL_COMMON_INTERNAL_BYTE_STRING_TRIVIAL_ABI ByteStringRep final {
#ifdef _MSC_VER
#pragma push(pack, 1)
#pragma pack(push, 1)
#endif
struct ABSL_ATTRIBUTE_PACKED CEL_COMMON_INTERNAL_BYTE_STRING_TRIVIAL_ABI {
ByteStringKind kind : 2;
} header;
#ifdef _MSC_VER
#pragma pop(pack)
#pragma pack(pop)
#endif
SmallByteStringRep small;
MediumByteStringRep medium;
Expand Down