[pulseaudio-commits] r1794 - in /branches/lennart/src/pulse: thread-mainloop.c timeval.c utf8.c utf8.h util.c util.h volume.c xmalloc.c
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Mon Sep 10 14:48:46 PDT 2007
Author: lennart
Date: Mon Sep 10 23:48:45 2007
New Revision: 1794
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1794&root=pulseaudio&view=rev
Log:
simple modernizations: s/assert/pa_assert
Modified:
branches/lennart/src/pulse/thread-mainloop.c
branches/lennart/src/pulse/timeval.c
branches/lennart/src/pulse/utf8.c
branches/lennart/src/pulse/utf8.h
branches/lennart/src/pulse/util.c
branches/lennart/src/pulse/util.h
branches/lennart/src/pulse/volume.c
branches/lennart/src/pulse/xmalloc.c
Modified: branches/lennart/src/pulse/thread-mainloop.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulse/thread-mainloop.c?rev=1794&root=pulseaudio&r1=1793&r2=1794&view=diff
==============================================================================
--- branches/lennart/src/pulse/thread-mainloop.c (original)
+++ branches/lennart/src/pulse/thread-mainloop.c Mon Sep 10 23:48:45 2007
@@ -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 "mainloop.h"
+#include <pulsecore/macro.h>
+
#include "thread-mainloop.h"
struct pa_threaded_mainloop {
@@ -63,7 +63,7 @@
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 @@
}
void pa_threaded_mainloop_free(pa_threaded_mainloop* m) {
- 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);
+
+ /* Make sure that this function is not called from the helper thread */
+ pa_assert((m->thread && !pa_thread_is_running(m->thread)) || !in_worker(m));
pa_threaded_mainloop_stop(m);
@@ -136,9 +136,9 @@
}
int pa_threaded_mainloop_start(pa_threaded_mainloop *m) {
- assert(m);
-
- assert(!m->thread || !pa_thread_is_running(m->thread));
+ pa_assert(m);
+
+ pa_assert(!m->thread || !pa_thread_is_running(m->thread));
if (!(m->thread = pa_thread_new(thread, m)))
return -1;
@@ -147,13 +147,13 @@
}
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_lock(pa_threaded_mainloop *m) {
- 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);
+
+ /* Make sure that this function is not called from the helper thread */
+ 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);
-
- /* 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);
+
+ /* Make sure that this function is not called from the helper thread */
+ 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_wait(pa_threaded_mainloop *m) {
- 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);
+
+ /* Make sure that this function is not called from the helper thread */
+ 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);
-
- /* 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);
+
+ /* Make sure that this function is not called from the helper thread */
+ 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);
}
Modified: branches/lennart/src/pulse/timeval.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulse/timeval.c?rev=1794&root=pulseaudio&r1=1793&r2=1794&view=diff
==============================================================================
--- branches/lennart/src/pulse/timeval.c (original)
+++ branches/lennart/src/pulse/timeval.c Mon Sep 10 23:48:45 2007
@@ -79,6 +79,7 @@
pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b) {
pa_usec_t r;
+
pa_assert(a);
pa_assert(b);
Modified: branches/lennart/src/pulse/utf8.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulse/utf8.c?rev=1794&root=pulseaudio&r1=1793&r2=1794&view=diff
==============================================================================
--- branches/lennart/src/pulse/utf8.c (original)
+++ branches/lennart/src/pulse/utf8.c Mon Sep 10 23:48:45 2007
@@ -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 @@
return 0;
if ((ch & 0xFFFE) == 0xFFFE) /* BOM (Byte Order Mark) */
return 0;
+
return 1;
}
@@ -96,6 +98,8 @@
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 @@
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 @@
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 @@
#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;
}
Modified: branches/lennart/src/pulse/utf8.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulse/utf8.h?rev=1794&root=pulseaudio&r1=1793&r2=1794&view=diff
==============================================================================
--- branches/lennart/src/pulse/utf8.h (original)
+++ branches/lennart/src/pulse/utf8.h Mon Sep 10 23:48:45 2007
@@ -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);
Modified: branches/lennart/src/pulse/util.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulse/util.c?rev=1794&root=pulseaudio&r1=1793&r2=1794&view=diff
==============================================================================
--- branches/lennart/src/pulse/util.c (original)
+++ branches/lennart/src/pulse/util.c Mon Sep 10 23:48:45 2007
@@ -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 @@
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_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 @@
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_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 @@
}
#endif
-#ifdef HAVE_READLINK
+#ifdef __linux__
{
int i;
char path[PATH_MAX];
@@ -206,13 +212,15 @@
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 @@
struct addrinfo *a, hints;
#endif
+ pa_assert(s);
+ pa_assert(l > 0);
+
if (!pa_get_host_name(hn, sizeof(hn)))
return NULL;
Modified: branches/lennart/src/pulse/util.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulse/util.h?rev=1794&root=pulseaudio&r1=1793&r2=1794&view=diff
==============================================================================
--- branches/lennart/src/pulse/util.h (original)
+++ branches/lennart/src/pulse/util.h Mon Sep 10 23:48:45 2007
@@ -52,7 +52,7 @@
/** 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);
Modified: branches/lennart/src/pulse/volume.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulse/volume.c?rev=1794&root=pulseaudio&r1=1793&r2=1794&view=diff
==============================================================================
--- branches/lennart/src/pulse/volume.c (original)
+++ branches/lennart/src/pulse/volume.c Mon Sep 10 23:48:45 2007
@@ -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 @@
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_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 @@
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 @@
/** 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 @@
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 @@
}
int pa_cvolume_valid(const pa_cvolume *v) {
- assert(v);
+ pa_assert(v);
if (v->channels <= 0 || v->channels > PA_CHANNELS_MAX)
return 0;
Modified: branches/lennart/src/pulse/xmalloc.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulse/xmalloc.c?rev=1794&root=pulseaudio&r1=1793&r2=1794&view=diff
==============================================================================
--- branches/lennart/src/pulse/xmalloc.c (original)
+++ branches/lennart/src/pulse/xmalloc.c Mon Sep 10 23:48:45 2007
@@ -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 @@
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_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_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();
More information about the pulseaudio-commits
mailing list