]> code.delx.au - pulseaudio/commitdiff
simple modernizations: s/assert/pa_assert
authorLennart Poettering <lennart@poettering.net>
Mon, 10 Sep 2007 21:48:45 +0000 (21:48 +0000)
committerLennart Poettering <lennart@poettering.net>
Mon, 10 Sep 2007 21:48:45 +0000 (21:48 +0000)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1794 fefdeb5f-60dc-0310-8127-8f9354f1896f

src/pulse/thread-mainloop.c
src/pulse/timeval.c
src/pulse/utf8.c
src/pulse/utf8.h
src/pulse/util.c
src/pulse/util.h
src/pulse/volume.c
src/pulse/xmalloc.c

index 4f3cacc9a12df2ec63af554771fded4bd118de9e..0ed54837055f0038740a10739248d01102bb59f0 100644 (file)
 #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);
 }
index ba1128c4c539a24b78e91b65a7777ca18bb186d8..44d74c949de489ac0223c82810e081f798ecfb0d 100644 (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 r;
+    
     pa_assert(a);
     pa_assert(b);
 
index a179b3fcdb963a269c6f76abbe8f16f2e5b4a63b..a02c5d1d8e98fbfd0353eb47105de84308b6ad0b 100644 (file)
 #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;
 }
 
index ff8dc215bc4ac147f9ec79dcf36a63567b4aca33..ea08840b9255125f2ec7b676b4dbbde5592cca53 100644 (file)
@@ -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);
index c4f2cf7860ce0fbd724bd7377d914aecc4bfeabf..879b7bf1265b5bd5e3c5bef7b877835848688dd0 100644 (file)
 #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;
 
index 95bd86f36320f9e50f46adf9638a0ef1a2cf3d07..764678e5caafc2258298e5de67f6d3a91984e8ae 100644 (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
  * 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);
index 8bba834d5bd833e5ae35764c9b6e16a8d6b4734a..3688b847c68aa3cda66fd47b7d902819096bf997 100644 (file)
 #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;
index 1f0734c242c127bdc06e9632904462ef8c738969..5348dda412c3037b0a4365e0b07fadc28909fe67 100644 (file)
 
 #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();