replaced mpd_likely/mpd_unlikely by G_LIKELY/G_UNLIKELY
We want to remove gcc.h eventually. This takes care of all the G_LIKELY/G_UNLIKELY macros.
This commit is contained in:
parent
4ca24f22f1
commit
2720585731
@ -110,7 +110,7 @@ char *pfx_dir(char *dst,
|
|||||||
const char *path, const size_t path_len,
|
const char *path, const size_t path_len,
|
||||||
const char *pfx, const size_t pfx_len)
|
const char *pfx, const size_t pfx_len)
|
||||||
{
|
{
|
||||||
if (mpd_unlikely((pfx_len + path_len + 1) >= MPD_PATH_MAX))
|
if (G_UNLIKELY((pfx_len + path_len + 1) >= MPD_PATH_MAX))
|
||||||
FATAL("Cannot prefix '%s' to '%s', PATH_MAX: %d\n",
|
FATAL("Cannot prefix '%s' to '%s', PATH_MAX: %d\n",
|
||||||
pfx, path, MPD_PATH_MAX);
|
pfx, path, MPD_PATH_MAX);
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
pcm_dither(void)
|
pcm_dither(void)
|
||||||
@ -40,9 +41,9 @@ pcm_dither(void)
|
|||||||
static int32_t
|
static int32_t
|
||||||
pcm_range(int32_t sample, unsigned bits)
|
pcm_range(int32_t sample, unsigned bits)
|
||||||
{
|
{
|
||||||
if (mpd_unlikely(sample < (-1 << (bits - 1))))
|
if (G_UNLIKELY(sample < (-1 << (bits - 1))))
|
||||||
return -1 << (bits - 1);
|
return -1 << (bits - 1);
|
||||||
if (mpd_unlikely(sample >= (1 << (bits - 1))))
|
if (G_UNLIKELY(sample >= (1 << (bits - 1))))
|
||||||
return (1 << (bits - 1)) - 1;
|
return (1 << (bits - 1)) - 1;
|
||||||
return sample;
|
return sample;
|
||||||
}
|
}
|
||||||
|
@ -19,13 +19,13 @@
|
|||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
#include "state_file.h"
|
#include "state_file.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "gcc.h"
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
#include "playlist.h"
|
#include "playlist.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "volume.h"
|
#include "volume.h"
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ void write_state_file(void)
|
|||||||
if (!sfpath)
|
if (!sfpath)
|
||||||
return;
|
return;
|
||||||
fp = fopen(sfpath, "w");
|
fp = fopen(sfpath, "w");
|
||||||
if (mpd_unlikely(!fp)) {
|
if (G_UNLIKELY(!fp)) {
|
||||||
ERROR("problems opening state file \"%s\" for writing: %s\n",
|
ERROR("problems opening state file \"%s\" for writing: %s\n",
|
||||||
sfpath, strerror(errno));
|
sfpath, strerror(errno));
|
||||||
return;
|
return;
|
||||||
@ -87,7 +87,7 @@ void read_state_file(void)
|
|||||||
FATAL("state file \"%s\" is not a regular file\n", sfpath);
|
FATAL("state file \"%s\" is not a regular file\n", sfpath);
|
||||||
|
|
||||||
while (!(fp = fopen(sfpath, "r")) && errno == EINTR);
|
while (!(fp = fopen(sfpath, "r")) && errno == EINTR);
|
||||||
if (mpd_unlikely(!fp)) {
|
if (G_UNLIKELY(!fp)) {
|
||||||
FATAL("problems opening state file \"%s\" for reading: %s\n",
|
FATAL("problems opening state file \"%s\" for reading: %s\n",
|
||||||
sfpath, strerror(errno));
|
sfpath, strerror(errno));
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ static id3_utf8_t * processID3FieldString (int is_id3v1, const id3_ucs4_t *ucs4,
|
|||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
isostr = id3_ucs4_latin1duplicate(ucs4);
|
isostr = id3_ucs4_latin1duplicate(ucs4);
|
||||||
if (mpd_unlikely(!isostr)) {
|
if (G_UNLIKELY(!isostr)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ static id3_utf8_t * processID3FieldString (int is_id3v1, const id3_ucs4_t *ucs4,
|
|||||||
free(isostr);
|
free(isostr);
|
||||||
} else {
|
} else {
|
||||||
utf8 = id3_ucs4_utf8duplicate(ucs4);
|
utf8 = id3_ucs4_utf8duplicate(ucs4);
|
||||||
if (mpd_unlikely(!utf8)) {
|
if (G_UNLIKELY(!utf8)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
src/utils.c
15
src/utils.c
@ -27,6 +27,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
@ -78,7 +79,7 @@ int ipv6Supported(void)
|
|||||||
mpd_malloc char *xstrdup(const char *s)
|
mpd_malloc char *xstrdup(const char *s)
|
||||||
{
|
{
|
||||||
char *ret = strdup(s);
|
char *ret = strdup(s);
|
||||||
if (mpd_unlikely(!ret))
|
if (G_UNLIKELY(!ret))
|
||||||
FATAL("OOM: strdup\n");
|
FATAL("OOM: strdup\n");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -89,10 +90,10 @@ mpd_malloc void *xmalloc(size_t size)
|
|||||||
{
|
{
|
||||||
void *ret;
|
void *ret;
|
||||||
|
|
||||||
assert(mpd_likely(size));
|
assert(G_LIKELY(size));
|
||||||
|
|
||||||
ret = malloc(size);
|
ret = malloc(size);
|
||||||
if (mpd_unlikely(!ret))
|
if (G_UNLIKELY(!ret))
|
||||||
FATAL("OOM: malloc\n");
|
FATAL("OOM: malloc\n");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -104,10 +105,10 @@ mpd_malloc void *xrealloc(void *ptr, size_t size)
|
|||||||
/* some C libraries return NULL when size == 0,
|
/* some C libraries return NULL when size == 0,
|
||||||
* make sure we get a free()-able pointer (free(NULL)
|
* make sure we get a free()-able pointer (free(NULL)
|
||||||
* doesn't work with all C libraries, either) */
|
* doesn't work with all C libraries, either) */
|
||||||
if (mpd_unlikely(!ret && !size))
|
if (G_UNLIKELY(!ret && !size))
|
||||||
ret = realloc(ptr, 1);
|
ret = realloc(ptr, 1);
|
||||||
|
|
||||||
if (mpd_unlikely(!ret))
|
if (G_UNLIKELY(!ret))
|
||||||
FATAL("OOM: realloc\n");
|
FATAL("OOM: realloc\n");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -116,10 +117,10 @@ mpd_malloc void *xcalloc(size_t nmemb, size_t size)
|
|||||||
{
|
{
|
||||||
void *ret;
|
void *ret;
|
||||||
|
|
||||||
assert(mpd_likely(nmemb && size));
|
assert(G_LIKELY(nmemb && size));
|
||||||
|
|
||||||
ret = calloc(nmemb, size);
|
ret = calloc(nmemb, size);
|
||||||
if (mpd_unlikely(!ret))
|
if (G_UNLIKELY(!ret))
|
||||||
FATAL("OOM: calloc\n");
|
FATAL("OOM: calloc\n");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -526,7 +526,7 @@ void read_sw_volume_state(FILE *fp)
|
|||||||
if (!g_str_has_prefix(buf, SW_VOLUME_STATE))
|
if (!g_str_has_prefix(buf, SW_VOLUME_STATE))
|
||||||
continue;
|
continue;
|
||||||
sv = strtol(buf + strlen(SW_VOLUME_STATE), &end, 10);
|
sv = strtol(buf + strlen(SW_VOLUME_STATE), &end, 10);
|
||||||
if (mpd_likely(!*end))
|
if (G_LIKELY(!*end))
|
||||||
changeSoftwareVolume(sv, 0);
|
changeSoftwareVolume(sv, 0);
|
||||||
else
|
else
|
||||||
ERROR("Can't parse software volume: %s\n", buf);
|
ERROR("Can't parse software volume: %s\n", buf);
|
||||||
|
Loading…
Reference in New Issue
Block a user