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

improve endianness validation strategy #10

Open
wants to merge 4 commits into
base: main
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
14 changes: 2 additions & 12 deletions cpp/BloomFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,18 @@ BloomFilter::~BloomFilter()

const char *BloomFilter::getInternalPointer() const
{
#if IS_BIG_ENDIAN
throw std::runtime_error("Big endian systems are not supported");
#endif
return reinterpret_cast<const char *>(internal);
}

char *BloomFilter::getMutableInternalPointer()
{
#if IS_BIG_ENDIAN
throw std::runtime_error("Big endian systems are not supported");
#endif
return reinterpret_cast<char *>(internal);
}

// Zero-copy constructor
BloomFilter::BloomFilter(const char *buff)
{
#if IS_BIG_ENDIAN
throw std::runtime_error("Big endian systems are not supported");
#endif
internal =
const_cast<BloomFilterSerialized *>(reinterpret_cast<const BloomFilterSerialized *>(buff));
internal = const_cast<BloomFilterSerialized *>(
reinterpret_cast<const BloomFilterSerialized *>(buff));
}

auto BloomFilter::hashString(const std::string &value, uint32_t seed) -> uint32_t
Expand Down
12 changes: 2 additions & 10 deletions cpp/BloomFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,11 @@
#include <stdexcept>
#include <string>

// TODO: check these preprocessor directives..
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
#define IS_BIG_ENDIAN 1
#elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
#define IS_BIG_ENDIAN 0
#error "TODO: Big Endian support"
#elif defined(__BIG_ENDIAN__) || defined(__ARMEB__) || defined(__THUMBEB__) || \
defined(__AARCH64EB__) || defined(_MIBSEB) || defined(__MIBSEB) || defined(__MIBSEB__)
#define IS_BIG_ENDIAN 1
#elif defined(__LITTLE_ENDIAN__) || defined(__ARMEL__) || defined(__THUMBEL__) || \
defined(__AARCH64EL__) || defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__)
#define IS_BIG_ENDIAN 0
#else
#error "Unable to determine endianness, manual configuration required"
#error "TODO: Big Endian support"
#endif

class FalsePositiveRate
Expand Down
Loading