Message ID | 1456414292-55363-1-git-send-email-emaste@freebsd.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 02/25/2016 08:31 AM, Ed Maste wrote: > EAI_ADDRFAMILY is obsolete and FreeBSD/s netdb.h does not provide a > definition. > > Signed-off-by: Ed Maste <emaste@freebsd.org> > --- > tests/test-io-channel-socket.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/tests/test-io-channel-socket.c b/tests/test-io-channel-socket.c > index 0697363..f4dbd60 100644 > --- a/tests/test-io-channel-socket.c > +++ b/tests/test-io-channel-socket.c > @@ -63,7 +63,10 @@ static int check_protocol_support(bool *has_ipv4, bool *has_ipv6) > > gaierr = getaddrinfo("::1", NULL, &hints, &ai); > if (gaierr != 0) { > - if (gaierr == EAI_ADDRFAMILY || > + if ( > +#ifdef EAI_ADDRFAMILY > + gaierr == EAI_ADDRFAMILY || > +#endif > gaierr == EAI_FAMILY || I'm not the biggest-fan of mid-expression #ifdefs. Can we rewrite this to look more like: #ifndef EAI_ADDRFAMILY #define EAI_ADDRFAMILY EAI_FAMILY #endif and leave the conditional expression unchanged?
On Thu, Feb 25, 2016 at 09:29:02AM -0700, Eric Blake wrote: > On 02/25/2016 08:31 AM, Ed Maste wrote: > > EAI_ADDRFAMILY is obsolete and FreeBSD/s netdb.h does not provide a > > definition. > > > > Signed-off-by: Ed Maste <emaste@freebsd.org> > > --- > > tests/test-io-channel-socket.c | 5 ++++- > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > diff --git a/tests/test-io-channel-socket.c b/tests/test-io-channel-socket.c > > index 0697363..f4dbd60 100644 > > --- a/tests/test-io-channel-socket.c > > +++ b/tests/test-io-channel-socket.c > > @@ -63,7 +63,10 @@ static int check_protocol_support(bool *has_ipv4, bool *has_ipv6) > > > > gaierr = getaddrinfo("::1", NULL, &hints, &ai); > > if (gaierr != 0) { > > - if (gaierr == EAI_ADDRFAMILY || > > + if ( > > +#ifdef EAI_ADDRFAMILY > > + gaierr == EAI_ADDRFAMILY || > > +#endif > > gaierr == EAI_FAMILY || > > I'm not the biggest-fan of mid-expression #ifdefs. Can we rewrite this > to look more like: > > #ifndef EAI_ADDRFAMILY > #define EAI_ADDRFAMILY EAI_FAMILY > #endif > > and leave the conditional expression unchanged? I think that'll cause gcc 6 to whine about you checking the same value twice in the conditional, like how it complains that EWOULDBLOCK and EAGAIN are the same. Regards, Daniel
On 02/25/2016 09:32 AM, Daniel P. Berrange wrote: >>> + if ( >>> +#ifdef EAI_ADDRFAMILY >>> + gaierr == EAI_ADDRFAMILY || >>> +#endif >>> gaierr == EAI_FAMILY || >> >> I'm not the biggest-fan of mid-expression #ifdefs. Can we rewrite this >> to look more like: >> >> #ifndef EAI_ADDRFAMILY >> #define EAI_ADDRFAMILY EAI_FAMILY >> #endif >> >> and leave the conditional expression unchanged? > > I think that'll cause gcc 6 to whine about you checking the same > value twice in the conditional, like how it complains that EWOULDBLOCK > and EAGAIN are the same. Oh, right. That's annoying. What about: #ifndef EAI_ADDRFAMILY #define EAI_ADDRFAMILY 0 #endif if ((EAI_ADDRFAMILY && gaierr == EAIADDRFAMILY) || gaierr == EAI_FAMILY... to shut up gcc 6, while still hoisting the preprocessor logic outside of the expression?
On Thu, Feb 25, 2016 at 09:37:18AM -0700, Eric Blake wrote: > On 02/25/2016 09:32 AM, Daniel P. Berrange wrote: > > >>> + if ( > >>> +#ifdef EAI_ADDRFAMILY > >>> + gaierr == EAI_ADDRFAMILY || > >>> +#endif > >>> gaierr == EAI_FAMILY || > >> > >> I'm not the biggest-fan of mid-expression #ifdefs. Can we rewrite this > >> to look more like: > >> > >> #ifndef EAI_ADDRFAMILY > >> #define EAI_ADDRFAMILY EAI_FAMILY > >> #endif > >> > >> and leave the conditional expression unchanged? > > > > I think that'll cause gcc 6 to whine about you checking the same > > value twice in the conditional, like how it complains that EWOULDBLOCK > > and EAGAIN are the same. > > Oh, right. That's annoying. What about: > > #ifndef EAI_ADDRFAMILY > #define EAI_ADDRFAMILY 0 > #endif > > if ((EAI_ADDRFAMILY && gaierr == EAIADDRFAMILY) || > gaierr == EAI_FAMILY... > > to shut up gcc 6, while still hoisting the preprocessor logic outside of > the expression? To be honest, I think the preprocessor check inside the expression isn't a big deal and clearer than playing games like this. Regards, Daniel
On 25 February 2016 at 11:41, Daniel P. Berrange <berrange@redhat.com> wrote: > On Thu, Feb 25, 2016 at 09:37:18AM -0700, Eric Blake wrote: >> >> Oh, right. That's annoying. What about: >> >> #ifndef EAI_ADDRFAMILY >> #define EAI_ADDRFAMILY 0 >> #endif >> >> if ((EAI_ADDRFAMILY && gaierr == EAIADDRFAMILY) || >> gaierr == EAI_FAMILY... >> >> to shut up gcc 6, while still hoisting the preprocessor logic outside of >> the expression? > > To be honest, I think the preprocessor check inside the expression isn't > a big deal and clearer than playing games like this. I wasn't a fan of putting the preprocessor check inside the expression either, but no clear and concise alternative came to mind. I think it's easier to see both intent and effect with the preoprocessor check than with the above.
diff --git a/tests/test-io-channel-socket.c b/tests/test-io-channel-socket.c index 0697363..f4dbd60 100644 --- a/tests/test-io-channel-socket.c +++ b/tests/test-io-channel-socket.c @@ -63,7 +63,10 @@ static int check_protocol_support(bool *has_ipv4, bool *has_ipv6) gaierr = getaddrinfo("::1", NULL, &hints, &ai); if (gaierr != 0) { - if (gaierr == EAI_ADDRFAMILY || + if ( +#ifdef EAI_ADDRFAMILY + gaierr == EAI_ADDRFAMILY || +#endif gaierr == EAI_FAMILY || gaierr == EAI_NONAME) { *has_ipv6 = false;
EAI_ADDRFAMILY is obsolete and FreeBSD/s netdb.h does not provide a definition. Signed-off-by: Ed Maste <emaste@freebsd.org> --- tests/test-io-channel-socket.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)