Skip to content

Commit cc477e0

Browse files
committed
fixup! interpreter: add macos compat for htole32 and htole64
1 parent c65e0f1 commit cc477e0

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

src/script/interpreter.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ extern "C" {
1616
#include <simplicity/elements/exec.h>
1717
#include <simplicity/errorCodes.h>
1818
}
19-
// ELEMENTS: Macos compat for htole32 and htole64
20-
#if defined(__APPLE__)
21-
#include <libkern/OSByteOrder.h>
22-
#define htole32(x) OSSwapHostToLittleInt32(x)
23-
#define htole64(x) OSSwapHostToLittleInt64(x)
24-
#endif
2519

2620
typedef std::vector<unsigned char> valtype;
2721

@@ -90,13 +84,13 @@ static inline int64_t read_le8_signed(const unsigned char* ptr)
9084

9185
static inline void push4_le(std::vector<valtype>& stack, uint32_t v)
9286
{
93-
uint32_t v_le = htole32(v);
87+
uint32_t v_le = htole32_internal(v);
9488
stack.emplace_back(reinterpret_cast<unsigned char*>(&v_le), reinterpret_cast<unsigned char*>(&v_le) + sizeof(v_le));
9589
}
9690

9791
static inline void push8_le(std::vector<valtype>& stack, uint64_t v)
9892
{
99-
uint64_t v_le = htole64(v);
93+
uint64_t v_le = htole64_internal(v);
10094
stack.emplace_back(reinterpret_cast<unsigned char*>(&v_le), reinterpret_cast<unsigned char*>(&v_le) + sizeof(v_le));
10195
}
10296

@@ -1669,7 +1663,7 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
16691663
hasher.Write(vchSeed.data(), vchSeed.size());
16701664
do {
16711665
if (nHashIndex >= 3) {
1672-
uint64_t le_counter = htole64(nCounter);
1666+
uint64_t le_counter = htole64_internal(nCounter);
16731667
CSHA256(hasher).Write((const unsigned char*)&le_counter, sizeof(nCounter)).Finalize(vchHash.data());
16741668
nHashIndex = 0;
16751669
nCounter++;

src/test/fuzz/simplicity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ uint32_t read_u32(const unsigned char **buf) {
6969
uint32_t ret;
7070
memcpy(&ret, *buf, 4);
7171
*buf += 4;
72-
return le32toh(ret);
72+
return le32toh_internal(ret);
7373
}
7474

7575
#define MAX_LEN (1024 * 1024)

0 commit comments

Comments
 (0)