Skip to content

Commit

Permalink
simplify endian handling (#737)
Browse files Browse the repository at this point in the history
* simplify endian handling

* lint
  • Loading branch information
lemire authored Sep 18, 2024
1 parent 7459f65 commit e730702
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 40 deletions.
34 changes: 0 additions & 34 deletions include/ada/common_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,40 +185,6 @@ namespace ada {
#define ada_constexpr constexpr
#endif

#if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__)
#define ADA_IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
#elif defined(_WIN32)
#define ADA_IS_BIG_ENDIAN 0
#else
#if defined(__APPLE__) || \
defined(__FreeBSD__) // defined __BYTE_ORDER__ && defined
// __ORDER_BIG_ENDIAN__
#include <machine/endian.h>
#elif defined(sun) || \
defined(__sun) // defined(__APPLE__) || defined(__FreeBSD__)
#include <sys/byteorder.h>
#else // defined(__APPLE__) || defined(__FreeBSD__)

#ifdef __has_include
#if __has_include(<endian.h>)
#include <endian.h>
#endif //__has_include(<endian.h>)
#endif //__has_include

#endif // defined(__APPLE__) || defined(__FreeBSD__)

#ifndef !defined(__BYTE_ORDER__) || !defined(__ORDER_LITTLE_ENDIAN__)
#define ADA_IS_BIG_ENDIAN 0
#endif

#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define ADA_IS_BIG_ENDIAN 0
#else // __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define ADA_IS_BIG_ENDIAN 1
#endif // __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__

#endif // defined __BYTE_ORDER__ && defined __ORDER_BIG_ENDIAN__

// Unless the programmer has already set ADA_DEVELOPMENT_CHECKS,
// we want to set it under debug builds. We detect a debug build
// under Visual Studio when the _DEBUG macro is set. Under the other
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "ada.h"
#include "ada/checkers-inl.h"
#include "ada/common_defs.h" // make sure ADA_IS_BIG_ENDIAN gets defined.
#include "ada/common_defs.h"
#include "ada/scheme.h"

#include <cstring>
Expand Down
11 changes: 6 additions & 5 deletions tests/basic_fuzzer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "ada.h"
#include <iostream>
#include <memory>
#include <bit>

std::string url_examples[] = {
"https://www.google.com/"
Expand Down Expand Up @@ -118,11 +119,11 @@ size_t roller_fuzz(size_t N) {
}

int main() {
#if ADA_IS_BIG_ENDIAN
std::cout << "You have big-endian system." << std::endl;
#else
std::cout << "You have litte-endian system." << std::endl;
#endif
if (std::endian::native == std::endian::big) {
std::cout << "You have big-endian system." << std::endl;
} else {
std::cout << "You have litte-endian system." << std::endl;
}
std::cout << "Running basic fuzzer.\n";
std::cout << "[fancy] Executed " << fancy_fuzz<ada::url>(100000)
<< " mutations.\n";
Expand Down

0 comments on commit e730702

Please sign in to comment.