Skip to content

Commit

Permalink
Merge pull request #295 from dpogue/endian-fixes
Browse files Browse the repository at this point in the history
Avoid WORDS_BIGENDIAN conflict with Python3
  • Loading branch information
zrax authored Dec 22, 2024
2 parents a95ca3a + bdf430d commit 341ca00
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ cmake_dependent_option(
OFF
)

include(TestBigEndian)
test_big_endian(BIG_ENDIAN)
if(BIG_ENDIAN)
add_definitions("-DHS_BIG_ENDIAN")
endif()

set(CMAKE_C_FLAGS_DEBUG "-DDEBUG ${CMAKE_C_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG ${CMAKE_CXX_FLAGS_DEBUG}")
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR
Expand Down
8 changes: 4 additions & 4 deletions core/Stream/hsStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ uint16_t hsStream::readShort()
void hsStream::readShorts(size_t count, uint16_t* buf)
{
read(sizeof(uint16_t) * count, buf);
#ifdef WORDS_BIGENDIAN
#ifdef HS_BIG_ENDIAN
for (size_t i=0; i<count; i++)
buf[i] = LESWAP16(buf[i]);
#endif
Expand All @@ -70,7 +70,7 @@ uint32_t hsStream::readInt()
void hsStream::readInts(size_t count, uint32_t* buf)
{
read(sizeof(uint32_t) * count, buf);
#ifdef WORDS_BIGENDIAN
#ifdef HS_BIG_ENDIAN
for (size_t i=0; i<count; i++)
buf[i] = LESWAP32(buf[i]);
#endif
Expand Down Expand Up @@ -220,7 +220,7 @@ void hsStream::writeShort(uint16_t v)

void hsStream::writeShorts(size_t count, const uint16_t* buf)
{
#ifdef WORDS_BIGENDIAN
#ifdef HS_BIG_ENDIAN
uint16_t* swbuf = new uint16_t[count];
for (size_t i=0; i<count; i++)
swbuf[i] = LESWAP16(buf[i]);
Expand All @@ -239,7 +239,7 @@ void hsStream::writeInt(uint32_t v)

void hsStream::writeInts(size_t count, const uint32_t* buf)
{
#ifdef WORDS_BIGENDIAN
#ifdef HS_BIG_ENDIAN
uint32_t* swbuf = new uint32_t[count];
for (size_t i=0; i<count; i++)
swbuf[i] = LESWAP32(buf[i]);
Expand Down
6 changes: 1 addition & 5 deletions core/Sys/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,7 @@ inline double ENDSWAPD(double val)
return conv.fv;
}

#if defined(MACOSX) && defined(__BIG_ENDIAN__)
#define WORDS_BIGENDIAN
#endif

#ifdef WORDS_BIGENDIAN
#ifdef HS_BIG_ENDIAN
#define LESWAP16(val) ENDSWAP16(val)
#define BESWAP16(val) (val)
#define LESWAP32(val) ENDSWAP32(val)
Expand Down

0 comments on commit 341ca00

Please sign in to comment.