Skip to contentSkip to conversation

compat/bswap.h: don't assume MSVC is little-endian

PATCH In review Daniel Gurney 3 participants 3 messages Nov 11, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 compat/bswap.h: don't assume MSVC is little-endian

In 1af265f0 (compat/bswap.h: simplify MSVC endianness detection, 2020-11-08) we attempted to simplify code by assuming MSVC builds will be for little-endian machines, since only unusably old versions of MSVC supported big-endian MIPS and m68k architectures.

However, it's possible that MSVC could be ported to build for a big-endian architecture again, so the simplification wasn't as future-proof as hoped.

So let's go back to the old way of detecting MSVC, and then checking architecture from a list of little-endian architecture macros.

Note that MSVC does not treat ARM64 as bi-endian, so we can safely treat it as little-endian.

---
 compat/bswap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
compat/bswap.h +1 -1
index 72f225eaa8..512f6f4b99 100644
@@ -74,7 +74,7 @@ static inline uint64_t git_bswap64(uint64_t x)
 }
 #endif
 
-#elif defined(_MSC_VER)
+#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64) || defined(_M_ARM64))
 
 #include <stdlib.h>
 
Signature · 1 line
2.29.2
#1 lore raw

Hi Daniel,

Quoted 12 lines · Daniel Gurney

In 1af265f0 (compat/bswap.h: simplify MSVC endianness detection, 2020-11-08) we attempted to simplify code by assuming MSVC builds will be for little-endian machines, since only unusably old versions of MSVC supported big-endian MIPS and m68k architectures.

However, it's possible that MSVC could be ported to build for a big-endian architecture again, so the simplification wasn't as future-proof as hoped.

So let's go back to the old way of detecting MSVC, and then checking architecture from a list of little-endian architecture macros.

Quoted 8 lines

Note that MSVC does not treat ARM64 as bi-endian, so we can safely treat it as little-endian.

ACK!

Thank you so much,
Dscho

Quoted 21 lines
---
 compat/bswap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
compat/bswap.h +1 -2
index 72f225eaa8..512f6f4b99 100644
@@ -74,7 +74,7 @@ static inline uint64_t git_bswap64(uint64_t x)
 }
 #endif
 
-#elif defined(_MSC_VER)
+#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64) || defined(_M_ARM64))
 
 #include <stdlib.h>
 
--

2.29.2

#2 lore raw
Quoted 13 lines · Johannes Schindelin
Quoted 4 lines

...
So let's go back to the old way of detecting MSVC, and then checking architecture from a list of little-endian architecture macros.

Quoted 8 lines

Note that MSVC does not treat ARM64 as bi-endian, so we can safely treat it as little-endian.

Quoted 4 lines

ACK!

Thank you so much,
Dscho

Thanks, all.