Skip to content

Commit

Permalink
crnlib: make CRNLIB_FORCE_INLINE functions extern because the compile…
Browse files Browse the repository at this point in the history
…r will override anyway

Avoids errors on macOS like:

duplicate symbol __ZN6crnlib5utils10write_le64EPvy in:
    crn_arealist.o
    crn_assert.o

Setting static instead of extern would also workaround the error but it's wrong
and would raise warnings on other systems like FreeBSD:

In file included from crunch/crnlib/crn_core.h:174:
crunch/crnlib/crn_utils.h:235:8: warning: 'gnu_inline' attribute without 'extern' in C++ treated as externally available, this changed in Clang 10 [-Wgnu-inline-cpp-without-extern]
static CRNLIB_FORCE_INLINE void write_be64(void* p, uint64 x) {
       ^
crunch/crnlib/crn_core.h:85:70: note: expanded from macro 'CRNLIB_FORCE_INLINE'
 #define CRNLIB_FORCE_INLINE inline __attribute__((__always_inline__, __gnu_inline__))
                                                                      ^

Setting extern fixes the duplicate symbols error on macOS without introducing
warnings on FreeBSD.
  • Loading branch information
illwieckz committed Feb 10, 2023
1 parent 4b7442d commit ec8eb7a
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions crnlib/crn_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,82 +157,82 @@ inline bool read_obj(T& obj, const void*& pBuf, uint& buf_size, bool buffer_is_l
}

#if defined(_MSC_VER)
static CRNLIB_FORCE_INLINE uint16 swap16(uint16 x) {
extern CRNLIB_FORCE_INLINE uint16 swap16(uint16 x) {
return _byteswap_ushort(x);
}
static CRNLIB_FORCE_INLINE uint32 swap32(uint32 x) {
extern CRNLIB_FORCE_INLINE uint32 swap32(uint32 x) {
return _byteswap_ulong(x);
}
static CRNLIB_FORCE_INLINE uint64 swap64(uint64 x) {
extern CRNLIB_FORCE_INLINE uint64 swap64(uint64 x) {
return _byteswap_uint64(x);
}
#elif defined(__GNUC__)
static CRNLIB_FORCE_INLINE uint16 swap16(uint16 x) {
extern CRNLIB_FORCE_INLINE uint16 swap16(uint16 x) {
return static_cast<uint16>((x << 8U) | (x >> 8U));
}
static CRNLIB_FORCE_INLINE uint32 swap32(uint32 x) {
extern CRNLIB_FORCE_INLINE uint32 swap32(uint32 x) {
return __builtin_bswap32(x);
}
static CRNLIB_FORCE_INLINE uint64 swap64(uint64 x) {
extern CRNLIB_FORCE_INLINE uint64 swap64(uint64 x) {
return __builtin_bswap64(x);
}
#else
static CRNLIB_FORCE_INLINE uint16 swap16(uint16 x) {
extern CRNLIB_FORCE_INLINE uint16 swap16(uint16 x) {
return static_cast<uint16>((x << 8U) | (x >> 8U));
}
static CRNLIB_FORCE_INLINE uint32 swap32(uint32 x) {
extern CRNLIB_FORCE_INLINE uint32 swap32(uint32 x) {
return ((x << 24U) | ((x << 8U) & 0x00FF0000U) | ((x >> 8U) & 0x0000FF00U) | (x >> 24U));
}
static CRNLIB_FORCE_INLINE uint64 swap64(uint64 x) {
extern CRNLIB_FORCE_INLINE uint64 swap64(uint64 x) {
return (static_cast<uint64>(swap32(static_cast<uint32>(x))) << 32ULL) | swap32(static_cast<uint32>(x >> 32U));
}
#endif

// Assumes x has been read from memory as a little endian value, converts to native endianness for manipulation.
CRNLIB_FORCE_INLINE uint16 swap_le16_to_native(uint16 x) {
extern CRNLIB_FORCE_INLINE uint16 swap_le16_to_native(uint16 x) {
return c_crnlib_little_endian_platform ? x : swap16(x);
}
CRNLIB_FORCE_INLINE uint32 swap_le32_to_native(uint32 x) {
extern CRNLIB_FORCE_INLINE uint32 swap_le32_to_native(uint32 x) {
return c_crnlib_little_endian_platform ? x : swap32(x);
}
CRNLIB_FORCE_INLINE uint64 swap_le64_to_native(uint64 x) {
extern CRNLIB_FORCE_INLINE uint64 swap_le64_to_native(uint64 x) {
return c_crnlib_little_endian_platform ? x : swap64(x);
}

// Assumes x has been read from memory as a big endian value, converts to native endianness for manipulation.
CRNLIB_FORCE_INLINE uint16 swap_be16_to_native(uint16 x) {
extern CRNLIB_FORCE_INLINE uint16 swap_be16_to_native(uint16 x) {
return c_crnlib_big_endian_platform ? x : swap16(x);
}
CRNLIB_FORCE_INLINE uint32 swap_be32_to_native(uint32 x) {
extern CRNLIB_FORCE_INLINE uint32 swap_be32_to_native(uint32 x) {
return c_crnlib_big_endian_platform ? x : swap32(x);
}
CRNLIB_FORCE_INLINE uint64 swap_be64_to_native(uint64 x) {
extern CRNLIB_FORCE_INLINE uint64 swap_be64_to_native(uint64 x) {
return c_crnlib_big_endian_platform ? x : swap64(x);
}

CRNLIB_FORCE_INLINE uint32 read_le32(const void* p) {
extern CRNLIB_FORCE_INLINE uint32 read_le32(const void* p) {
return swap_le32_to_native(*static_cast<const uint32*>(p));
}
CRNLIB_FORCE_INLINE void write_le32(void* p, uint32 x) {
extern CRNLIB_FORCE_INLINE void write_le32(void* p, uint32 x) {
*static_cast<uint32*>(p) = swap_le32_to_native(x);
}
CRNLIB_FORCE_INLINE uint64 read_le64(const void* p) {
extern CRNLIB_FORCE_INLINE uint64 read_le64(const void* p) {
return swap_le64_to_native(*static_cast<const uint64*>(p));
}
CRNLIB_FORCE_INLINE void write_le64(void* p, uint64 x) {
extern CRNLIB_FORCE_INLINE void write_le64(void* p, uint64 x) {
*static_cast<uint64*>(p) = swap_le64_to_native(x);
}

CRNLIB_FORCE_INLINE uint32 read_be32(const void* p) {
extern CRNLIB_FORCE_INLINE uint32 read_be32(const void* p) {
return swap_be32_to_native(*static_cast<const uint32*>(p));
}
CRNLIB_FORCE_INLINE void write_be32(void* p, uint32 x) {
extern CRNLIB_FORCE_INLINE void write_be32(void* p, uint32 x) {
*static_cast<uint32*>(p) = swap_be32_to_native(x);
}
CRNLIB_FORCE_INLINE uint64 read_be64(const void* p) {
extern CRNLIB_FORCE_INLINE uint64 read_be64(const void* p) {
return swap_be64_to_native(*static_cast<const uint64*>(p));
}
CRNLIB_FORCE_INLINE void write_be64(void* p, uint64 x) {
extern CRNLIB_FORCE_INLINE void write_be64(void* p, uint64 x) {
*static_cast<uint64*>(p) = swap_be64_to_native(x);
}

Expand Down

0 comments on commit ec8eb7a

Please sign in to comment.