[PATCH 0/6] alsa-lib: Various portability fixes
Even though alsa-lib doesn't aim for ISO C conformance, hopefully these changes are uncontroversial enough to be considered anyway.
Michael Forney (6): Use __func__ instead of __FUNCTION__ List cases in range explicitly Don't return in a void function Make sure parameter qualifiers match between declaration and definition Remove unused empty struct Avoid pointer arithmetic on `void *`
aserver/aserver.c | 4 ++-- include/error.h | 8 ++++---- include/local.h | 4 ++-- src/conf.c | 22 ++++++++++++---------- src/pcm/pcm.c | 16 ++++++++-------- src/pcm/pcm_direct.h | 2 -- src/pcm/pcm_hw.c | 2 +- src/pcm/pcm_rate.c | 8 ++++---- src/pcm/pcm_share.c | 4 ++-- 9 files changed, 35 insertions(+), 35 deletions(-)
They are equivalent, but __func__ is in C99. __FUNCTION__ exists only for backwards compatibility with old gcc versions.
Signed-off-by: Michael Forney mforney@mforney.org --- aserver/aserver.c | 4 ++-- include/error.h | 8 ++++---- include/local.h | 4 ++-- src/pcm/pcm_share.c | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/aserver/aserver.c b/aserver/aserver.c index 6d20f330..28387021 100644 --- a/aserver/aserver.c +++ b/aserver/aserver.c @@ -39,13 +39,13 @@ char *command;
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95) #define ERROR(...) do {\ - fprintf(stderr, "%s %s:%i:(%s) ", command, __FILE__, __LINE__, __FUNCTION__); \ + fprintf(stderr, "%s %s:%i:(%s) ", command, __FILE__, __LINE__, __func__); \ fprintf(stderr, __VA_ARGS__); \ putc('\n', stderr); \ } while (0) #else #define ERROR(args...) do {\ - fprintf(stderr, "%s %s:%i:(%s) ", command, __FILE__, __LINE__, __FUNCTION__); \ + fprintf(stderr, "%s %s:%i:(%s) ", command, __FILE__, __LINE__, __func__); \ fprintf(stderr, ##args); \ putc('\n', stderr); \ } while (0) diff --git a/include/error.h b/include/error.h index 9a996aba..7239db85 100644 --- a/include/error.h +++ b/include/error.h @@ -61,11 +61,11 @@ extern snd_lib_error_handler_t snd_lib_error; extern int snd_lib_error_set_handler(snd_lib_error_handler_t handler);
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 95) -#define SNDERR(...) snd_lib_error(__FILE__, __LINE__, __FUNCTION__, 0, __VA_ARGS__) /**< Shows a sound error message. */ -#define SYSERR(...) snd_lib_error(__FILE__, __LINE__, __FUNCTION__, errno, __VA_ARGS__) /**< Shows a system error message (related to \c errno). */ +#define SNDERR(...) snd_lib_error(__FILE__, __LINE__, __func__, 0, __VA_ARGS__) /**< Shows a sound error message. */ +#define SYSERR(...) snd_lib_error(__FILE__, __LINE__, __func__, errno, __VA_ARGS__) /**< Shows a system error message (related to \c errno). */ #else -#define SNDERR(args...) snd_lib_error(__FILE__, __LINE__, __FUNCTION__, 0, ##args) /**< Shows a sound error message. */ -#define SYSERR(args...) snd_lib_error(__FILE__, __LINE__, __FUNCTION__, errno, ##args) /**< Shows a system error message (related to \c errno). */ +#define SNDERR(args...) snd_lib_error(__FILE__, __LINE__, __func__, 0, ##args) /**< Shows a sound error message. */ +#define SYSERR(args...) snd_lib_error(__FILE__, __LINE__, __func__, errno, ##args) /**< Shows a system error message (related to \c errno). */ #endif
/** } */ diff --git a/include/local.h b/include/local.h index e8390df5..bf19f0f8 100644 --- a/include/local.h +++ b/include/local.h @@ -244,8 +244,8 @@ size_t snd_strlcpy(char *dst, const char *src, size_t size); #ifndef NDEBUG #define CHECK_SANITY(x) x extern snd_lib_error_handler_t snd_err_msg; -#define SNDMSG(args...) snd_err_msg(__FILE__, __LINE__, __FUNCTION__, 0, ##args) -#define SYSMSG(args...) snd_err_msg(__FILE__, __LINE__, __FUNCTION__, errno, ##args) +#define SNDMSG(args...) snd_err_msg(__FILE__, __LINE__, __func__, 0, ##args) +#define SYSMSG(args...) snd_err_msg(__FILE__, __LINE__, __func__, errno, ##args) #else #define CHECK_SANITY(x) 0 /* not evaluated */ #define SNDMSG(args...) /* nop */ diff --git a/src/pcm/pcm_share.c b/src/pcm/pcm_share.c index 5a540c4f..bff9507d 100644 --- a/src/pcm/pcm_share.c +++ b/src/pcm/pcm_share.c @@ -54,11 +54,11 @@ char *snd_pcm_share_slaves_mutex_holder; do { \ int err = pthread_mutex_trylock(mutex); \ if (err < 0) { \ - fprintf(stderr, "lock " #mutex " is busy (%s): waiting in " __FUNCTION__ "\n", *(mutex##_holder)); \ + fprintf(stderr, "lock " #mutex " is busy (%s): waiting in " __func__ "\n", *(mutex##_holder)); \ pthread_mutex_lock(mutex); \ fprintf(stderr, "... got\n"); \ } \ - *(mutex##_holder) = __FUNCTION__; \ + *(mutex##_holder) = __func__; \ } while (0)
#define Pthread_mutex_unlock(mutex) \
Case ranges are a GNU extension, and provide only a slight readability improvement.
Signed-off-by: Michael Forney mforney@mforney.org --- src/conf.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/src/conf.c b/src/conf.c index 3e4b76a3..77fd0da5 100644 --- a/src/conf.c +++ b/src/conf.c @@ -888,7 +888,8 @@ static int get_quotedchar(input_t *input) return '\r'; case 'f': return '\f'; - case '0' ... '7': + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': { int num = c - '0'; int i = 1; @@ -1479,7 +1480,8 @@ static void string_print(char *str, int id, snd_output_t *out) } if (!id) { switch (*p) { - case '0' ... '9': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': case '-': goto quoted; } @@ -1488,8 +1490,6 @@ static void string_print(char *str, int id, snd_output_t *out) switch (*p) { case 0: goto nonquoted; - case 1 ... 31: - case 127 ... 255: case ' ': case '=': case ';': @@ -1501,6 +1501,8 @@ static void string_print(char *str, int id, snd_output_t *out) case '"': goto quoted; default: + if (*p <= 31 || *p >= 127) + goto quoted; p++; goto loop; } @@ -1542,12 +1544,11 @@ static void string_print(char *str, int id, snd_output_t *out) snd_output_putc(out, '\'); snd_output_putc(out, c); break; - case 32 ... ''' - 1: - case ''' + 1 ... 126: - snd_output_putc(out, c); - break; default: - snd_output_printf(out, "\%04o", c); + if (c >= 32 && c <= 126 && c != ''') + snd_output_putc(out, c); + else + snd_output_printf(out, "\%04o", c); break; } p++; @@ -4687,7 +4688,8 @@ static int parse_char(const char **ptr) case 'f': c = '\f'; break; - case '0' ... '7': + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': { int num = c - '0'; int i = 1;
A return statement with an expression in a function returning void is a constraint violation.
Signed-off-by: Michael Forney mforney@mforney.org --- src/pcm/pcm_hw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c index 77d4dae1..2028790e 100644 --- a/src/pcm/pcm_hw.c +++ b/src/pcm/pcm_hw.c @@ -1171,7 +1171,7 @@ static void __fill_chmap_ctl_id(snd_ctl_elem_id_t *id, int dev, int subdev, static void fill_chmap_ctl_id(snd_pcm_t *pcm, snd_ctl_elem_id_t *id) { snd_pcm_hw_t *hw = pcm->private_data; - return __fill_chmap_ctl_id(id, hw->device, hw->subdevice, pcm->stream); + __fill_chmap_ctl_id(id, hw->device, hw->subdevice, pcm->stream); }
static int is_chmap_type(int type)
Signed-off-by: Michael Forney mforney@mforney.org --- src/pcm/pcm.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c index fa51ca99..e0ceccc4 100644 --- a/src/pcm/pcm.c +++ b/src/pcm/pcm.c @@ -1997,7 +1997,7 @@ static const char *const snd_pcm_tstamp_type_names[] = { * \param stream PCM stream type * \return ascii name of PCM stream type */ -const char *snd_pcm_stream_name(snd_pcm_stream_t stream) +const char *snd_pcm_stream_name(const snd_pcm_stream_t stream) { if (stream > SND_PCM_STREAM_LAST) return NULL; @@ -2009,7 +2009,7 @@ const char *snd_pcm_stream_name(snd_pcm_stream_t stream) * \param acc PCM access type * \return ascii name of PCM access type */ -const char *snd_pcm_access_name(snd_pcm_access_t acc) +const char *snd_pcm_access_name(const snd_pcm_access_t acc) { if (acc > SND_PCM_ACCESS_LAST) return NULL; @@ -2021,7 +2021,7 @@ const char *snd_pcm_access_name(snd_pcm_access_t acc) * \param format PCM sample format * \return ascii name of PCM sample format */ -const char *snd_pcm_format_name(snd_pcm_format_t format) +const char *snd_pcm_format_name(const snd_pcm_format_t format) { if (format > SND_PCM_FORMAT_LAST) return NULL; @@ -2033,7 +2033,7 @@ const char *snd_pcm_format_name(snd_pcm_format_t format) * \param format PCM sample format * \return ascii description of PCM sample format */ -const char *snd_pcm_format_description(snd_pcm_format_t format) +const char *snd_pcm_format_description(const snd_pcm_format_t format) { if (format > SND_PCM_FORMAT_LAST) return NULL; @@ -2072,7 +2072,7 @@ snd_pcm_format_t snd_pcm_format_value(const char* name) * \param subformat PCM sample subformat * \return ascii name of PCM sample subformat */ -const char *snd_pcm_subformat_name(snd_pcm_subformat_t subformat) +const char *snd_pcm_subformat_name(const snd_pcm_subformat_t subformat) { if (subformat > SND_PCM_SUBFORMAT_LAST) return NULL; @@ -2084,7 +2084,7 @@ const char *snd_pcm_subformat_name(snd_pcm_subformat_t subformat) * \param subformat PCM sample subformat * \return ascii description of PCM sample subformat */ -const char *snd_pcm_subformat_description(snd_pcm_subformat_t subformat) +const char *snd_pcm_subformat_description(const snd_pcm_subformat_t subformat) { if (subformat > SND_PCM_SUBFORMAT_LAST) return NULL; @@ -2128,7 +2128,7 @@ link_warning(snd_pcm_xrun_mode_name, "Warning: xrun_mode is deprecated, consider * \param mode PCM tstamp mode * \return ascii name of PCM tstamp mode setting */ -const char *snd_pcm_tstamp_mode_name(snd_pcm_tstamp_t mode) +const char *snd_pcm_tstamp_mode_name(const snd_pcm_tstamp_t mode) { if (mode > SND_PCM_TSTAMP_LAST) return NULL; @@ -2152,7 +2152,7 @@ const char *snd_pcm_tstamp_type_name(snd_pcm_tstamp_type_t type) * \param state PCM state * \return ascii name of PCM state */ -const char *snd_pcm_state_name(snd_pcm_state_t state) +const char *snd_pcm_state_name(const snd_pcm_state_t state) { if (state > SND_PCM_STATE_LAST) return NULL;
Signed-off-by: Michael Forney mforney@mforney.org --- src/pcm/pcm_direct.h | 2 -- 1 file changed, 2 deletions(-)
diff --git a/src/pcm/pcm_direct.h b/src/pcm/pcm_direct.h index a71aab13..221edbe1 100644 --- a/src/pcm/pcm_direct.h +++ b/src/pcm/pcm_direct.h @@ -186,8 +186,6 @@ struct snd_pcm_direct { mix_areas_24_t *remix_areas_24; mix_areas_u8_t *remix_areas_u8; } dmix; - struct { - } dsnoop; struct { unsigned long long chn_mask; } dshare;
The pointer operand to the binary `+` operator must be to a complete object type.
Signed-off-by: Michael Forney mforney@mforney.org --- src/pcm/pcm_rate.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/pcm/pcm_rate.c b/src/pcm/pcm_rate.c index 5dc8a927..fdcaa8de 100644 --- a/src/pcm/pcm_rate.c +++ b/src/pcm/pcm_rate.c @@ -300,10 +300,10 @@ static int snd_pcm_rate_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params) rate->sareas = rate->pareas + channels; rate->sareas[0].addr = (char *)rate->pareas[0].addr + ((cwidth * channels * cinfo->period_size) / 8); for (chn = 0; chn < channels; chn++) { - rate->pareas[chn].addr = rate->pareas[0].addr + (cwidth * chn * cinfo->period_size) / 8; + rate->pareas[chn].addr = (char *)rate->pareas[0].addr + (cwidth * chn * cinfo->period_size) / 8; rate->pareas[chn].first = 0; rate->pareas[chn].step = cwidth; - rate->sareas[chn].addr = rate->sareas[0].addr + (swidth * chn * sinfo->period_size) / 8; + rate->sareas[chn].addr = (char *)rate->sareas[0].addr + (swidth * chn * sinfo->period_size) / 8; rate->sareas[chn].first = 0; rate->sareas[chn].step = swidth; } @@ -513,14 +513,14 @@ static void do_convert(const snd_pcm_channel_area_t *dst_areas, const int16_t *src; int16_t *dst; if (! rate->src_buf) - src = src_areas->addr + src_offset * 2 * channels; + src = (int16_t *)src_areas->addr + src_offset * channels; else { convert_to_s16(rate, rate->src_buf, src_areas, src_offset, src_frames, channels); src = rate->src_buf; } if (! rate->dst_buf) - dst = dst_areas->addr + dst_offset * 2 * channels; + dst = (int16_t *)dst_areas->addr + dst_offset * channels; else dst = rate->dst_buf; rate->ops.convert_s16(rate->obj, dst, dst_frames, src, src_frames);
participants (1)
-
Michael Forney