diff options
Diffstat (limited to 'src/pulse')
| -rw-r--r-- | src/pulse/thread-mainloop.c | 44 | ||||
| -rw-r--r-- | src/pulse/timeval.c | 1 | ||||
| -rw-r--r-- | src/pulse/utf8.c | 19 | ||||
| -rw-r--r-- | src/pulse/utf8.h | 2 | ||||
| -rw-r--r-- | src/pulse/util.c | 31 | ||||
| -rw-r--r-- | src/pulse/util.h | 2 | ||||
| -rw-r--r-- | src/pulse/volume.c | 31 | ||||
| -rw-r--r-- | src/pulse/xmalloc.c | 14 | 
8 files changed, 83 insertions, 61 deletions
diff --git a/src/pulse/thread-mainloop.c b/src/pulse/thread-mainloop.c index 4f3cacc9..0ed54837 100644 --- a/src/pulse/thread-mainloop.c +++ b/src/pulse/thread-mainloop.c @@ -26,24 +26,24 @@  #include <config.h>  #endif -#include <assert.h>  #include <signal.h>  #include <stdio.h>  #ifdef HAVE_SYS_POLL_H  #include <sys/poll.h>  #else -#include "../pulsecore/poll.h" +#include <pulsecore/poll.h>  #endif  #include <pulse/xmalloc.h> +#include <pulse/mainloop.h>  #include <pulsecore/log.h>  #include <pulsecore/hashmap.h>  #include <pulsecore/thread.h>  #include <pulsecore/mutex.h> +#include <pulsecore/macro.h> -#include "mainloop.h"  #include "thread-mainloop.h"  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;      int r; -    assert(mutex); +    pa_assert(mutex);      /* Before entering poll() we unlock the mutex, so that       * 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) { -    assert(m); +    pa_assert(m);      /* 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); @@ -136,9 +136,9 @@ void pa_threaded_mainloop_free(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)))          return -1; @@ -147,13 +147,13 @@ int pa_threaded_mainloop_start(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))          return;      /* 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_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) { -    assert(m); +    pa_assert(m);      /* 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);  }  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 */ -    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);  }  void pa_threaded_mainloop_signal(pa_threaded_mainloop *m, int wait_for_accept) { -    assert(m); +    pa_assert(m);      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) { -    assert(m); +    pa_assert(m);      /* 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 ++;      pa_cond_wait(m->cond, m->mutex); -    assert(m->n_waiting > 0); +    pa_assert(m->n_waiting > 0);      m->n_waiting --;  }  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 */ -    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);  }  int pa_threaded_mainloop_get_retval(pa_threaded_mainloop *m) { -    assert(m); +    pa_assert(m);      return pa_mainloop_get_retval(m->real_mainloop);  }  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);  } diff --git a/src/pulse/timeval.c b/src/pulse/timeval.c index ba1128c4..44d74c94 100644 --- a/src/pulse/timeval.c +++ b/src/pulse/timeval.c @@ -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 r; +          pa_assert(a);      pa_assert(b); diff --git a/src/pulse/utf8.c b/src/pulse/utf8.c index a179b3fc..a02c5d1d 100644 --- a/src/pulse/utf8.c +++ b/src/pulse/utf8.c @@ -59,14 +59,15 @@  #include <iconv.h>  #endif +#include <pulse/xmalloc.h>  #include <pulsecore/macro.h>  #include "utf8.h" -#include "xmalloc.h"  #define FILTER_CHAR '_'  static inline int is_unicode_valid(uint32_t ch) { +          if (ch >= 0x110000) /* End of unicode space */          return 0;      if ((ch & 0xFFFFF800) == 0xD800) /* Reserved area for UTF-16 */ @@ -75,6 +76,7 @@ static inline int is_unicode_valid(uint32_t ch) {          return 0;      if ((ch & 0xFFFE) == 0xFFFE) /* BOM (Byte Order Mark) */          return 0; +          return 1;  } @@ -96,6 +98,8 @@ static char* utf8_validate(const char *str, char *output) {      int size;      uint8_t *o; +    pa_assert(str); +          o = (uint8_t*) output;      for (p = (const uint8_t*) str; *p; p++) {          if (*p < 128) { @@ -179,15 +183,15 @@ failure:      return NULL;  } -const char* pa_utf8_valid (const char *str) { +char* pa_utf8_valid (const char *str) {      return utf8_validate(str, NULL);  }  char* pa_utf8_filter (const char *str) {      char *new_str; +    pa_assert(str);      new_str = pa_xnew(char, strlen(str) + 1); -      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) {      char *new_str;      size_t len, inlen; -      iconv_t cd;      ICONV_CONST char *inbuf;      char *outbuf;      size_t res, inbytes, outbytes; +    pa_assert(str); +    pa_assert(to); +    pa_assert(from); +          cd = iconv_open(to, from);      if (cd == (iconv_t)-1)          return NULL;      inlen = len = strlen(str) + 1; -    new_str = pa_xmalloc(len); +    new_str = pa_xnew(char, len);      for (;;) {          inbuf = (ICONV_CONST char*) str; /* Brain dead prototype for iconv() */ @@ -248,10 +255,12 @@ char* pa_locale_to_utf8 (const char *str) {  #else  char* pa_utf8_to_locale (const char *str) { +    pa_assert(str);      return NULL;  }  char* pa_locale_to_utf8 (const char *str) { +    pa_assert(str);      return NULL;  } diff --git a/src/pulse/utf8.h b/src/pulse/utf8.h index ff8dc215..ea08840b 100644 --- a/src/pulse/utf8.h +++ b/src/pulse/utf8.h @@ -34,7 +34,7 @@  PA_C_DECL_BEGIN  /** 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() */  char *pa_utf8_filter(const char *str); diff --git a/src/pulse/util.c b/src/pulse/util.c index c4f2cf78..879b7bf1 100644 --- a/src/pulse/util.c +++ b/src/pulse/util.c @@ -56,11 +56,11 @@  #include <sys/prctl.h>  #endif -#include "../pulsecore/winsock.h" - +#include <pulsecore/winsock.h>  #include <pulsecore/core-error.h>  #include <pulsecore/log.h>  #include <pulsecore/core-util.h> +#include <pulsecore/macro.h>  #include "util.h" @@ -78,7 +78,8 @@ char *pa_get_user_name(char *s, size_t l) {      struct passwd pw, *r;  #endif -    assert(s && l > 0); +    pa_assert(s); +    pa_assert(l > 0);      if (!(p = getenv("USER")) && !(p = getenv("LOGNAME")) && !(p = getenv("USERNAME"))) {  #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) { -    assert(s && l > 0); + +    pa_assert(s); +    pa_assert(l > 0); +          if (gethostname(s, l) < 0) {          pa_log("gethostname(): %s", pa_cstrerror(errno));          return NULL;      } +          s[l-1] = 0;      return s;  } @@ -130,7 +135,8 @@ char *pa_get_home_dir(char *s, size_t l) {      struct passwd pw, *r;  #endif -    assert(s && l); +    pa_assert(s); +    pa_assert(l > 0);      if ((e = getenv("HOME")))          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) { -    assert(s); -    assert(l); +    pa_assert(s); +    pa_assert(l > 0);  #if defined(OS_IS_WIN32)      { @@ -171,7 +177,7 @@ char *pa_get_binary_name(char *s, size_t l) {      }  #endif -#ifdef HAVE_READLINK +#ifdef __linux__      {          int i;          char path[PATH_MAX]; @@ -206,13 +212,15 @@ char *pa_get_binary_name(char *s, size_t l) {      return NULL;  } -const char *pa_path_get_filename(const char *p) { +char *pa_path_get_filename(const char *p) {      char *fn; +    pa_assert(p); +      if ((fn = strrchr(p, PATH_SEP)))          return fn+1; -    return (const char*) p; +    return (char*) p;  }  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;  #endif +    pa_assert(s); +    pa_assert(l > 0); +          if (!pa_get_host_name(hn, sizeof(hn)))          return NULL; diff --git a/src/pulse/util.h b/src/pulse/util.h index 95bd86f3..764678e5 100644 --- a/src/pulse/util.h +++ b/src/pulse/util.h @@ -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   * component). */ -const char *pa_path_get_filename(const char *p); +char *pa_path_get_filename(const char *p);  /** Wait t milliseconds */  int pa_msleep(unsigned long t); diff --git a/src/pulse/volume.c b/src/pulse/volume.c index 8bba834d..3688b847 100644 --- a/src/pulse/volume.c +++ b/src/pulse/volume.c @@ -25,17 +25,18 @@  #include <config.h>  #endif -#include <assert.h>  #include <stdio.h>  #include <string.h>  #include <pulsecore/core-util.h> +#include <pulsecore/macro.h> +  #include "volume.h"  int pa_cvolume_equal(const pa_cvolume *a, const pa_cvolume *b) {      int i; -    assert(a); -    assert(b); +    pa_assert(a); +    pa_assert(b);      if (a->channels != b->channels)          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) {      int i; -    assert(a); -    assert(channels > 0); -    assert(channels <= PA_CHANNELS_MAX); +    pa_assert(a); +    pa_assert(channels > 0); +    pa_assert(channels <= PA_CHANNELS_MAX);      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) {      uint64_t sum = 0;      int i; -    assert(a); +    pa_assert(a);      for (i = 0; i < a->channels; 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;      char *e; -    assert(s); -    assert(l > 0); -    assert(c); +    pa_assert(s); +    pa_assert(l > 0); +    pa_assert(c);      *(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 */  int pa_cvolume_channels_equal_to(const pa_cvolume *a, pa_volume_t v) {      unsigned c; -    assert(a); +    pa_assert(a);      for (c = 0; c < a->channels; c++)          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) {      unsigned i; -    assert(dest); -    assert(a); -    assert(b); +    pa_assert(dest); +    pa_assert(a); +    pa_assert(b);      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) { -    assert(v); +    pa_assert(v);      if (v->channels <= 0 || v->channels > PA_CHANNELS_MAX)          return 0; diff --git a/src/pulse/xmalloc.c b/src/pulse/xmalloc.c index 1f0734c2..5348dda4 100644 --- a/src/pulse/xmalloc.c +++ b/src/pulse/xmalloc.c @@ -27,12 +27,12 @@  #include <stdlib.h>  #include <signal.h> -#include <assert.h>  #include <unistd.h>  #include <string.h>  #include <pulsecore/core-util.h>  #include <pulsecore/gccmacro.h> +#include <pulsecore/macro.h>  #include "xmalloc.h" @@ -60,8 +60,8 @@ static void oom(void) {  void* pa_xmalloc(size_t size) {      void *p; -    assert(size > 0); -    assert(size < MAX_ALLOC_SIZE); +    pa_assert(size > 0); +    pa_assert(size < MAX_ALLOC_SIZE);      if (!(p = malloc(size)))          oom(); @@ -71,8 +71,8 @@ void* pa_xmalloc(size_t size) {  void* pa_xmalloc0(size_t size) {      void *p; -    assert(size > 0); -    assert(size < MAX_ALLOC_SIZE); +    pa_assert(size > 0); +    pa_assert(size < MAX_ALLOC_SIZE);      if (!(p = calloc(1, size)))          oom(); @@ -82,8 +82,8 @@ void* pa_xmalloc0(size_t size) {  void *pa_xrealloc(void *ptr, size_t size) {      void *p; -    assert(size > 0); -    assert(size < MAX_ALLOC_SIZE); +    pa_assert(size > 0); +    pa_assert(size < MAX_ALLOC_SIZE);      if (!(p = realloc(ptr, size)))          oom();  | 
