Skip to content
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

strict aliasing via C++20's char8_t (merged with master) #9312

Merged
merged 16 commits into from
Feb 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions base/common/StringRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ struct StringRef
const char * data = nullptr;
size_t size = 0;

StringRef(const char * data_, size_t size_) : data(data_), size(size_) {}
StringRef(const unsigned char * data_, size_t size_) : data(reinterpret_cast<const char *>(data_)), size(size_) {}
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>>
StringRef(const CharT * data_, size_t size_) : data(reinterpret_cast<const char *>(data_)), size(size_) {}

StringRef(const std::string & s) : data(s.data()), size(s.size()) {}
StringRef(const std::string_view & s) : data(s.data()), size(s.size()) {}
explicit StringRef(const char * data_) : data(data_), size(strlen(data_)) {}
Expand Down
2 changes: 1 addition & 1 deletion base/common/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using Int16 = int16_t;
using Int32 = int32_t;
using Int64 = int64_t;

using UInt8 = uint8_t;
using UInt8 = char8_t;
using UInt16 = uint16_t;
using UInt32 = uint32_t;
using UInt64 = uint64_t;
Expand Down
6 changes: 6 additions & 0 deletions base/common/itoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,12 @@ char * itoa(I i, char * p)
return impl::convert::itoa(i, p);
}

template <>
inline char * itoa(char8_t i, char * p)
{
return impl::convert::itoa(uint8_t(i), p);
}

template <>
inline char * itoa<uint128_t>(uint128_t i, char * p)
{
Expand Down
1 change: 1 addition & 0 deletions base/mysqlxx/include/mysqlxx/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ template <> inline bool Value::get<bool >() cons
template <> inline char Value::get<char >() const { return getInt(); }
template <> inline signed char Value::get<signed char >() const { return getInt(); }
template <> inline unsigned char Value::get<unsigned char >() const { return getUInt(); }
template <> inline char8_t Value::get<char8_t >() const { return getUInt(); }
template <> inline short Value::get<short >() const { return getInt(); }
template <> inline unsigned short Value::get<unsigned short >() const { return getUInt(); }
template <> inline int Value::get<int >() const { return getInt(); }
Expand Down
2 changes: 1 addition & 1 deletion contrib/libcxx
1 change: 0 additions & 1 deletion dbms/src/Access/Authentication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,3 @@ void Authentication::checkPassword(const String & password_, const String & user
}

}

2 changes: 1 addition & 1 deletion dbms/src/Access/Authentication.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Authentication
DOUBLE_SHA1_PASSWORD,
};

using Digest = std::vector<UInt8>;
using Digest = std::vector<uint8_t>;

Authentication(Authentication::Type type_ = NO_PASSWORD) : type(type_) {}
Authentication(const Authentication & src) = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ class RoaringBitmapWithSmallSet : private boost::noncopyable
}
}

UInt32 db_container_to_uint32_array(DB::WriteBuffer & dbBuf, const void * container, UInt8 typecode, UInt32 base) const
UInt32 db_container_to_uint32_array(DB::WriteBuffer & dbBuf, const void * container, uint8_t typecode, UInt32 base) const
{
container = container_unwrap_shared(container, &typecode);
switch (typecode)
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/AggregateFunctions/QuantileTiming.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ class QuantileTiming : private boost::noncopyable
detail::QuantileTimingLarge * large;
};

enum class Kind : UInt8
enum class Kind : uint8_t
{
Tiny = 1,
Medium = 2,
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Columns/ColumnNullable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ StringRef ColumnNullable::serializeValueIntoArena(size_t n, Arena & arena, char

const char * ColumnNullable::deserializeAndInsertFromArena(const char * pos)
{
UInt8 val = *reinterpret_cast<const UInt8 *>(pos);
UInt8 val = unalignedLoad<UInt8>(pos);
pos += sizeof(val);

getNullMapData().push_back(val);
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Columns/ColumnUnique.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ size_t ColumnUnique<ColumnType>::uniqueDeserializeAndInsertFromArena(const char
{
if (is_nullable)
{
UInt8 val = *reinterpret_cast<const UInt8 *>(pos);
UInt8 val = unalignedLoad<UInt8>(pos);
pos += sizeof(val);

if (val)
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Common/CombinedCardinalityEstimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ namespace DB
namespace details
{

enum class ContainerType : UInt8 { SMALL = 1, MEDIUM = 2, LARGE = 3 };
enum class ContainerType : uint8_t { SMALL = 1, MEDIUM = 2, LARGE = 3 };

static inline ContainerType max(const ContainerType & lhs, const ContainerType & rhs)
{
UInt8 res = std::max(static_cast<UInt8>(lhs), static_cast<UInt8>(rhs));
uint8_t res = std::max(static_cast<uint8_t>(lhs), static_cast<uint8_t>(rhs));
return static_cast<ContainerType>(res);
}

Expand Down