mirror of
git://sourceware.org/git/glibc.git
synced 2025-03-06 20:58:33 +01:00
resolv: Replace __builtin_expect with __glibc_unlikely/__glibc_likely
This commit is contained in:
parent
3e2cf872a5
commit
bee05c9d58
6 changed files with 41 additions and 20 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
||||||
|
2017-04-19 Florian Weimer <fweimer@redhat.com>
|
||||||
|
|
||||||
|
* resolv/gai_suspend.c (gai_suspend): Replace __builtin_expect
|
||||||
|
with __glibc_likely.
|
||||||
|
* resolv/nss_dns/dns-host.c (getanswer_r, gaih_getanswer_slice):
|
||||||
|
Replace __builtin_expect with __glibc_unlikely.
|
||||||
|
* resolv/res_init.c (__res_vinit): Likewise.
|
||||||
|
* resolv/res_query.c (__libc_res_nquery): Likewise.
|
||||||
|
* resolv/res_send.c (__libc_res_nsend): Likewise.
|
||||||
|
|
||||||
2017-04-19 Florian Weimer <fweimer@redhat.com>
|
2017-04-19 Florian Weimer <fweimer@redhat.com>
|
||||||
|
|
||||||
[BZ #15722]
|
[BZ #15722]
|
||||||
|
|
|
@ -141,7 +141,7 @@ gai_suspend (const struct gaicb *const list[], int ent,
|
||||||
/* An error occurred. Possibly it's EINTR. We have to translate
|
/* An error occurred. Possibly it's EINTR. We have to translate
|
||||||
the timeout error report of `pthread_cond_timedwait' to the
|
the timeout error report of `pthread_cond_timedwait' to the
|
||||||
form expected from `gai_suspend'. */
|
form expected from `gai_suspend'. */
|
||||||
if (__builtin_expect (result, ETIMEDOUT) == ETIMEDOUT)
|
if (__glibc_likely (result == ETIMEDOUT))
|
||||||
result = EAI_AGAIN;
|
result = EAI_AGAIN;
|
||||||
else if (result == EINTR)
|
else if (result == EINTR)
|
||||||
result = EAI_INTR;
|
result = EAI_INTR;
|
||||||
|
|
|
@ -619,7 +619,7 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
|
||||||
ancount = ntohs (hp->ancount);
|
ancount = ntohs (hp->ancount);
|
||||||
qdcount = ntohs (hp->qdcount);
|
qdcount = ntohs (hp->qdcount);
|
||||||
cp = answer->buf + HFIXEDSZ;
|
cp = answer->buf + HFIXEDSZ;
|
||||||
if (__builtin_expect (qdcount, 1) != 1)
|
if (__glibc_unlikely (qdcount != 1))
|
||||||
{
|
{
|
||||||
*h_errnop = NO_RECOVERY;
|
*h_errnop = NO_RECOVERY;
|
||||||
return NSS_STATUS_UNAVAIL;
|
return NSS_STATUS_UNAVAIL;
|
||||||
|
@ -633,7 +633,7 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
|
||||||
packtmp, sizeof packtmp);
|
packtmp, sizeof packtmp);
|
||||||
if (n != -1 && __ns_name_ntop (packtmp, bp, linebuflen) == -1)
|
if (n != -1 && __ns_name_ntop (packtmp, bp, linebuflen) == -1)
|
||||||
{
|
{
|
||||||
if (__builtin_expect (errno, 0) == EMSGSIZE)
|
if (__glibc_unlikely (errno) == EMSGSIZE)
|
||||||
goto too_small;
|
goto too_small;
|
||||||
|
|
||||||
n = -1;
|
n = -1;
|
||||||
|
@ -642,13 +642,19 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
|
||||||
if (n > 0 && bp[0] == '.')
|
if (n > 0 && bp[0] == '.')
|
||||||
bp[0] = '\0';
|
bp[0] = '\0';
|
||||||
|
|
||||||
if (__builtin_expect (n < 0 || ((*name_ok) (bp) == 0 && (errno = EBADMSG)),
|
if (__glibc_unlikely (n < 0))
|
||||||
0))
|
|
||||||
{
|
{
|
||||||
*errnop = errno;
|
*errnop = errno;
|
||||||
*h_errnop = NO_RECOVERY;
|
*h_errnop = NO_RECOVERY;
|
||||||
return NSS_STATUS_UNAVAIL;
|
return NSS_STATUS_UNAVAIL;
|
||||||
}
|
}
|
||||||
|
if (__glibc_unlikely (name_ok (bp) == 0))
|
||||||
|
{
|
||||||
|
errno = EBADMSG;
|
||||||
|
*errnop = EBADMSG;
|
||||||
|
*h_errnop = NO_RECOVERY;
|
||||||
|
return NSS_STATUS_UNAVAIL;
|
||||||
|
}
|
||||||
cp += n + QFIXEDSZ;
|
cp += n + QFIXEDSZ;
|
||||||
|
|
||||||
if (qtype == T_A || qtype == T_AAAA)
|
if (qtype == T_A || qtype == T_AAAA)
|
||||||
|
@ -690,7 +696,7 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
|
||||||
packtmp, sizeof packtmp);
|
packtmp, sizeof packtmp);
|
||||||
if (n != -1 && __ns_name_ntop (packtmp, bp, linebuflen) == -1)
|
if (n != -1 && __ns_name_ntop (packtmp, bp, linebuflen) == -1)
|
||||||
{
|
{
|
||||||
if (__builtin_expect (errno, 0) == EMSGSIZE)
|
if (__glibc_unlikely (errno == EMSGSIZE))
|
||||||
goto too_small;
|
goto too_small;
|
||||||
|
|
||||||
n = -1;
|
n = -1;
|
||||||
|
@ -750,7 +756,7 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
|
||||||
/* Store alias. */
|
/* Store alias. */
|
||||||
*ap++ = bp;
|
*ap++ = bp;
|
||||||
n = strlen (bp) + 1; /* For the \0. */
|
n = strlen (bp) + 1; /* For the \0. */
|
||||||
if (__builtin_expect (n, 0) >= MAXHOSTNAMELEN)
|
if (__glibc_unlikely (n >= MAXHOSTNAMELEN))
|
||||||
{
|
{
|
||||||
++had_error;
|
++had_error;
|
||||||
continue;
|
continue;
|
||||||
|
@ -761,7 +767,7 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
|
||||||
n = strlen (tbuf) + 1; /* For the \0. */
|
n = strlen (tbuf) + 1; /* For the \0. */
|
||||||
if (__glibc_unlikely (n > linebuflen))
|
if (__glibc_unlikely (n > linebuflen))
|
||||||
goto too_small;
|
goto too_small;
|
||||||
if (__builtin_expect (n, 0) >= MAXHOSTNAMELEN)
|
if (__glibc_unlikely (n >= MAXHOSTNAMELEN))
|
||||||
{
|
{
|
||||||
++had_error;
|
++had_error;
|
||||||
continue;
|
continue;
|
||||||
|
@ -789,7 +795,7 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
|
||||||
n = strlen (tbuf) + 1; /* For the \0. */
|
n = strlen (tbuf) + 1; /* For the \0. */
|
||||||
if (__glibc_unlikely (n > linebuflen))
|
if (__glibc_unlikely (n > linebuflen))
|
||||||
goto too_small;
|
goto too_small;
|
||||||
if (__builtin_expect (n, 0) >= MAXHOSTNAMELEN)
|
if (__glibc_unlikely (n >= MAXHOSTNAMELEN))
|
||||||
{
|
{
|
||||||
++had_error;
|
++had_error;
|
||||||
continue;
|
continue;
|
||||||
|
@ -821,7 +827,7 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
|
||||||
packtmp, sizeof packtmp);
|
packtmp, sizeof packtmp);
|
||||||
if (n != -1 && __ns_name_ntop (packtmp, bp, linebuflen) == -1)
|
if (n != -1 && __ns_name_ntop (packtmp, bp, linebuflen) == -1)
|
||||||
{
|
{
|
||||||
if (__builtin_expect (errno, 0) == EMSGSIZE)
|
if (__glibc_unlikely (errno == EMSGSIZE))
|
||||||
goto too_small;
|
goto too_small;
|
||||||
|
|
||||||
n = -1;
|
n = -1;
|
||||||
|
@ -854,7 +860,7 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
|
||||||
return NSS_STATUS_SUCCESS;
|
return NSS_STATUS_SUCCESS;
|
||||||
case T_A:
|
case T_A:
|
||||||
case T_AAAA:
|
case T_AAAA:
|
||||||
if (__builtin_expect (strcasecmp (result->h_name, bp), 0) != 0)
|
if (__glibc_unlikely (strcasecmp (result->h_name, bp) != 0))
|
||||||
{
|
{
|
||||||
cp += n;
|
cp += n;
|
||||||
continue; /* XXX - had_error++ ? */
|
continue; /* XXX - had_error++ ? */
|
||||||
|
@ -975,7 +981,7 @@ gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname,
|
||||||
it later. */
|
it later. */
|
||||||
if (n != -1 && __ns_name_ntop (packtmp, buffer, buflen) == -1)
|
if (n != -1 && __ns_name_ntop (packtmp, buffer, buflen) == -1)
|
||||||
{
|
{
|
||||||
if (__builtin_expect (errno, 0) == EMSGSIZE)
|
if (__glibc_unlikely (errno == EMSGSIZE))
|
||||||
{
|
{
|
||||||
too_small:
|
too_small:
|
||||||
*errnop = ERANGE;
|
*errnop = ERANGE;
|
||||||
|
@ -986,13 +992,19 @@ gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname,
|
||||||
n = -1;
|
n = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (__builtin_expect (n < 0 || (res_hnok (buffer) == 0
|
if (__glibc_unlikely (n < 0))
|
||||||
&& (errno = EBADMSG)), 0))
|
|
||||||
{
|
{
|
||||||
*errnop = errno;
|
*errnop = errno;
|
||||||
*h_errnop = NO_RECOVERY;
|
*h_errnop = NO_RECOVERY;
|
||||||
return NSS_STATUS_UNAVAIL;
|
return NSS_STATUS_UNAVAIL;
|
||||||
}
|
}
|
||||||
|
if (__glibc_unlikely (res_hnok (buffer) == 0))
|
||||||
|
{
|
||||||
|
errno = EBADMSG;
|
||||||
|
*errnop = EBADMSG;
|
||||||
|
*h_errnop = NO_RECOVERY;
|
||||||
|
return NSS_STATUS_UNAVAIL;
|
||||||
|
}
|
||||||
cp += n + QFIXEDSZ;
|
cp += n + QFIXEDSZ;
|
||||||
|
|
||||||
int haveanswer = 0;
|
int haveanswer = 0;
|
||||||
|
@ -1014,7 +1026,7 @@ gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname,
|
||||||
if (n != -1 &&
|
if (n != -1 &&
|
||||||
(h_namelen = __ns_name_ntop (packtmp, buffer, buflen)) == -1)
|
(h_namelen = __ns_name_ntop (packtmp, buffer, buflen)) == -1)
|
||||||
{
|
{
|
||||||
if (__builtin_expect (errno, 0) == EMSGSIZE)
|
if (__glibc_unlikely (errno == EMSGSIZE))
|
||||||
goto too_small;
|
goto too_small;
|
||||||
|
|
||||||
n = -1;
|
n = -1;
|
||||||
|
@ -1128,8 +1140,7 @@ gaih_getanswer_slice (const querybuf *answer, int anslen, const char *qname,
|
||||||
buffer += pad;
|
buffer += pad;
|
||||||
buflen = buflen > pad ? buflen - pad : 0;
|
buflen = buflen > pad ? buflen - pad : 0;
|
||||||
|
|
||||||
if (__builtin_expect (buflen < sizeof (struct gaih_addrtuple),
|
if (__glibc_unlikely (buflen < sizeof (struct gaih_addrtuple)))
|
||||||
0))
|
|
||||||
goto too_small;
|
goto too_small;
|
||||||
|
|
||||||
*pat = (struct gaih_addrtuple *) buffer;
|
*pat = (struct gaih_addrtuple *) buffer;
|
||||||
|
|
|
@ -356,7 +356,7 @@ __res_vinit(res_state statp, int preinit) {
|
||||||
statp->nsort = nsort;
|
statp->nsort = nsort;
|
||||||
(void) fclose(fp);
|
(void) fclose(fp);
|
||||||
}
|
}
|
||||||
if (__builtin_expect(statp->nscount == 0, 0)) {
|
if (__glibc_unlikely (statp->nscount == 0)) {
|
||||||
statp->nsaddr.sin_addr = __inet_makeaddr(IN_LOOPBACKNET, 1);
|
statp->nsaddr.sin_addr = __inet_makeaddr(IN_LOOPBACKNET, 1);
|
||||||
statp->nsaddr.sin_family = AF_INET;
|
statp->nsaddr.sin_family = AF_INET;
|
||||||
statp->nsaddr.sin_port = htons(NAMESERVER_PORT);
|
statp->nsaddr.sin_port = htons(NAMESERVER_PORT);
|
||||||
|
|
|
@ -199,7 +199,7 @@ __libc_res_nquery(res_state statp,
|
||||||
nquery1 = n;
|
nquery1 = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (__builtin_expect (n <= 0, 0) && !use_malloc) {
|
if (__glibc_unlikely (n <= 0) && !use_malloc) {
|
||||||
/* Retry just in case res_nmkquery failed because of too
|
/* Retry just in case res_nmkquery failed because of too
|
||||||
short buffer. Shouldn't happen. */
|
short buffer. Shouldn't happen. */
|
||||||
bufsize = (type == T_QUERY_A_AND_AAAA ? 2 : 1) * MAXPACKET;
|
bufsize = (type == T_QUERY_A_AND_AAAA ? 2 : 1) * MAXPACKET;
|
||||||
|
|
|
@ -424,7 +424,7 @@ __libc_res_nsend(res_state statp, const u_char *buf, int buflen,
|
||||||
* Some resolvers want to even out the load on their nameservers.
|
* Some resolvers want to even out the load on their nameservers.
|
||||||
* Note that RES_BLAST overrides RES_ROTATE.
|
* Note that RES_BLAST overrides RES_ROTATE.
|
||||||
*/
|
*/
|
||||||
if (__builtin_expect ((statp->options & RES_ROTATE) != 0, 0)) {
|
if (__glibc_unlikely ((statp->options & RES_ROTATE) != 0)) {
|
||||||
struct sockaddr_in ina;
|
struct sockaddr_in ina;
|
||||||
struct sockaddr_in6 *inp;
|
struct sockaddr_in6 *inp;
|
||||||
int lastns = statp->nscount - 1;
|
int lastns = statp->nscount - 1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue