simple modernizations: s/assert/pa_assert

git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1794 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2007-09-10 21:48:45 +00:00
parent 662988650a
commit a6f8b813ae
8 changed files with 83 additions and 61 deletions

View file

@ -26,24 +26,24 @@
#include <config.h> #include <config.h>
#endif #endif
#include <assert.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#ifdef HAVE_SYS_POLL_H #ifdef HAVE_SYS_POLL_H
#include <sys/poll.h> #include <sys/poll.h>
#else #else
#include "../pulsecore/poll.h" #include <pulsecore/poll.h>
#endif #endif
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulse/mainloop.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/hashmap.h> #include <pulsecore/hashmap.h>
#include <pulsecore/thread.h> #include <pulsecore/thread.h>
#include <pulsecore/mutex.h> #include <pulsecore/mutex.h>
#include <pulsecore/macro.h>
#include "mainloop.h"
#include "thread-mainloop.h" #include "thread-mainloop.h"
struct pa_threaded_mainloop { struct pa_threaded_mainloop {
@ -63,7 +63,7 @@ static int poll_func(struct pollfd *ufds, unsigned long nfds, int timeout, void
pa_mutex *mutex = userdata; pa_mutex *mutex = userdata;
int r; int r;
assert(mutex); pa_assert(mutex);
/* Before entering poll() we unlock the mutex, so that /* Before entering poll() we unlock the mutex, so that
* avahi_simple_poll_quit() can succeed from another thread. */ * avahi_simple_poll_quit() can succeed from another thread. */
@ -116,10 +116,10 @@ pa_threaded_mainloop *pa_threaded_mainloop_new(void) {
} }
void pa_threaded_mainloop_free(pa_threaded_mainloop* m) { void pa_threaded_mainloop_free(pa_threaded_mainloop* m) {
assert(m); pa_assert(m);
/* Make sure that this function is not called from the helper thread */ /* Make sure that this function is not called from the helper thread */
assert((m->thread && !pa_thread_is_running(m->thread)) || !in_worker(m)); pa_assert((m->thread && !pa_thread_is_running(m->thread)) || !in_worker(m));
pa_threaded_mainloop_stop(m); pa_threaded_mainloop_stop(m);
@ -136,9 +136,9 @@ void pa_threaded_mainloop_free(pa_threaded_mainloop* m) {
} }
int pa_threaded_mainloop_start(pa_threaded_mainloop *m) { int pa_threaded_mainloop_start(pa_threaded_mainloop *m) {
assert(m); pa_assert(m);
assert(!m->thread || !pa_thread_is_running(m->thread)); pa_assert(!m->thread || !pa_thread_is_running(m->thread));
if (!(m->thread = pa_thread_new(thread, m))) if (!(m->thread = pa_thread_new(thread, m)))
return -1; return -1;
@ -147,13 +147,13 @@ int pa_threaded_mainloop_start(pa_threaded_mainloop *m) {
} }
void pa_threaded_mainloop_stop(pa_threaded_mainloop *m) { void pa_threaded_mainloop_stop(pa_threaded_mainloop *m) {
assert(m); pa_assert(m);
if (!m->thread || !pa_thread_is_running(m->thread)) if (!m->thread || !pa_thread_is_running(m->thread))
return; return;
/* Make sure that this function is not called from the helper thread */ /* Make sure that this function is not called from the helper thread */
assert(!in_worker(m)); pa_assert(!in_worker(m));
pa_mutex_lock(m->mutex); pa_mutex_lock(m->mutex);
pa_mainloop_quit(m->real_mainloop, 0); pa_mainloop_quit(m->real_mainloop, 0);
@ -163,25 +163,25 @@ void pa_threaded_mainloop_stop(pa_threaded_mainloop *m) {
} }
void pa_threaded_mainloop_lock(pa_threaded_mainloop *m) { void pa_threaded_mainloop_lock(pa_threaded_mainloop *m) {
assert(m); pa_assert(m);
/* Make sure that this function is not called from the helper thread */ /* Make sure that this function is not called from the helper thread */
assert(!m->thread || !pa_thread_is_running(m->thread) || !in_worker(m)); pa_assert(!m->thread || !pa_thread_is_running(m->thread) || !in_worker(m));
pa_mutex_lock(m->mutex); pa_mutex_lock(m->mutex);
} }
void pa_threaded_mainloop_unlock(pa_threaded_mainloop *m) { void pa_threaded_mainloop_unlock(pa_threaded_mainloop *m) {
assert(m); pa_assert(m);
/* Make sure that this function is not called from the helper thread */ /* Make sure that this function is not called from the helper thread */
assert(!m->thread || !pa_thread_is_running(m->thread) || !in_worker(m)); pa_assert(!m->thread || !pa_thread_is_running(m->thread) || !in_worker(m));
pa_mutex_unlock(m->mutex); pa_mutex_unlock(m->mutex);
} }
void pa_threaded_mainloop_signal(pa_threaded_mainloop *m, int wait_for_accept) { void pa_threaded_mainloop_signal(pa_threaded_mainloop *m, int wait_for_accept) {
assert(m); pa_assert(m);
pa_cond_signal(m->cond, 1); pa_cond_signal(m->cond, 1);
@ -190,36 +190,36 @@ void pa_threaded_mainloop_signal(pa_threaded_mainloop *m, int wait_for_accept) {
} }
void pa_threaded_mainloop_wait(pa_threaded_mainloop *m) { void pa_threaded_mainloop_wait(pa_threaded_mainloop *m) {
assert(m); pa_assert(m);
/* Make sure that this function is not called from the helper thread */ /* Make sure that this function is not called from the helper thread */
assert(!m->thread || !pa_thread_is_running(m->thread) || !in_worker(m)); pa_assert(!m->thread || !pa_thread_is_running(m->thread) || !in_worker(m));
m->n_waiting ++; m->n_waiting ++;
pa_cond_wait(m->cond, m->mutex); pa_cond_wait(m->cond, m->mutex);
assert(m->n_waiting > 0); pa_assert(m->n_waiting > 0);
m->n_waiting --; m->n_waiting --;
} }
void pa_threaded_mainloop_accept(pa_threaded_mainloop *m) { void pa_threaded_mainloop_accept(pa_threaded_mainloop *m) {
assert(m); pa_assert(m);
/* Make sure that this function is not called from the helper thread */ /* Make sure that this function is not called from the helper thread */
assert(!m->thread || !pa_thread_is_running(m->thread) || !in_worker(m)); pa_assert(!m->thread || !pa_thread_is_running(m->thread) || !in_worker(m));
pa_cond_signal(m->accept_cond, 0); pa_cond_signal(m->accept_cond, 0);
} }
int pa_threaded_mainloop_get_retval(pa_threaded_mainloop *m) { int pa_threaded_mainloop_get_retval(pa_threaded_mainloop *m) {
assert(m); pa_assert(m);
return pa_mainloop_get_retval(m->real_mainloop); return pa_mainloop_get_retval(m->real_mainloop);
} }
pa_mainloop_api* pa_threaded_mainloop_get_api(pa_threaded_mainloop*m) { pa_mainloop_api* pa_threaded_mainloop_get_api(pa_threaded_mainloop*m) {
assert(m); pa_assert(m);
return pa_mainloop_get_api(m->real_mainloop); return pa_mainloop_get_api(m->real_mainloop);
} }

View file

@ -79,6 +79,7 @@ struct timeval *pa_gettimeofday(struct timeval *tv) {
pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b) { pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b) {
pa_usec_t r; pa_usec_t r;
pa_assert(a); pa_assert(a);
pa_assert(b); pa_assert(b);

View file

@ -59,14 +59,15 @@
#include <iconv.h> #include <iconv.h>
#endif #endif
#include <pulse/xmalloc.h>
#include <pulsecore/macro.h> #include <pulsecore/macro.h>
#include "utf8.h" #include "utf8.h"
#include "xmalloc.h"
#define FILTER_CHAR '_' #define FILTER_CHAR '_'
static inline int is_unicode_valid(uint32_t ch) { static inline int is_unicode_valid(uint32_t ch) {
if (ch >= 0x110000) /* End of unicode space */ if (ch >= 0x110000) /* End of unicode space */
return 0; return 0;
if ((ch & 0xFFFFF800) == 0xD800) /* Reserved area for UTF-16 */ if ((ch & 0xFFFFF800) == 0xD800) /* Reserved area for UTF-16 */
@ -75,6 +76,7 @@ static inline int is_unicode_valid(uint32_t ch) {
return 0; return 0;
if ((ch & 0xFFFE) == 0xFFFE) /* BOM (Byte Order Mark) */ if ((ch & 0xFFFE) == 0xFFFE) /* BOM (Byte Order Mark) */
return 0; return 0;
return 1; return 1;
} }
@ -96,6 +98,8 @@ static char* utf8_validate(const char *str, char *output) {
int size; int size;
uint8_t *o; uint8_t *o;
pa_assert(str);
o = (uint8_t*) output; o = (uint8_t*) output;
for (p = (const uint8_t*) str; *p; p++) { for (p = (const uint8_t*) str; *p; p++) {
if (*p < 128) { if (*p < 128) {
@ -179,15 +183,15 @@ failure:
return NULL; return NULL;
} }
const char* pa_utf8_valid (const char *str) { char* pa_utf8_valid (const char *str) {
return utf8_validate(str, NULL); return utf8_validate(str, NULL);
} }
char* pa_utf8_filter (const char *str) { char* pa_utf8_filter (const char *str) {
char *new_str; char *new_str;
pa_assert(str);
new_str = pa_xnew(char, strlen(str) + 1); new_str = pa_xnew(char, strlen(str) + 1);
return utf8_validate(str, new_str); return utf8_validate(str, new_str);
} }
@ -196,18 +200,21 @@ char* pa_utf8_filter (const char *str) {
static char* iconv_simple(const char *str, const char *to, const char *from) { static char* iconv_simple(const char *str, const char *to, const char *from) {
char *new_str; char *new_str;
size_t len, inlen; size_t len, inlen;
iconv_t cd; iconv_t cd;
ICONV_CONST char *inbuf; ICONV_CONST char *inbuf;
char *outbuf; char *outbuf;
size_t res, inbytes, outbytes; size_t res, inbytes, outbytes;
pa_assert(str);
pa_assert(to);
pa_assert(from);
cd = iconv_open(to, from); cd = iconv_open(to, from);
if (cd == (iconv_t)-1) if (cd == (iconv_t)-1)
return NULL; return NULL;
inlen = len = strlen(str) + 1; inlen = len = strlen(str) + 1;
new_str = pa_xmalloc(len); new_str = pa_xnew(char, len);
for (;;) { for (;;) {
inbuf = (ICONV_CONST char*) str; /* Brain dead prototype for iconv() */ inbuf = (ICONV_CONST char*) str; /* Brain dead prototype for iconv() */
@ -248,10 +255,12 @@ char* pa_locale_to_utf8 (const char *str) {
#else #else
char* pa_utf8_to_locale (const char *str) { char* pa_utf8_to_locale (const char *str) {
pa_assert(str);
return NULL; return NULL;
} }
char* pa_locale_to_utf8 (const char *str) { char* pa_locale_to_utf8 (const char *str) {
pa_assert(str);
return NULL; return NULL;
} }

View file

@ -34,7 +34,7 @@
PA_C_DECL_BEGIN PA_C_DECL_BEGIN
/** Test if the specified strings qualifies as valid UTF8. Return the string if so, otherwise NULL */ /** Test if the specified strings qualifies as valid UTF8. Return the string if so, otherwise NULL */
const char *pa_utf8_valid(const char *str); char *pa_utf8_valid(const char *str);
/** Filter all invalid UTF8 characters from the specified string, returning a new fully UTF8 valid string. Don't forget to free the returned string with pa_xfree() */ /** Filter all invalid UTF8 characters from the specified string, returning a new fully UTF8 valid string. Don't forget to free the returned string with pa_xfree() */
char *pa_utf8_filter(const char *str); char *pa_utf8_filter(const char *str);

View file

@ -56,11 +56,11 @@
#include <sys/prctl.h> #include <sys/prctl.h>
#endif #endif
#include "../pulsecore/winsock.h" #include <pulsecore/winsock.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/macro.h>
#include "util.h" #include "util.h"
@ -78,7 +78,8 @@ char *pa_get_user_name(char *s, size_t l) {
struct passwd pw, *r; struct passwd pw, *r;
#endif #endif
assert(s && l > 0); pa_assert(s);
pa_assert(l > 0);
if (!(p = getenv("USER")) && !(p = getenv("LOGNAME")) && !(p = getenv("USERNAME"))) { if (!(p = getenv("USER")) && !(p = getenv("LOGNAME")) && !(p = getenv("USERNAME"))) {
#ifdef HAVE_PWD_H #ifdef HAVE_PWD_H
@ -113,11 +114,15 @@ char *pa_get_user_name(char *s, size_t l) {
} }
char *pa_get_host_name(char *s, size_t l) { char *pa_get_host_name(char *s, size_t l) {
assert(s && l > 0);
pa_assert(s);
pa_assert(l > 0);
if (gethostname(s, l) < 0) { if (gethostname(s, l) < 0) {
pa_log("gethostname(): %s", pa_cstrerror(errno)); pa_log("gethostname(): %s", pa_cstrerror(errno));
return NULL; return NULL;
} }
s[l-1] = 0; s[l-1] = 0;
return s; return s;
} }
@ -130,7 +135,8 @@ char *pa_get_home_dir(char *s, size_t l) {
struct passwd pw, *r; struct passwd pw, *r;
#endif #endif
assert(s && l); pa_assert(s);
pa_assert(l > 0);
if ((e = getenv("HOME"))) if ((e = getenv("HOME")))
return pa_strlcpy(s, e, l); return pa_strlcpy(s, e, l);
@ -159,8 +165,8 @@ char *pa_get_home_dir(char *s, size_t l) {
char *pa_get_binary_name(char *s, size_t l) { char *pa_get_binary_name(char *s, size_t l) {
assert(s); pa_assert(s);
assert(l); pa_assert(l > 0);
#if defined(OS_IS_WIN32) #if defined(OS_IS_WIN32)
{ {
@ -171,7 +177,7 @@ char *pa_get_binary_name(char *s, size_t l) {
} }
#endif #endif
#ifdef HAVE_READLINK #ifdef __linux__
{ {
int i; int i;
char path[PATH_MAX]; char path[PATH_MAX];
@ -206,13 +212,15 @@ char *pa_get_binary_name(char *s, size_t l) {
return NULL; return NULL;
} }
const char *pa_path_get_filename(const char *p) { char *pa_path_get_filename(const char *p) {
char *fn; char *fn;
pa_assert(p);
if ((fn = strrchr(p, PATH_SEP))) if ((fn = strrchr(p, PATH_SEP)))
return fn+1; return fn+1;
return (const char*) p; return (char*) p;
} }
char *pa_get_fqdn(char *s, size_t l) { char *pa_get_fqdn(char *s, size_t l) {
@ -221,6 +229,9 @@ char *pa_get_fqdn(char *s, size_t l) {
struct addrinfo *a, hints; struct addrinfo *a, hints;
#endif #endif
pa_assert(s);
pa_assert(l > 0);
if (!pa_get_host_name(hn, sizeof(hn))) if (!pa_get_host_name(hn, sizeof(hn)))
return NULL; return NULL;

View file

@ -52,7 +52,7 @@ char *pa_get_binary_name(char *s, size_t l);
/** Return a pointer to the filename inside a path (which is the last /** Return a pointer to the filename inside a path (which is the last
* component). */ * component). */
const char *pa_path_get_filename(const char *p); char *pa_path_get_filename(const char *p);
/** Wait t milliseconds */ /** Wait t milliseconds */
int pa_msleep(unsigned long t); int pa_msleep(unsigned long t);

View file

@ -25,17 +25,18 @@
#include <config.h> #include <config.h>
#endif #endif
#include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/macro.h>
#include "volume.h" #include "volume.h"
int pa_cvolume_equal(const pa_cvolume *a, const pa_cvolume *b) { int pa_cvolume_equal(const pa_cvolume *a, const pa_cvolume *b) {
int i; int i;
assert(a); pa_assert(a);
assert(b); pa_assert(b);
if (a->channels != b->channels) if (a->channels != b->channels)
return 0; return 0;
@ -50,9 +51,9 @@ int pa_cvolume_equal(const pa_cvolume *a, const pa_cvolume *b) {
pa_cvolume* pa_cvolume_set(pa_cvolume *a, unsigned channels, pa_volume_t v) { pa_cvolume* pa_cvolume_set(pa_cvolume *a, unsigned channels, pa_volume_t v) {
int i; int i;
assert(a); pa_assert(a);
assert(channels > 0); pa_assert(channels > 0);
assert(channels <= PA_CHANNELS_MAX); pa_assert(channels <= PA_CHANNELS_MAX);
a->channels = channels; a->channels = channels;
@ -65,7 +66,7 @@ pa_cvolume* pa_cvolume_set(pa_cvolume *a, unsigned channels, pa_volume_t v) {
pa_volume_t pa_cvolume_avg(const pa_cvolume *a) { pa_volume_t pa_cvolume_avg(const pa_cvolume *a) {
uint64_t sum = 0; uint64_t sum = 0;
int i; int i;
assert(a); pa_assert(a);
for (i = 0; i < a->channels; i++) for (i = 0; i < a->channels; i++)
sum += a->values[i]; sum += a->values[i];
@ -119,9 +120,9 @@ char *pa_cvolume_snprint(char *s, size_t l, const pa_cvolume *c) {
int first = 1; int first = 1;
char *e; char *e;
assert(s); pa_assert(s);
assert(l > 0); pa_assert(l > 0);
assert(c); pa_assert(c);
*(e = s) = 0; *(e = s) = 0;
@ -141,7 +142,7 @@ char *pa_cvolume_snprint(char *s, size_t l, const pa_cvolume *c) {
/** Return non-zero if the volume of all channels is equal to the specified value */ /** Return non-zero if the volume of all channels is equal to the specified value */
int pa_cvolume_channels_equal_to(const pa_cvolume *a, pa_volume_t v) { int pa_cvolume_channels_equal_to(const pa_cvolume *a, pa_volume_t v) {
unsigned c; unsigned c;
assert(a); pa_assert(a);
for (c = 0; c < a->channels; c++) for (c = 0; c < a->channels; c++)
if (a->values[c] != v) if (a->values[c] != v)
@ -153,9 +154,9 @@ int pa_cvolume_channels_equal_to(const pa_cvolume *a, pa_volume_t v) {
pa_cvolume *pa_sw_cvolume_multiply(pa_cvolume *dest, const pa_cvolume *a, const pa_cvolume *b) { pa_cvolume *pa_sw_cvolume_multiply(pa_cvolume *dest, const pa_cvolume *a, const pa_cvolume *b) {
unsigned i; unsigned i;
assert(dest); pa_assert(dest);
assert(a); pa_assert(a);
assert(b); pa_assert(b);
for (i = 0; i < a->channels && i < b->channels && i < PA_CHANNELS_MAX; i++) { for (i = 0; i < a->channels && i < b->channels && i < PA_CHANNELS_MAX; i++) {
@ -170,7 +171,7 @@ pa_cvolume *pa_sw_cvolume_multiply(pa_cvolume *dest, const pa_cvolume *a, const
} }
int pa_cvolume_valid(const pa_cvolume *v) { int pa_cvolume_valid(const pa_cvolume *v) {
assert(v); pa_assert(v);
if (v->channels <= 0 || v->channels > PA_CHANNELS_MAX) if (v->channels <= 0 || v->channels > PA_CHANNELS_MAX)
return 0; return 0;

View file

@ -27,12 +27,12 @@
#include <stdlib.h> #include <stdlib.h>
#include <signal.h> #include <signal.h>
#include <assert.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/gccmacro.h> #include <pulsecore/gccmacro.h>
#include <pulsecore/macro.h>
#include "xmalloc.h" #include "xmalloc.h"
@ -60,8 +60,8 @@ static void oom(void) {
void* pa_xmalloc(size_t size) { void* pa_xmalloc(size_t size) {
void *p; void *p;
assert(size > 0); pa_assert(size > 0);
assert(size < MAX_ALLOC_SIZE); pa_assert(size < MAX_ALLOC_SIZE);
if (!(p = malloc(size))) if (!(p = malloc(size)))
oom(); oom();
@ -71,8 +71,8 @@ void* pa_xmalloc(size_t size) {
void* pa_xmalloc0(size_t size) { void* pa_xmalloc0(size_t size) {
void *p; void *p;
assert(size > 0); pa_assert(size > 0);
assert(size < MAX_ALLOC_SIZE); pa_assert(size < MAX_ALLOC_SIZE);
if (!(p = calloc(1, size))) if (!(p = calloc(1, size)))
oom(); oom();
@ -82,8 +82,8 @@ void* pa_xmalloc0(size_t size) {
void *pa_xrealloc(void *ptr, size_t size) { void *pa_xrealloc(void *ptr, size_t size) {
void *p; void *p;
assert(size > 0); pa_assert(size > 0);
assert(size < MAX_ALLOC_SIZE); pa_assert(size < MAX_ALLOC_SIZE);
if (!(p = realloc(ptr, size))) if (!(p = realloc(ptr, size)))
oom(); oom();