Skip to content

Commit

Permalink
ffi: Add support for MSVC compilation.
Browse files Browse the repository at this point in the history
  • Loading branch information
junhaoliao committed Mar 31, 2024
1 parent 2b884bd commit 6eb6806
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion components/core/src/ffi/ir_stream/byteswap.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#ifndef FFI_IR_STREAM_BYTESWAP_HPP
#define FFI_IR_STREAM_BYTESWAP_HPP

#ifdef __APPLE__
#if defined(__APPLE__)
#include <libkern/OSByteOrder.h>
#define bswap_16(x) OSSwapInt16(x)
#define bswap_32(x) OSSwapInt32(x)
#define bswap_64(x) OSSwapInt64(x)
#elif defined(_MSC_VER)
#include <stdlib.h>
#define bswap_16(x) _byteswap_ushort(x)
#define bswap_32(x) _byteswap_ulong(x)
#define bswap_64(x) _byteswap_uint64(x)
#else
#include <byteswap.h>
#endif
Expand Down
8 changes: 7 additions & 1 deletion components/core/src/string_utils.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@

template <typename integer_t>
bool convert_string_to_int(std::string_view raw, integer_t& converted) {
#if defined(_MSC_VER)
auto raw_begin = raw.data();
auto raw_end = raw_begin + raw.size();
#else
auto raw_begin = raw.cbegin();
auto raw_end = raw.cend();
auto result = std::from_chars(raw.cbegin(), raw_end, converted);
#endif
auto result = std::from_chars(raw_begin, raw_end, converted);
if (raw_end != result.ptr) {
return false;
} else {
Expand Down

0 comments on commit 6eb6806

Please sign in to comment.