Skip to content

Commit c55ec3a

Browse files
sebastianasgitster
authored andcommitted
bswap.h: Move the overwriting of the ntohl*/ htonl* macros.
The top of that file contains optimized bswap32/64 only for a few little endian machines. Since the commit cited below there is one for every architecture supporting the __builtin_bswap* directives. Later in the file, the ntohl* macros are replaced with the bswap* macros should they be provided. Since they are now provided even on big endian machines they replace the nop with a swap. Move the ntohl*/ htonl* replacement once it is determined that it is a little architecture where the swap is performed. Fixes: 6547d1c ("bswap.h: add support for built-in bswap functions") Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b50795d commit c55ec3a

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

compat/bswap.h

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,6 @@ static inline uint64_t git_bswap64(uint64_t x)
9595

9696
#endif
9797

98-
#if defined(bswap32)
99-
100-
#undef ntohl
101-
#undef htonl
102-
#define ntohl(x) bswap32(x)
103-
#define htonl(x) bswap32(x)
104-
105-
#endif
106-
107-
#if defined(bswap64)
108-
109-
#undef ntohll
110-
#undef htonll
111-
#define ntohll(x) bswap64(x)
112-
#define htonll(x) bswap64(x)
113-
114-
#else
115-
11698
#undef ntohll
11799
#undef htonll
118100

@@ -151,10 +133,23 @@ static inline uint64_t git_bswap64(uint64_t x)
151133
# define ntohll(n) (n)
152134
# define htonll(n) (n)
153135
#else
154-
# define ntohll(n) default_bswap64(n)
155-
# define htonll(n) default_bswap64(n)
156-
#endif
157136

137+
# if defined(bswap32)
138+
# undef ntohl
139+
# undef htonl
140+
# define ntohl(x) bswap32(x)
141+
# define htonl(x) bswap32(x)
142+
# endif
143+
144+
# if defined(bswap64)
145+
# undef ntohll
146+
# undef htonll
147+
# define ntohll(x) bswap64(x)
148+
# define htonll(x) bswap64(x)
149+
# else
150+
# define ntohll(n) default_bswap64(n)
151+
# define htonll(n) default_bswap64(n)
152+
# endif
158153
#endif
159154

160155
static inline uint16_t get_be16(const void *ptr)

0 commit comments

Comments
 (0)