Эх сурвалжийг харах

common: fix swap functions on Bitrig and OpenBSD

swap{16,32,64} are defined as macros on the two, but client code
tries to invoke them as Common::swap{16,32,64}, which naturally
doesn't work. This hack redefines the macros as inline functions
in the Common namespace: the bodies of the functions are the
same as the original macros, but relying on OS-specific
implementation details like this is of course brittle.
Daniel Lim Wee Soong 8 жил өмнө
parent
commit
a66204eb5c
1 өөрчлөгдсөн 13 нэмэгдсэн , 1 устгасан
  1. 13 1
      src/common/swap.h

+ 13 - 1
src/common/swap.h

@@ -103,7 +103,19 @@ inline __attribute__((always_inline)) u64 swap64(u64 _data) {
     return __builtin_bswap64(_data);
 }
 #elif defined(__Bitrig__) || defined(__OpenBSD__)
-// swap16, swap32, swap64 are left as is
+// redefine swap16, swap32, swap64 as inline functions
+#undef swap16
+#undef swap32
+#undef swap64
+inline u16 swap16(u16 _data) {
+    return __swap16(_data);
+}
+inline u32 swap32(u32 _data) {
+    return __swap32(_data);
+}
+inline u64 swap64(u64 _data) {
+    return __swap64(_data);
+}
 #elif defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__)
 inline u16 swap16(u16 _data) {
     return bswap16(_data);