Re: [PATCH] block-sha1: Windows declares ntohl() in winsock2.h
- From
Linus Torvalds <torvalds@linux-foundation.org>
- Date
- Aug 18, 2009, 15:40 UTC
- Message-ID
- <alpine.LFD.2.01.0908180836440.3162@localhost.localdomain>
- In-Reply-To
- <7v4os5gs0p.fsf@alter.siamese.dyndns.org>
On Tue, 18 Aug 2009, Junio C Hamano wrote:
Show 19 quoted lines
> Sebastian Schuberth <sschuberth@gmail.com> writes: > > > On Tue, Aug 18, 2009 at 14:56, Artur Skawina<art.08.09@gmail.com> wrote: > > ... > >> I'd limit it to windows and any other ia32 platform that doesn't pick the > >> bswaps itself; as is, it just adds an unnecessary hidden gcc dependency. > >> > >> Hmm, it's actually a gcc-4.3+ dependency, so it won't even build w/ gcc 4.2; > >> something like this would be required: "(__GNUC__>=4 && __GNUC_MINOR__>=3)" . > > > > So, as you say the code makes no difference under Linux, would you be > > OK with just testing for GCC 4.3+, and not for Windows? That would get > > rid of the "hidden" GCC dependency and not make the preprocessor > > checks overly complex. Moreover, limiting my patch to any "platform > > that doesn't pick the bswaps itself" could possibly require > > maintenance on compiler / CRT updates. > > I would say that should be fine, but I'd let Linus and Nico to overrule me > on this if they have any input.
I'd suggest not using a gcc builtin, since if you're using gcc you might as well just use inline asm that has been around forever (unlike the builtin).
Just do:
#if defined(__GNUC__)
#define htonl(x) ({ unsigned int __res; \
__asm__("bswap %0":"=r" (__res):"0" (x)); \
__res; })
#define ntohl(x) htonl(x)
#endifor similar in the x86 section that does the rol/ror thing.
Linus