remaining s/assert/pa_assert/ and refcnt.h modernizations

git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1809 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2007-09-11 20:48:33 +00:00
parent 2988c3d9fb
commit d5bedbcd98
59 changed files with 967 additions and 724 deletions

View file

@ -26,7 +26,6 @@
#endif #endif
#include <string.h> #include <string.h>
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <getopt.h> #include <getopt.h>
@ -36,6 +35,7 @@
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/strbuf.h> #include <pulsecore/strbuf.h>
#include <pulsecore/macro.h>
#include "cmdline.h" #include "cmdline.h"
@ -100,6 +100,8 @@ static struct option long_options[] = {
void pa_cmdline_help(const char *argv0) { void pa_cmdline_help(const char *argv0) {
const char *e; const char *e;
pa_assert(argv0);
if ((e = strrchr(argv0, '/'))) if ((e = strrchr(argv0, '/')))
e++; e++;
else else
@ -154,7 +156,10 @@ void pa_cmdline_help(const char *argv0) {
int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d) { int pa_cmdline_parse(pa_daemon_conf *conf, int argc, char *const argv [], int *d) {
pa_strbuf *buf = NULL; pa_strbuf *buf = NULL;
int c; int c;
assert(conf && argc && argv);
pa_assert(conf);
pa_assert(argc > 0);
pa_assert(argv);
buf = pa_strbuf_new(); buf = pa_strbuf_new();

View file

@ -30,6 +30,7 @@
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include "cpulimit.h" #include "cpulimit.h"
@ -38,7 +39,6 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
@ -92,23 +92,18 @@ static enum {
/* Reset the SIGXCPU timer to the next t seconds */ /* Reset the SIGXCPU timer to the next t seconds */
static void reset_cpu_time(int t) { static void reset_cpu_time(int t) {
int r;
long n; long n;
struct rlimit rl; struct rlimit rl;
struct rusage ru; struct rusage ru;
/* Get the current CPU time of the current process */ /* Get the current CPU time of the current process */
r = getrusage(RUSAGE_SELF, &ru); pa_assert_se(getrusage(RUSAGE_SELF, &ru) >= 0);
assert(r >= 0);
n = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec + t; n = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec + t;
pa_assert_se(getrlimit(RLIMIT_CPU, &rl) >= 0);
r = getrlimit(RLIMIT_CPU, &rl);
assert(r >= 0);
rl.rlim_cur = n; rl.rlim_cur = n;
r = setrlimit(RLIMIT_CPU, &rl); pa_assert_se(setrlimit(RLIMIT_CPU, &rl) >= 0);
assert(r >= 0);
} }
/* A simple, thread-safe puts() work-alike */ /* A simple, thread-safe puts() work-alike */
@ -118,7 +113,7 @@ static void write_err(const char *p) {
/* The signal handler, called on every SIGXCPU */ /* The signal handler, called on every SIGXCPU */
static void signal_handler(int sig) { static void signal_handler(int sig) {
assert(sig == SIGXCPU); pa_assert(sig == SIGXCPU);
if (phase == PHASE_IDLE) { if (phase == PHASE_IDLE) {
time_t now; time_t now;
@ -160,7 +155,12 @@ static void signal_handler(int sig) {
/* Callback for IO events on the FIFO */ /* Callback for IO events on the FIFO */
static void callback(pa_mainloop_api*m, pa_io_event*e, int fd, pa_io_event_flags_t f, void *userdata) { static void callback(pa_mainloop_api*m, pa_io_event*e, int fd, pa_io_event_flags_t f, void *userdata) {
char c; char c;
assert(m && e && f == PA_IO_EVENT_INPUT && e == io_event && fd == the_pipe[0]); pa_assert(m);
pa_assert(e);
pa_assert(f == PA_IO_EVENT_INPUT);
pa_assert(e == io_event);
pa_assert(fd == the_pipe[0]);
pa_read(the_pipe[0], &c, sizeof(c), NULL); pa_read(the_pipe[0], &c, sizeof(c), NULL);
m->quit(m, 1); /* Quit the main loop */ m->quit(m, 1); /* Quit the main loop */
} }
@ -168,7 +168,13 @@ static void callback(pa_mainloop_api*m, pa_io_event*e, int fd, pa_io_event_flags
/* Initializes CPU load limiter */ /* Initializes CPU load limiter */
int pa_cpu_limit_init(pa_mainloop_api *m) { int pa_cpu_limit_init(pa_mainloop_api *m) {
struct sigaction sa; struct sigaction sa;
assert(m && !api && !io_event && the_pipe[0] == -1 && the_pipe[1] == -1 && !installed);
pa_assert(m);
pa_assert(!api);
pa_assert(!io_event);
pa_assert(the_pipe[0] == -1);
pa_assert(the_pipe[1] == -1);
pa_assert(!installed);
time(&last_time); time(&last_time);
@ -208,10 +214,9 @@ int pa_cpu_limit_init(pa_mainloop_api *m) {
/* Shutdown CPU load limiter */ /* Shutdown CPU load limiter */
void pa_cpu_limit_done(void) { void pa_cpu_limit_done(void) {
int r;
if (io_event) { if (io_event) {
assert(api); pa_assert(api);
api->io_free(io_event); api->io_free(io_event);
io_event = NULL; io_event = NULL;
api = NULL; api = NULL;
@ -224,8 +229,7 @@ void pa_cpu_limit_done(void) {
the_pipe[0] = the_pipe[1] = -1; the_pipe[0] = the_pipe[1] = -1;
if (installed) { if (installed) {
r = sigaction(SIGXCPU, &sigaction_prev, NULL); pa_assert_se(sigaction(SIGXCPU, &sigaction_prev, NULL) >= 0);
assert(r >= 0);
installed = 0; installed = 0;
} }
} }

View file

@ -28,7 +28,6 @@
#include <string.h> #include <string.h>
#include <getopt.h> #include <getopt.h>
#include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <ltdl.h> #include <ltdl.h>
@ -36,19 +35,23 @@
#include <pulsecore/modinfo.h> #include <pulsecore/modinfo.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/macro.h>
#include "dumpmodules.h" #include "dumpmodules.h"
#define PREFIX "module-" #define PREFIX "module-"
static void short_info(const char *name, PA_GCC_UNUSED const char *path, pa_modinfo *i) { static void short_info(const char *name, PA_GCC_UNUSED const char *path, pa_modinfo *i) {
assert(name && i); pa_assert(name);
pa_assert(i);
printf("%-40s%s\n", name, i->description ? i->description : "n/a"); printf("%-40s%s\n", name, i->description ? i->description : "n/a");
} }
static void long_info(const char *name, const char *path, pa_modinfo *i) { static void long_info(const char *name, const char *path, pa_modinfo *i) {
static int nl = 0; static int nl = 0;
assert(name && i); pa_assert(name);
pa_assert(i);
if (nl) if (nl)
printf("\n"); printf("\n");
@ -77,6 +80,8 @@ static void long_info(const char *name, const char *path, pa_modinfo *i) {
static void show_info(const char *name, const char *path, void (*info)(const char *name, const char *path, pa_modinfo*i)) { static void show_info(const char *name, const char *path, void (*info)(const char *name, const char *path, pa_modinfo*i)) {
pa_modinfo *i; pa_modinfo *i;
pa_assert(name);
if ((i = pa_modinfo_get_by_name(path ? path : name))) { if ((i = pa_modinfo_get_by_name(path ? path : name))) {
info(name, path, i); info(name, path, i);
pa_modinfo_free(i); pa_modinfo_free(i);
@ -122,6 +127,8 @@ static int callback(const char *path, lt_ptr data) {
} }
void pa_dump_modules(pa_daemon_conf *c, int argc, char * const argv[]) { void pa_dump_modules(pa_daemon_conf *c, int argc, char * const argv[]) {
pa_assert(c);
if (argc > 0) { if (argc > 0) {
int i; int i;
for (i = 0; i < argc; i++) for (i = 0; i < argc; i++)

View file

@ -33,7 +33,6 @@
#include <stdio.h> #include <stdio.h>
#include <signal.h> #include <signal.h>
#include <stddef.h> #include <stddef.h>
#include <assert.h>
#include <ltdl.h> #include <ltdl.h>
#include <limits.h> #include <limits.h>
#include <fcntl.h> #include <fcntl.h>
@ -287,7 +286,7 @@ static int create_runtime_dir(void) {
static void set_one_rlimit(const pa_rlimit *r, int resource, const char *name) { static void set_one_rlimit(const pa_rlimit *r, int resource, const char *name) {
struct rlimit rl; struct rlimit rl;
assert(r); pa_assert(r);
if (!r->is_set) if (!r->is_set)
return; return;
@ -498,7 +497,7 @@ int main(int argc, char *argv[]) {
goto finish; goto finish;
default: default:
assert(conf->cmd == PA_CMD_DAEMON); pa_assert(conf->cmd == PA_CMD_DAEMON);
} }
if (real_root && !conf->system_instance) { if (real_root && !conf->system_instance) {
@ -630,8 +629,7 @@ int main(int argc, char *argv[]) {
pa_rtsig_configure(SIGRTMIN+10, SIGRTMAX); pa_rtsig_configure(SIGRTMIN+10, SIGRTMAX);
mainloop = pa_mainloop_new(); pa_assert_se(mainloop = pa_mainloop_new());
assert(mainloop);
if (!(c = pa_core_new(pa_mainloop_get_api(mainloop), !conf->disable_shm))) { if (!(c = pa_core_new(pa_mainloop_get_api(mainloop), !conf->disable_shm))) {
pa_log("pa_core_new() failed."); pa_log("pa_core_new() failed.");
@ -664,9 +662,7 @@ int main(int argc, char *argv[]) {
#endif #endif
#ifdef OS_IS_WIN32 #ifdef OS_IS_WIN32
timer = pa_mainloop_get_api(mainloop)->time_new( pa_assert_se(timer = pa_mainloop_get_api(mainloop)->time_new(pa_mainloop_get_api(mainloop), pa_gettimeofday(&tv), message_cb, NULL));
pa_mainloop_get_api(mainloop), pa_gettimeofday(&tv), message_cb, NULL);
assert(timer);
#endif #endif
if (conf->daemonize) if (conf->daemonize)
@ -674,10 +670,8 @@ int main(int argc, char *argv[]) {
oil_init(); oil_init();
if (!conf->no_cpu_limit) { if (!conf->no_cpu_limit)
r = pa_cpu_limit_init(pa_mainloop_get_api(mainloop)); pa_assert_se(pa_cpu_limit_init(pa_mainloop_get_api(mainloop)) == 0);
assert(r == 0);
}
buf = pa_strbuf_new(); buf = pa_strbuf_new();
if (conf->default_script_file) if (conf->default_script_file)

View file

@ -88,7 +88,7 @@ static void io_cb(pa_mainloop_api*a, pa_io_event* e, PA_GCC_UNUSED int fd, pa_io
} }
} }
assert(i != fdl->num_fds); pa_assert(i != fdl->num_fds);
if ((err = snd_mixer_poll_descriptors_revents(fdl->mixer, fdl->work_fds, fdl->num_fds, &revents)) < 0) { if ((err = snd_mixer_poll_descriptors_revents(fdl->mixer, fdl->work_fds, fdl->num_fds, &revents)) < 0) {
pa_log_error("Unable to get poll revent: %s", snd_strerror(err)); pa_log_error("Unable to get poll revent: %s", snd_strerror(err));

View file

@ -26,7 +26,6 @@
#include <config.h> #include <config.h>
#endif #endif
#include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <asoundlib.h> #include <asoundlib.h>
@ -817,7 +816,7 @@ int pa__init(pa_module*m) {
pa_log_info("Using %u fragments of size %lu bytes.", nfrags, (long unsigned) u->fragment_size); pa_log_info("Using %u fragments of size %lu bytes.", nfrags, (long unsigned) u->fragment_size);
if (u->mixer_handle) { if (u->mixer_handle) {
assert(u->mixer_elem); pa_assert(u->mixer_elem);
if (snd_mixer_selem_has_capture_volume(u->mixer_elem)) { if (snd_mixer_selem_has_capture_volume(u->mixer_elem)) {
int i; int i;

View file

@ -26,7 +26,6 @@
#endif #endif
#include <stdio.h> #include <stdio.h>
#include <assert.h>
#include <unistd.h> #include <unistd.h>
#include <pulsecore/module.h> #include <pulsecore/module.h>
@ -35,6 +34,7 @@
#include <pulsecore/sioman.h> #include <pulsecore/sioman.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/modargs.h> #include <pulsecore/modargs.h>
#include <pulsecore/macro.h>
#include "module-cli-symdef.h" #include "module-cli-symdef.h"
@ -51,8 +51,8 @@ static const char* const valid_modargs[] = {
static void eof_and_unload_cb(pa_cli*c, void *userdata) { static void eof_and_unload_cb(pa_cli*c, void *userdata) {
pa_module *m = userdata; pa_module *m = userdata;
assert(c); pa_assert(c);
assert(m); pa_assert(m);
pa_module_unload_request(m); pa_module_unload_request(m);
} }
@ -60,8 +60,8 @@ static void eof_and_unload_cb(pa_cli*c, void *userdata) {
static void eof_and_exit_cb(pa_cli*c, void *userdata) { static void eof_and_exit_cb(pa_cli*c, void *userdata) {
pa_module *m = userdata; pa_module *m = userdata;
assert(c); pa_assert(c);
assert(m); pa_assert(m);
m->core->mainloop->quit(m->core->mainloop, 0); m->core->mainloop->quit(m->core->mainloop, 0);
} }
@ -71,7 +71,7 @@ int pa__init(pa_module*m) {
pa_modargs *ma; pa_modargs *ma;
int exit_on_eof = 0; int exit_on_eof = 0;
assert(m); pa_assert(m);
if (m->core->running_as_daemon) { if (m->core->running_as_daemon) {
pa_log_info("Running as daemon, refusing to load this module."); pa_log_info("Running as daemon, refusing to load this module.");
@ -113,7 +113,7 @@ fail:
} }
void pa__done(pa_module*m) { void pa__done(pa_module*m) {
assert(m); pa_assert(m);
if (m->core->running_as_daemon == 0) { if (m->core->running_as_daemon == 0) {
pa_cli_free(m->userdata); pa_cli_free(m->userdata);

View file

@ -28,7 +28,6 @@
#endif #endif
#include <stdio.h> #include <stdio.h>
#include <assert.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
@ -44,6 +43,7 @@
#include <pulsecore/modargs.h> #include <pulsecore/modargs.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/macro.h>
#include "module-detect-symdef.h" #include "module-detect-symdef.h"

View file

@ -26,12 +26,12 @@
#endif #endif
#include <stdio.h> #include <stdio.h>
#include <assert.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <lirc/lirc_client.h>
#include <stdlib.h> #include <stdlib.h>
#include <lirc/lirc_client.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulsecore/module.h> #include <pulsecore/module.h>
@ -39,6 +39,7 @@
#include <pulsecore/namereg.h> #include <pulsecore/namereg.h>
#include <pulsecore/sink.h> #include <pulsecore/sink.h>
#include <pulsecore/modargs.h> #include <pulsecore/modargs.h>
#include <pulsecore/macro.h>
#include "module-lirc-symdef.h" #include "module-lirc-symdef.h"

View file

@ -26,7 +26,6 @@
#endif #endif
#include <stdio.h> #include <stdio.h>
#include <assert.h>
#include <math.h> #include <math.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>

View file

@ -26,7 +26,6 @@
#endif #endif
#include <stdio.h> #include <stdio.h>
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>

View file

@ -25,8 +25,6 @@
#include <config.h> #include <config.h>
#endif #endif
#include <assert.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>

View file

@ -25,7 +25,6 @@
#include <config.h> #include <config.h>
#endif #endif
#include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <pulsecore/gccmacro.h> #include <pulsecore/gccmacro.h>

View file

@ -26,7 +26,6 @@
#include <config.h> #include <config.h>
#endif #endif
#include <assert.h>
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>
#include <stdio.h> #include <stdio.h>

View file

@ -38,7 +38,6 @@
struct authkey_data { struct authkey_data {
PA_REFCNT_DECLARE; PA_REFCNT_DECLARE;
int ref;
size_t length; size_t length;
}; };

View file

@ -28,7 +28,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>

View file

@ -27,7 +27,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>

View file

@ -26,7 +26,6 @@
#include <config.h> #include <config.h>
#endif #endif
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -60,6 +59,7 @@
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/macro.h>
#include "core-scache.h" #include "core-scache.h"
@ -68,7 +68,10 @@
static void timeout_callback(pa_mainloop_api *m, pa_time_event*e, PA_GCC_UNUSED const struct timeval *tv, void *userdata) { static void timeout_callback(pa_mainloop_api *m, pa_time_event*e, PA_GCC_UNUSED const struct timeval *tv, void *userdata) {
pa_core *c = userdata; pa_core *c = userdata;
struct timeval ntv; struct timeval ntv;
assert(c && c->mainloop == m && c->scache_auto_unload_event == e);
pa_assert(c);
pa_assert(c->mainloop == m);
pa_assert(c->scache_auto_unload_event == e);
pa_scache_unload_unused(c); pa_scache_unload_unused(c);
@ -78,7 +81,8 @@ static void timeout_callback(pa_mainloop_api *m, pa_time_event*e, PA_GCC_UNUSED
} }
static void free_entry(pa_scache_entry *e) { static void free_entry(pa_scache_entry *e) {
assert(e); pa_assert(e);
pa_namereg_unregister(e->core, e->name); pa_namereg_unregister(e->core, e->name);
pa_subscription_post(e->core, PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE|PA_SUBSCRIPTION_EVENT_REMOVE, e->index); pa_subscription_post(e->core, PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE|PA_SUBSCRIPTION_EVENT_REMOVE, e->index);
pa_xfree(e->name); pa_xfree(e->name);
@ -90,7 +94,9 @@ static void free_entry(pa_scache_entry *e) {
static pa_scache_entry* scache_add_item(pa_core *c, const char *name) { static pa_scache_entry* scache_add_item(pa_core *c, const char *name) {
pa_scache_entry *e; pa_scache_entry *e;
assert(c && name);
pa_assert(c);
pa_assert(name);
if ((e = pa_namereg_get(c, name, PA_NAMEREG_SAMPLE, 0))) { if ((e = pa_namereg_get(c, name, PA_NAMEREG_SAMPLE, 0))) {
if (e->memchunk.memblock) if (e->memchunk.memblock)
@ -98,11 +104,11 @@ static pa_scache_entry* scache_add_item(pa_core *c, const char *name) {
pa_xfree(e->filename); pa_xfree(e->filename);
assert(e->core == c); pa_assert(e->core == c);
pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE|PA_SUBSCRIPTION_EVENT_CHANGE, e->index); pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE|PA_SUBSCRIPTION_EVENT_CHANGE, e->index);
} else { } else {
e = pa_xmalloc(sizeof(pa_scache_entry)); e = pa_xnew(pa_scache_entry, 1);
if (!pa_namereg_register(c, name, PA_NAMEREG_SAMPLE, e, 1)) { if (!pa_namereg_register(c, name, PA_NAMEREG_SAMPLE, e, 1)) {
pa_xfree(e); pa_xfree(e);
@ -114,7 +120,7 @@ static pa_scache_entry* scache_add_item(pa_core *c, const char *name) {
if (!c->scache) { if (!c->scache) {
c->scache = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); c->scache = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
assert(c->scache); pa_assert(c->scache);
} }
pa_idxset_put(c->scache, e, &e->index); pa_idxset_put(c->scache, e, &e->index);
@ -139,7 +145,9 @@ static pa_scache_entry* scache_add_item(pa_core *c, const char *name) {
int pa_scache_add_item(pa_core *c, const char *name, const pa_sample_spec *ss, const pa_channel_map *map, const pa_memchunk *chunk, uint32_t *idx) { int pa_scache_add_item(pa_core *c, const char *name, const pa_sample_spec *ss, const pa_channel_map *map, const pa_memchunk *chunk, uint32_t *idx) {
pa_scache_entry *e; pa_scache_entry *e;
char st[PA_SAMPLE_SPEC_SNPRINT_MAX]; char st[PA_SAMPLE_SPEC_SNPRINT_MAX];
assert(c && name);
pa_assert(c);
pa_assert(name);
if (chunk && chunk->length > PA_SCACHE_ENTRY_SIZE_MAX) if (chunk && chunk->length > PA_SCACHE_ENTRY_SIZE_MAX)
return -1; return -1;
@ -164,7 +172,7 @@ int pa_scache_add_item(pa_core *c, const char *name, const pa_sample_spec *ss, c
if (idx) if (idx)
*idx = e->index; *idx = e->index;
pa_log_debug("created sample \"%s\" (#%d), %lu bytes with sample spec %s", pa_log_debug("Created sample \"%s\" (#%d), %lu bytes with sample spec %s",
name, e->index, (unsigned long) e->memchunk.length, name, e->index, (unsigned long) e->memchunk.length,
pa_sample_spec_snprint(st, sizeof(st), &e->sample_spec)); pa_sample_spec_snprint(st, sizeof(st), &e->sample_spec));
@ -184,6 +192,10 @@ int pa_scache_add_file(pa_core *c, const char *name, const char *filename, uint3
filename = buf; filename = buf;
#endif #endif
pa_assert(c);
pa_assert(name);
pa_assert(filename);
if (pa_sound_file_load(c->mempool, filename, &ss, &map, &chunk) < 0) if (pa_sound_file_load(c->mempool, filename, &ss, &map, &chunk) < 0)
return -1; return -1;
@ -203,7 +215,9 @@ int pa_scache_add_file_lazy(pa_core *c, const char *name, const char *filename,
filename = buf; filename = buf;
#endif #endif
assert(c && name); pa_assert(c);
pa_assert(name);
pa_assert(filename);
if (!(e = scache_add_item(c, name))) if (!(e = scache_add_item(c, name)))
return -1; return -1;
@ -226,15 +240,17 @@ int pa_scache_add_file_lazy(pa_core *c, const char *name, const char *filename,
int pa_scache_remove_item(pa_core *c, const char *name) { int pa_scache_remove_item(pa_core *c, const char *name) {
pa_scache_entry *e; pa_scache_entry *e;
assert(c && name);
pa_assert(c);
pa_assert(name);
if (!(e = pa_namereg_get(c, name, PA_NAMEREG_SAMPLE, 0))) if (!(e = pa_namereg_get(c, name, PA_NAMEREG_SAMPLE, 0)))
return -1; return -1;
if (pa_idxset_remove_by_data(c->scache, e, NULL) != e) if (pa_idxset_remove_by_data(c->scache, e, NULL) != e)
assert(0); pa_assert(0);
pa_log_debug("removed sample \"%s\"", name); pa_log_debug("Removed sample \"%s\"", name);
free_entry(e); free_entry(e);
@ -243,12 +259,13 @@ int pa_scache_remove_item(pa_core *c, const char *name) {
static void free_cb(void *p, PA_GCC_UNUSED void *userdata) { static void free_cb(void *p, PA_GCC_UNUSED void *userdata) {
pa_scache_entry *e = p; pa_scache_entry *e = p;
assert(e); pa_assert(e);
free_entry(e); free_entry(e);
} }
void pa_scache_free(pa_core *c) { void pa_scache_free(pa_core *c) {
assert(c); pa_assert(c);
if (c->scache) { if (c->scache) {
pa_idxset_free(c->scache, free_cb, NULL); pa_idxset_free(c->scache, free_cb, NULL);
@ -264,9 +281,9 @@ int pa_scache_play_item(pa_core *c, const char *name, pa_sink *sink, pa_volume_t
char *t; char *t;
pa_cvolume r; pa_cvolume r;
assert(c); pa_assert(c);
assert(name); pa_assert(name);
assert(sink); pa_assert(sink);
if (!(e = pa_namereg_get(c, name, PA_NAMEREG_SAMPLE, 1))) if (!(e = pa_namereg_get(c, name, PA_NAMEREG_SAMPLE, 1)))
return -1; return -1;
@ -284,7 +301,7 @@ int pa_scache_play_item(pa_core *c, const char *name, pa_sink *sink, pa_volume_t
if (!e->memchunk.memblock) if (!e->memchunk.memblock)
return -1; return -1;
pa_log_debug("playing sample \"%s\" on \"%s\"", name, sink->name); pa_log_debug("Playing sample \"%s\" on \"%s\"", name, sink->name);
t = pa_sprintf_malloc("sample:%s", name); t = pa_sprintf_malloc("sample:%s", name);
@ -318,7 +335,9 @@ int pa_scache_play_item_by_name(pa_core *c, const char *name, const char*sink_na
const char * pa_scache_get_name_by_id(pa_core *c, uint32_t id) { const char * pa_scache_get_name_by_id(pa_core *c, uint32_t id) {
pa_scache_entry *e; pa_scache_entry *e;
assert(c && id != PA_IDXSET_INVALID);
pa_assert(c);
pa_assert(id != PA_IDXSET_INVALID);
if (!c->scache || !(e = pa_idxset_get_by_index(c->scache, id))) if (!c->scache || !(e = pa_idxset_get_by_index(c->scache, id)))
return NULL; return NULL;
@ -328,7 +347,9 @@ const char * pa_scache_get_name_by_id(pa_core *c, uint32_t id) {
uint32_t pa_scache_get_id_by_name(pa_core *c, const char *name) { uint32_t pa_scache_get_id_by_name(pa_core *c, const char *name) {
pa_scache_entry *e; pa_scache_entry *e;
assert(c && name);
pa_assert(c);
pa_assert(name);
if (!(e = pa_namereg_get(c, name, PA_NAMEREG_SAMPLE, 0))) if (!(e = pa_namereg_get(c, name, PA_NAMEREG_SAMPLE, 0)))
return PA_IDXSET_INVALID; return PA_IDXSET_INVALID;
@ -339,7 +360,8 @@ uint32_t pa_scache_get_id_by_name(pa_core *c, const char *name) {
uint32_t pa_scache_total_size(pa_core *c) { uint32_t pa_scache_total_size(pa_core *c) {
pa_scache_entry *e; pa_scache_entry *e;
uint32_t idx, sum = 0; uint32_t idx, sum = 0;
assert(c);
pa_assert(c);
if (!c->scache || !pa_idxset_size(c->scache)) if (!c->scache || !pa_idxset_size(c->scache))
return 0; return 0;
@ -355,7 +377,8 @@ void pa_scache_unload_unused(pa_core *c) {
pa_scache_entry *e; pa_scache_entry *e;
time_t now; time_t now;
uint32_t idx; uint32_t idx;
assert(c);
pa_assert(c);
if (!c->scache || !pa_idxset_size(c->scache)) if (!c->scache || !pa_idxset_size(c->scache))
return; return;
@ -382,6 +405,9 @@ static void add_file(pa_core *c, const char *pathname) {
struct stat st; struct stat st;
const char *e; const char *e;
pa_core_assert_ref(c);
pa_assert(pathname);
e = pa_path_get_filename(pathname); e = pa_path_get_filename(pathname);
if (stat(pathname, &st) < 0) { if (stat(pathname, &st) < 0) {
@ -397,7 +423,9 @@ static void add_file(pa_core *c, const char *pathname) {
int pa_scache_add_directory_lazy(pa_core *c, const char *pathname) { int pa_scache_add_directory_lazy(pa_core *c, const char *pathname) {
DIR *dir; DIR *dir;
assert(c && pathname);
pa_core_assert_ref(c);
pa_assert(pathname);
/* First try to open this as directory */ /* First try to open this as directory */
if (!(dir = opendir(pathname))) { if (!(dir = opendir(pathname))) {

View file

@ -26,12 +26,12 @@
#endif #endif
#include <stdio.h> #include <stdio.h>
#include <assert.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulsecore/queue.h> #include <pulsecore/queue.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include "core-subscribe.h" #include "core-subscribe.h"
@ -68,9 +68,9 @@ static void sched_event(pa_core *c);
pa_subscription* pa_subscription_new(pa_core *c, pa_subscription_mask_t m, pa_subscription_cb_t callback, void *userdata) { pa_subscription* pa_subscription_new(pa_core *c, pa_subscription_mask_t m, pa_subscription_cb_t callback, void *userdata) {
pa_subscription *s; pa_subscription *s;
assert(c); pa_assert(c);
assert(m); pa_assert(m);
assert(callback); pa_assert(callback);
s = pa_xnew(pa_subscription, 1); s = pa_xnew(pa_subscription, 1);
s->core = c; s->core = c;
@ -85,24 +85,24 @@ pa_subscription* pa_subscription_new(pa_core *c, pa_subscription_mask_t m, pa_su
/* Free a subscription object, effectively marking it for deletion */ /* Free a subscription object, effectively marking it for deletion */
void pa_subscription_free(pa_subscription*s) { void pa_subscription_free(pa_subscription*s) {
assert(s); pa_assert(s);
assert(!s->dead); pa_assert(!s->dead);
s->dead = 1; s->dead = 1;
sched_event(s->core); sched_event(s->core);
} }
static void free_subscription(pa_subscription *s) { static void free_subscription(pa_subscription *s) {
assert(s); pa_assert(s);
assert(s->core); pa_assert(s->core);
PA_LLIST_REMOVE(pa_subscription, s->core->subscriptions, s); PA_LLIST_REMOVE(pa_subscription, s->core->subscriptions, s);
pa_xfree(s); pa_xfree(s);
} }
static void free_event(pa_subscription_event *s) { static void free_event(pa_subscription_event *s) {
assert(s); pa_assert(s);
assert(s->core); pa_assert(s->core);
if (!s->next) if (!s->next)
s->core->subscription_event_last = s->prev; s->core->subscription_event_last = s->prev;
@ -113,7 +113,7 @@ static void free_event(pa_subscription_event *s) {
/* Free all subscription objects */ /* Free all subscription objects */
void pa_subscription_free_all(pa_core *c) { void pa_subscription_free_all(pa_core *c) {
assert(c); pa_assert(c);
while (c->subscriptions) while (c->subscriptions)
free_subscription(c->subscriptions); free_subscription(c->subscriptions);
@ -160,9 +160,9 @@ static void defer_cb(pa_mainloop_api *m, pa_defer_event *de, void *userdata) {
pa_core *c = userdata; pa_core *c = userdata;
pa_subscription *s; pa_subscription *s;
assert(c->mainloop == m); pa_assert(c->mainloop == m);
assert(c); pa_assert(c);
assert(c->subscription_defer_event == de); pa_assert(c->subscription_defer_event == de);
c->mainloop->defer_enable(c->subscription_defer_event, 0); c->mainloop->defer_enable(c->subscription_defer_event, 0);
@ -196,11 +196,11 @@ static void defer_cb(pa_mainloop_api *m, pa_defer_event *de, void *userdata) {
/* Schedule an mainloop event so that a pending subscription event is dispatched */ /* Schedule an mainloop event so that a pending subscription event is dispatched */
static void sched_event(pa_core *c) { static void sched_event(pa_core *c) {
assert(c); pa_assert(c);
if (!c->subscription_defer_event) { if (!c->subscription_defer_event) {
c->subscription_defer_event = c->mainloop->defer_new(c->mainloop, defer_cb, c); c->subscription_defer_event = c->mainloop->defer_new(c->mainloop, defer_cb, c);
assert(c->subscription_defer_event); pa_assert(c->subscription_defer_event);
} }
c->mainloop->defer_enable(c->subscription_defer_event, 1); c->mainloop->defer_enable(c->subscription_defer_event, 1);
@ -209,7 +209,7 @@ static void sched_event(pa_core *c) {
/* Append a new subscription event to the subscription event queue and schedule a main loop event */ /* Append a new subscription event to the subscription event queue and schedule a main loop event */
void pa_subscription_post(pa_core *c, pa_subscription_event_type_t t, uint32_t idx) { void pa_subscription_post(pa_core *c, pa_subscription_event_type_t t, uint32_t idx) {
pa_subscription_event *e; pa_subscription_event *e;
assert(c); pa_assert(c);
/* No need for queuing subscriptions of noone is listening */ /* No need for queuing subscriptions of noone is listening */
if (!c->subscriptions) if (!c->subscriptions)

View file

@ -132,7 +132,7 @@ int pa_set_root(HANDLE handle) {
void pa_make_nonblock_fd(int fd) { void pa_make_nonblock_fd(int fd) {
#ifdef O_NONBLOCK #ifdef O_NONBLOCK
int v; int v;
assert(fd >= 0); pa_assert(fd >= 0);
if ((v = fcntl(fd, F_GETFL)) >= 0) if ((v = fcntl(fd, F_GETFL)) >= 0)
if (!(v & O_NONBLOCK)) if (!(v & O_NONBLOCK))
@ -153,7 +153,7 @@ int pa_make_secure_dir(const char* dir, mode_t m, uid_t uid, gid_t gid) {
struct stat st; struct stat st;
int r; int r;
assert(dir); pa_assert(dir);
#ifdef OS_IS_WIN32 #ifdef OS_IS_WIN32
r = mkdir(dir); r = mkdir(dir);
@ -300,9 +300,9 @@ ssize_t pa_loop_read(int fd, void*data, size_t size, int *type) {
ssize_t ret = 0; ssize_t ret = 0;
int _type; int _type;
assert(fd >= 0); pa_assert(fd >= 0);
assert(data); pa_assert(data);
assert(size); pa_assert(size);
if (!type) { if (!type) {
_type = 0; _type = 0;
@ -331,9 +331,9 @@ ssize_t pa_loop_write(int fd, const void*data, size_t size, int *type) {
ssize_t ret = 0; ssize_t ret = 0;
int _type; int _type;
assert(fd >= 0); pa_assert(fd >= 0);
assert(data); pa_assert(data);
assert(size); pa_assert(size);
if (!type) { if (!type) {
_type = 0; _type = 0;
@ -423,7 +423,7 @@ char *pa_sprintf_malloc(const char *format, ...) {
int size = 100; int size = 100;
char *c = NULL; char *c = NULL;
assert(format); pa_assert(format);
for(;;) { for(;;) {
int r; int r;
@ -453,7 +453,7 @@ char *pa_vsprintf_malloc(const char *format, va_list ap) {
int size = 100; int size = 100;
char *c = NULL; char *c = NULL;
assert(format); pa_assert(format);
for(;;) { for(;;) {
int r; int r;
@ -479,7 +479,9 @@ char *pa_vsprintf_malloc(const char *format, va_list ap) {
/* Similar to OpenBSD's strlcpy() function */ /* Similar to OpenBSD's strlcpy() function */
char *pa_strlcpy(char *b, const char *s, size_t l) { char *pa_strlcpy(char *b, const char *s, size_t l) {
assert(b && s && l > 0); pa_assert(b);
pa_assert(s);
pa_assert(l > 0);
strncpy(b, s, l); strncpy(b, s, l);
b[l-1] = 0; b[l-1] = 0;
@ -550,7 +552,7 @@ int pa_fd_set_cloexec(int fd, int b) {
#ifdef FD_CLOEXEC #ifdef FD_CLOEXEC
int v; int v;
assert(fd >= 0); pa_assert(fd >= 0);
if ((v = fcntl(fd, F_GETFD, 0)) < 0) if ((v = fcntl(fd, F_GETFD, 0)) < 0)
return -1; return -1;
@ -690,7 +692,7 @@ int pa_own_uid_in_group(const char *name, gid_t *gid) {
int n = sysconf(_SC_NGROUPS_MAX); int n = sysconf(_SC_NGROUPS_MAX);
int r = -1, i; int r = -1, i;
assert(n > 0); pa_assert(n > 0);
gids = pa_xmalloc(sizeof(GETGROUPS_T)*n); gids = pa_xmalloc(sizeof(GETGROUPS_T)*n);
@ -856,7 +858,7 @@ int pa_lock_fd(int fd, int b) {
/* Remove trailing newlines from a string */ /* Remove trailing newlines from a string */
char* pa_strip_nl(char *s) { char* pa_strip_nl(char *s) {
assert(s); pa_assert(s);
s[strcspn(s, "\r\n")] = 0; s[strcspn(s, "\r\n")] = 0;
return s; return s;
@ -865,7 +867,7 @@ char* pa_strip_nl(char *s) {
/* Create a temporary lock file and lock it. */ /* Create a temporary lock file and lock it. */
int pa_lock_lockfile(const char *fn) { int pa_lock_lockfile(const char *fn) {
int fd = -1; int fd = -1;
assert(fn); pa_assert(fn);
for (;;) { for (;;) {
struct stat st; struct stat st;
@ -916,7 +918,8 @@ fail:
/* Unlock a temporary lcok file */ /* Unlock a temporary lcok file */
int pa_unlock_lockfile(const char *fn, int fd) { int pa_unlock_lockfile(const char *fn, int fd) {
int r = 0; int r = 0;
assert(fn && fd >= 0); pa_assert(fn);
pa_assert(fd >= 0);
if (unlink(fn) < 0) { if (unlink(fn) < 0) {
pa_log_warn("WARNING: unable to remove lock file '%s': %s", pa_log_warn("WARNING: unable to remove lock file '%s': %s",
@ -1026,7 +1029,10 @@ FILE *pa_open_config_file(const char *global, const char *local, const char *env
char *pa_hexstr(const uint8_t* d, size_t dlength, char *s, size_t slength) { char *pa_hexstr(const uint8_t* d, size_t dlength, char *s, size_t slength) {
size_t i = 0, j = 0; size_t i = 0, j = 0;
const char hex[] = "0123456789abcdef"; const char hex[] = "0123456789abcdef";
assert(d && s && slength > 0);
pa_assert(d);
pa_assert(s);
pa_assert(slength > 0);
while (i < dlength && j+3 <= slength) { while (i < dlength && j+3 <= slength) {
s[j++] = hex[*d >> 4]; s[j++] = hex[*d >> 4];
@ -1057,7 +1063,9 @@ static int hexc(char c) {
/* Parse a hexadecimal string as created by pa_hexstr() to a BLOB */ /* Parse a hexadecimal string as created by pa_hexstr() to a BLOB */
size_t pa_parsehex(const char *p, uint8_t *d, size_t dlength) { size_t pa_parsehex(const char *p, uint8_t *d, size_t dlength) {
size_t j = 0; size_t j = 0;
assert(p && d);
pa_assert(p);
pa_assert(d);
while (j < dlength && *p) { while (j < dlength && *p) {
int b; int b;
@ -1084,8 +1092,8 @@ size_t pa_parsehex(const char *p, uint8_t *d, size_t dlength) {
int pa_startswith(const char *s, const char *pfx) { int pa_startswith(const char *s, const char *pfx) {
size_t l; size_t l;
assert(s); pa_assert(s);
assert(pfx); pa_assert(pfx);
l = strlen(pfx); l = strlen(pfx);
@ -1096,8 +1104,8 @@ int pa_startswith(const char *s, const char *pfx) {
int pa_endswith(const char *s, const char *sfx) { int pa_endswith(const char *s, const char *sfx) {
size_t l1, l2; size_t l1, l2;
assert(s); pa_assert(s);
assert(sfx); pa_assert(sfx);
l1 = strlen(s); l1 = strlen(s);
l2 = strlen(sfx); l2 = strlen(sfx);
@ -1150,7 +1158,9 @@ char *pa_runtime_path(const char *fn, char *s, size_t l) {
int pa_atoi(const char *s, int32_t *ret_i) { int pa_atoi(const char *s, int32_t *ret_i) {
char *x = NULL; char *x = NULL;
long l; long l;
assert(s && ret_i);
pa_assert(s);
pa_assert(ret_i);
l = strtol(s, &x, 0); l = strtol(s, &x, 0);
@ -1166,7 +1176,9 @@ int pa_atoi(const char *s, int32_t *ret_i) {
int pa_atou(const char *s, uint32_t *ret_u) { int pa_atou(const char *s, uint32_t *ret_u) {
char *x = NULL; char *x = NULL;
unsigned long l; unsigned long l;
assert(s && ret_u);
pa_assert(s);
pa_assert(ret_u);
l = strtoul(s, &x, 0); l = strtoul(s, &x, 0);

View file

@ -26,10 +26,10 @@
#endif #endif
#include <string.h> #include <string.h>
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulsecore/macro.h>
#include "dynarray.h" #include "dynarray.h"
@ -52,7 +52,7 @@ pa_dynarray* pa_dynarray_new(void) {
void pa_dynarray_free(pa_dynarray* a, void (*func)(void *p, void *userdata), void *userdata) { void pa_dynarray_free(pa_dynarray* a, void (*func)(void *p, void *userdata), void *userdata) {
unsigned i; unsigned i;
assert(a); pa_assert(a);
if (func) if (func)
for (i = 0; i < a->n_entries; i++) for (i = 0; i < a->n_entries; i++)
@ -64,7 +64,7 @@ void pa_dynarray_free(pa_dynarray* a, void (*func)(void *p, void *userdata), voi
} }
void pa_dynarray_put(pa_dynarray*a, unsigned i, void *p) { void pa_dynarray_put(pa_dynarray*a, unsigned i, void *p) {
assert(a); pa_assert(a);
if (i >= a->n_allocated) { if (i >= a->n_allocated) {
unsigned n; unsigned n;
@ -85,21 +85,27 @@ void pa_dynarray_put(pa_dynarray*a, unsigned i, void *p) {
} }
unsigned pa_dynarray_append(pa_dynarray*a, void *p) { unsigned pa_dynarray_append(pa_dynarray*a, void *p) {
unsigned i = a->n_entries; unsigned i;
pa_assert(a);
i = a->n_entries;
pa_dynarray_put(a, i, p); pa_dynarray_put(a, i, p);
return i; return i;
} }
void *pa_dynarray_get(pa_dynarray*a, unsigned i) { void *pa_dynarray_get(pa_dynarray*a, unsigned i) {
assert(a); pa_assert(a);
if (i >= a->n_entries) if (i >= a->n_entries)
return NULL; return NULL;
assert(a->data); pa_assert(a->data);
return a->data[i]; return a->data[i];
} }
unsigned pa_dynarray_size(pa_dynarray*a) { unsigned pa_dynarray_size(pa_dynarray*a) {
assert(a); pa_assert(a);
return a->n_entries; return a->n_entries;
} }

View file

@ -25,14 +25,14 @@
#include <config.h> #include <config.h>
#endif #endif
#include <assert.h> #include <pulse/xmalloc.h>
#include <pulsecore/atomic.h> #include <pulsecore/atomic.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/thread.h> #include <pulsecore/thread.h>
#include <pulsecore/macro.h> #include <pulsecore/macro.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulse/xmalloc.h> #include <pulsecore/macro.h>
#include "flist.h" #include "flist.h"
@ -111,7 +111,7 @@ pa_flist *pa_flist_new(unsigned size) {
if (!size) if (!size)
size = FLIST_SIZE; size = FLIST_SIZE;
assert(pa_is_power_of_two(size)); pa_assert(pa_is_power_of_two(size));
l = pa_xmalloc0(PA_ALIGN(sizeof(pa_flist)) + (sizeof(struct cell) * size)); l = pa_xmalloc0(PA_ALIGN(sizeof(pa_flist)) + (sizeof(struct cell) * size));
@ -129,7 +129,7 @@ static int reduce(pa_flist *l, int value) {
} }
void pa_flist_free(pa_flist *l, pa_free_cb_t free_cb) { void pa_flist_free(pa_flist *l, pa_free_cb_t free_cb) {
assert(l); pa_assert(l);
if (free_cb) { if (free_cb) {
struct cell *cells; struct cell *cells;
@ -156,8 +156,8 @@ int pa_flist_push(pa_flist*l, void *p) {
int idx, len, n; int idx, len, n;
struct cell *cells; struct cell *cells;
assert(l); pa_assert(l);
assert(p); pa_assert(p);
cells = PA_FLIST_CELLS(l); cells = PA_FLIST_CELLS(l);
@ -196,7 +196,7 @@ void* pa_flist_pop(pa_flist*l) {
int idx, len, n; int idx, len, n;
struct cell *cells; struct cell *cells;
assert(l); pa_assert(l);
cells = PA_FLIST_CELLS(l); cells = PA_FLIST_CELLS(l);

View file

@ -26,7 +26,6 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <assert.h>
#include <string.h> #include <string.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
@ -34,6 +33,7 @@
#include <pulsecore/idxset.h> #include <pulsecore/idxset.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/flist.h> #include <pulsecore/flist.h>
#include <pulsecore/macro.h>
#include "hashmap.h" #include "hashmap.h"
@ -72,8 +72,8 @@ pa_hashmap *pa_hashmap_new(pa_hash_func_t hash_func, pa_compare_func_t compare_f
} }
static void remove(pa_hashmap *h, struct hashmap_entry *e) { static void remove(pa_hashmap *h, struct hashmap_entry *e) {
assert(h); pa_assert(h);
assert(e); pa_assert(e);
if (e->next) if (e->next)
e->next->previous = e->previous; e->next->previous = e->previous;
@ -87,7 +87,7 @@ static void remove(pa_hashmap *h, struct hashmap_entry *e) {
if (e->bucket_previous) if (e->bucket_previous)
e->bucket_previous->bucket_next = e->bucket_next; e->bucket_previous->bucket_next = e->bucket_next;
else { else {
assert(e->hash < h->size); pa_assert(e->hash < h->size);
h->data[e->hash] = e->bucket_next; h->data[e->hash] = e->bucket_next;
} }
@ -98,7 +98,7 @@ static void remove(pa_hashmap *h, struct hashmap_entry *e) {
} }
void pa_hashmap_free(pa_hashmap*h, void (*free_func)(void *p, void *userdata), void *userdata) { void pa_hashmap_free(pa_hashmap*h, void (*free_func)(void *p, void *userdata), void *userdata) {
assert(h); pa_assert(h);
while (h->first_entry) { while (h->first_entry) {
if (free_func) if (free_func)
@ -112,8 +112,8 @@ void pa_hashmap_free(pa_hashmap*h, void (*free_func)(void *p, void *userdata), v
static struct hashmap_entry *get(pa_hashmap *h, unsigned hash, const void *key) { static struct hashmap_entry *get(pa_hashmap *h, unsigned hash, const void *key) {
struct hashmap_entry *e; struct hashmap_entry *e;
assert(h); pa_assert(h);
assert(hash < h->size); pa_assert(hash < h->size);
for (e = h->data[hash]; e; e = e->bucket_next) for (e = h->data[hash]; e; e = e->bucket_next)
if (h->compare_func(e->key, key) == 0) if (h->compare_func(e->key, key) == 0)
@ -125,7 +125,7 @@ static struct hashmap_entry *get(pa_hashmap *h, unsigned hash, const void *key)
int pa_hashmap_put(pa_hashmap *h, const void *key, void *value) { int pa_hashmap_put(pa_hashmap *h, const void *key, void *value) {
struct hashmap_entry *e; struct hashmap_entry *e;
unsigned hash; unsigned hash;
assert(h); pa_assert(h);
hash = h->hash_func(key) % h->size; hash = h->hash_func(key) % h->size;
@ -159,7 +159,7 @@ void* pa_hashmap_get(pa_hashmap *h, const void *key) {
unsigned hash; unsigned hash;
struct hashmap_entry *e; struct hashmap_entry *e;
assert(h); pa_assert(h);
hash = h->hash_func(key) % h->size; hash = h->hash_func(key) % h->size;
@ -174,7 +174,7 @@ void* pa_hashmap_remove(pa_hashmap *h, const void *key) {
unsigned hash; unsigned hash;
void *data; void *data;
assert(h); pa_assert(h);
hash = h->hash_func(key) % h->size; hash = h->hash_func(key) % h->size;
@ -191,8 +191,8 @@ unsigned pa_hashmap_size(pa_hashmap *h) {
} }
void *pa_hashmap_iterate(pa_hashmap *h, void **state, const void **key) { void *pa_hashmap_iterate(pa_hashmap *h, void **state, const void **key) {
assert(h); pa_assert(h);
assert(state); pa_assert(state);
if (!*state) if (!*state)
*state = h->first_entry; *state = h->first_entry;
@ -214,7 +214,7 @@ void *pa_hashmap_iterate(pa_hashmap *h, void **state, const void **key) {
void* pa_hashmap_steal_first(pa_hashmap *h) { void* pa_hashmap_steal_first(pa_hashmap *h) {
void *data; void *data;
assert(h); pa_assert(h);
if (!h->first_entry) if (!h->first_entry)
return NULL; return NULL;
@ -225,7 +225,7 @@ void* pa_hashmap_steal_first(pa_hashmap *h) {
} }
void *pa_hashmap_get_first(pa_hashmap *h) { void *pa_hashmap_get_first(pa_hashmap *h) {
assert(h); pa_assert(h);
if (!h->first_entry) if (!h->first_entry)
return NULL; return NULL;

View file

@ -21,10 +21,16 @@
USA. USA.
***/ ***/
#include <pulsecore/hook-list.h> #ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <pulsecore/macro.h>
#include "hook-list.h"
void pa_hook_init(pa_hook *hook, void *data) { void pa_hook_init(pa_hook *hook, void *data) {
assert(hook); pa_assert(hook);
PA_LLIST_HEAD_INIT(pa_hook_slot, hook->slots); PA_LLIST_HEAD_INIT(pa_hook_slot, hook->slots);
hook->last = NULL; hook->last = NULL;
@ -33,8 +39,8 @@ void pa_hook_init(pa_hook *hook, void *data) {
} }
static void slot_free(pa_hook *hook, pa_hook_slot *slot) { static void slot_free(pa_hook *hook, pa_hook_slot *slot) {
assert(hook); pa_assert(hook);
assert(slot); pa_assert(slot);
if (hook->last == slot) if (hook->last == slot)
hook->last = slot->prev; hook->last = slot->prev;
@ -45,8 +51,8 @@ static void slot_free(pa_hook *hook, pa_hook_slot *slot) {
} }
void pa_hook_free(pa_hook *hook) { void pa_hook_free(pa_hook *hook) {
assert(hook); pa_assert(hook);
assert(!hook->firing); pa_assert(!hook->firing);
while (hook->slots) while (hook->slots)
slot_free(hook, hook->slots); slot_free(hook, hook->slots);
@ -57,7 +63,7 @@ void pa_hook_free(pa_hook *hook) {
pa_hook_slot* pa_hook_connect(pa_hook *hook, pa_hook_cb_t cb, void *data) { pa_hook_slot* pa_hook_connect(pa_hook *hook, pa_hook_cb_t cb, void *data) {
pa_hook_slot *slot; pa_hook_slot *slot;
assert(cb); pa_assert(cb);
slot = pa_xnew(pa_hook_slot, 1); slot = pa_xnew(pa_hook_slot, 1);
slot->hook = hook; slot->hook = hook;
@ -72,8 +78,8 @@ pa_hook_slot* pa_hook_connect(pa_hook *hook, pa_hook_cb_t cb, void *data) {
} }
void pa_hook_slot_free(pa_hook_slot *slot) { void pa_hook_slot_free(pa_hook_slot *slot) {
assert(slot); pa_assert(slot);
assert(!slot->dead); pa_assert(!slot->dead);
if (slot->hook->firing > 0) { if (slot->hook->firing > 0) {
slot->dead = 1; slot->dead = 1;
@ -86,7 +92,7 @@ pa_hook_result_t pa_hook_fire(pa_hook *hook, void *data) {
pa_hook_slot *slot, *next; pa_hook_slot *slot, *next;
pa_hook_result_t result = PA_HOOK_OK; pa_hook_result_t result = PA_HOOK_OK;
assert(hook); pa_assert(hook);
hook->firing ++; hook->firing ++;

View file

@ -27,7 +27,6 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <assert.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
@ -47,6 +46,7 @@
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/socket-util.h> #include <pulsecore/socket-util.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include "iochannel.h" #include "iochannel.h"
@ -68,11 +68,11 @@ struct pa_iochannel {
}; };
static void enable_mainloop_sources(pa_iochannel *io) { static void enable_mainloop_sources(pa_iochannel *io) {
assert(io); pa_assert(io);
if (io->input_event == io->output_event && io->input_event) { if (io->input_event == io->output_event && io->input_event) {
pa_io_event_flags_t f = PA_IO_EVENT_NULL; pa_io_event_flags_t f = PA_IO_EVENT_NULL;
assert(io->input_event); pa_assert(io->input_event);
if (!io->readable) if (!io->readable)
f |= PA_IO_EVENT_INPUT; f |= PA_IO_EVENT_INPUT;
@ -92,10 +92,10 @@ static void callback(pa_mainloop_api* m, pa_io_event *e, int fd, pa_io_event_fla
pa_iochannel *io = userdata; pa_iochannel *io = userdata;
int changed = 0; int changed = 0;
assert(m); pa_assert(m);
assert(e); pa_assert(e);
assert(fd >= 0); pa_assert(fd >= 0);
assert(userdata); pa_assert(userdata);
if ((f & (PA_IO_EVENT_HANGUP|PA_IO_EVENT_ERROR)) && !io->hungup) { if ((f & (PA_IO_EVENT_HANGUP|PA_IO_EVENT_ERROR)) && !io->hungup) {
io->hungup = 1; io->hungup = 1;
@ -105,13 +105,13 @@ static void callback(pa_mainloop_api* m, pa_io_event *e, int fd, pa_io_event_fla
if ((f & PA_IO_EVENT_INPUT) && !io->readable) { if ((f & PA_IO_EVENT_INPUT) && !io->readable) {
io->readable = 1; io->readable = 1;
changed = 1; changed = 1;
assert(e == io->input_event); pa_assert(e == io->input_event);
} }
if ((f & PA_IO_EVENT_OUTPUT) && !io->writable) { if ((f & PA_IO_EVENT_OUTPUT) && !io->writable) {
io->writable = 1; io->writable = 1;
changed = 1; changed = 1;
assert(e == io->output_event); pa_assert(e == io->output_event);
} }
if (changed) { if (changed) {
@ -125,8 +125,8 @@ static void callback(pa_mainloop_api* m, pa_io_event *e, int fd, pa_io_event_fla
pa_iochannel* pa_iochannel_new(pa_mainloop_api*m, int ifd, int ofd) { pa_iochannel* pa_iochannel_new(pa_mainloop_api*m, int ifd, int ofd) {
pa_iochannel *io; pa_iochannel *io;
assert(m); pa_assert(m);
assert(ifd >= 0 || ofd >= 0); pa_assert(ifd >= 0 || ofd >= 0);
io = pa_xnew(pa_iochannel, 1); io = pa_xnew(pa_iochannel, 1);
io->ifd = ifd; io->ifd = ifd;
@ -144,7 +144,7 @@ pa_iochannel* pa_iochannel_new(pa_mainloop_api*m, int ifd, int ofd) {
io->input_event = io->output_event = NULL; io->input_event = io->output_event = NULL;
if (ifd == ofd) { if (ifd == ofd) {
assert(ifd >= 0); pa_assert(ifd >= 0);
pa_make_nonblock_fd(io->ifd); pa_make_nonblock_fd(io->ifd);
io->input_event = io->output_event = m->io_new(m, ifd, PA_IO_EVENT_INPUT|PA_IO_EVENT_OUTPUT, callback, io); io->input_event = io->output_event = m->io_new(m, ifd, PA_IO_EVENT_INPUT|PA_IO_EVENT_OUTPUT, callback, io);
} else { } else {
@ -164,7 +164,7 @@ pa_iochannel* pa_iochannel_new(pa_mainloop_api*m, int ifd, int ofd) {
} }
void pa_iochannel_free(pa_iochannel*io) { void pa_iochannel_free(pa_iochannel*io) {
assert(io); pa_assert(io);
if (io->input_event) if (io->input_event)
io->mainloop->io_free(io->input_event); io->mainloop->io_free(io->input_event);
@ -183,19 +183,19 @@ void pa_iochannel_free(pa_iochannel*io) {
} }
int pa_iochannel_is_readable(pa_iochannel*io) { int pa_iochannel_is_readable(pa_iochannel*io) {
assert(io); pa_assert(io);
return io->readable || io->hungup; return io->readable || io->hungup;
} }
int pa_iochannel_is_writable(pa_iochannel*io) { int pa_iochannel_is_writable(pa_iochannel*io) {
assert(io); pa_assert(io);
return io->writable && !io->hungup; return io->writable && !io->hungup;
} }
int pa_iochannel_is_hungup(pa_iochannel*io) { int pa_iochannel_is_hungup(pa_iochannel*io) {
assert(io); pa_assert(io);
return io->hungup; return io->hungup;
} }
@ -203,10 +203,10 @@ int pa_iochannel_is_hungup(pa_iochannel*io) {
ssize_t pa_iochannel_write(pa_iochannel*io, const void*data, size_t l) { ssize_t pa_iochannel_write(pa_iochannel*io, const void*data, size_t l) {
ssize_t r; ssize_t r;
assert(io); pa_assert(io);
assert(data); pa_assert(data);
assert(l); pa_assert(l);
assert(io->ofd >= 0); pa_assert(io->ofd >= 0);
r = pa_write(io->ofd, data, l, &io->ofd_type); r = pa_write(io->ofd, data, l, &io->ofd_type);
if (r >= 0) { if (r >= 0) {
@ -220,9 +220,9 @@ ssize_t pa_iochannel_write(pa_iochannel*io, const void*data, size_t l) {
ssize_t pa_iochannel_read(pa_iochannel*io, void*data, size_t l) { ssize_t pa_iochannel_read(pa_iochannel*io, void*data, size_t l) {
ssize_t r; ssize_t r;
assert(io); pa_assert(io);
assert(data); pa_assert(data);
assert(io->ifd >= 0); pa_assert(io->ifd >= 0);
r = pa_read(io->ifd, data, l, &io->ifd_type); r = pa_read(io->ifd, data, l, &io->ifd_type);
if (r >= 0) { if (r >= 0) {
@ -239,9 +239,9 @@ int pa_iochannel_creds_supported(pa_iochannel *io) {
struct sockaddr_un sa; struct sockaddr_un sa;
socklen_t l; socklen_t l;
assert(io); pa_assert(io);
assert(io->ifd >= 0); pa_assert(io->ifd >= 0);
assert(io->ofd == io->ifd); pa_assert(io->ofd == io->ifd);
l = sizeof(sa); l = sizeof(sa);
@ -254,8 +254,8 @@ int pa_iochannel_creds_supported(pa_iochannel *io) {
int pa_iochannel_creds_enable(pa_iochannel *io) { int pa_iochannel_creds_enable(pa_iochannel *io) {
int t = 1; int t = 1;
assert(io); pa_assert(io);
assert(io->ifd >= 0); pa_assert(io->ifd >= 0);
if (setsockopt(io->ifd, SOL_SOCKET, SO_PASSCRED, &t, sizeof(t)) < 0) { if (setsockopt(io->ifd, SOL_SOCKET, SO_PASSCRED, &t, sizeof(t)) < 0) {
pa_log_error("setsockopt(SOL_SOCKET, SO_PASSCRED): %s", pa_cstrerror(errno)); pa_log_error("setsockopt(SOL_SOCKET, SO_PASSCRED): %s", pa_cstrerror(errno));
@ -273,10 +273,10 @@ ssize_t pa_iochannel_write_with_creds(pa_iochannel*io, const void*data, size_t l
struct ucred *u; struct ucred *u;
struct cmsghdr *cmsg; struct cmsghdr *cmsg;
assert(io); pa_assert(io);
assert(data); pa_assert(data);
assert(l); pa_assert(l);
assert(io->ofd >= 0); pa_assert(io->ofd >= 0);
memset(&iov, 0, sizeof(iov)); memset(&iov, 0, sizeof(iov));
iov.iov_base = (void*) data; iov.iov_base = (void*) data;
@ -322,12 +322,12 @@ ssize_t pa_iochannel_read_with_creds(pa_iochannel*io, void*data, size_t l, pa_cr
struct iovec iov; struct iovec iov;
uint8_t cmsg_data[CMSG_SPACE(sizeof(struct ucred))]; uint8_t cmsg_data[CMSG_SPACE(sizeof(struct ucred))];
assert(io); pa_assert(io);
assert(data); pa_assert(data);
assert(l); pa_assert(l);
assert(io->ifd >= 0); pa_assert(io->ifd >= 0);
assert(creds); pa_assert(creds);
assert(creds_valid); pa_assert(creds_valid);
memset(&iov, 0, sizeof(iov)); memset(&iov, 0, sizeof(iov));
iov.iov_base = data; iov.iov_base = data;
@ -353,7 +353,7 @@ ssize_t pa_iochannel_read_with_creds(pa_iochannel*io, void*data, size_t l, pa_cr
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_CREDENTIALS) { if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_CREDENTIALS) {
struct ucred u; struct ucred u;
assert(cmsg->cmsg_len == CMSG_LEN(sizeof(struct ucred))); pa_assert(cmsg->cmsg_len == CMSG_LEN(sizeof(struct ucred)));
memcpy(&u, CMSG_DATA(cmsg), sizeof(struct ucred)); memcpy(&u, CMSG_DATA(cmsg), sizeof(struct ucred));
creds->gid = u.gid; creds->gid = u.gid;
@ -373,46 +373,46 @@ ssize_t pa_iochannel_read_with_creds(pa_iochannel*io, void*data, size_t l, pa_cr
#endif /* HAVE_CREDS */ #endif /* HAVE_CREDS */
void pa_iochannel_set_callback(pa_iochannel*io, pa_iochannel_cb_t _callback, void *userdata) { void pa_iochannel_set_callback(pa_iochannel*io, pa_iochannel_cb_t _callback, void *userdata) {
assert(io); pa_assert(io);
io->callback = _callback; io->callback = _callback;
io->userdata = userdata; io->userdata = userdata;
} }
void pa_iochannel_set_noclose(pa_iochannel*io, int b) { void pa_iochannel_set_noclose(pa_iochannel*io, int b) {
assert(io); pa_assert(io);
io->no_close = b; io->no_close = b;
} }
void pa_iochannel_socket_peer_to_string(pa_iochannel*io, char*s, size_t l) { void pa_iochannel_socket_peer_to_string(pa_iochannel*io, char*s, size_t l) {
assert(io); pa_assert(io);
assert(s); pa_assert(s);
assert(l); pa_assert(l);
pa_socket_peer_to_string(io->ifd, s, l); pa_socket_peer_to_string(io->ifd, s, l);
} }
int pa_iochannel_socket_set_rcvbuf(pa_iochannel *io, size_t l) { int pa_iochannel_socket_set_rcvbuf(pa_iochannel *io, size_t l) {
assert(io); pa_assert(io);
return pa_socket_set_rcvbuf(io->ifd, l); return pa_socket_set_rcvbuf(io->ifd, l);
} }
int pa_iochannel_socket_set_sndbuf(pa_iochannel *io, size_t l) { int pa_iochannel_socket_set_sndbuf(pa_iochannel *io, size_t l) {
assert(io); pa_assert(io);
return pa_socket_set_sndbuf(io->ofd, l); return pa_socket_set_sndbuf(io->ofd, l);
} }
pa_mainloop_api* pa_iochannel_get_mainloop_api(pa_iochannel *io) { pa_mainloop_api* pa_iochannel_get_mainloop_api(pa_iochannel *io) {
assert(io); pa_assert(io);
return io->mainloop; return io->mainloop;
} }
int pa_iochannel_get_recv_fd(pa_iochannel *io) { int pa_iochannel_get_recv_fd(pa_iochannel *io) {
assert(io); pa_assert(io);
return io->ifd; return io->ifd;
} }

View file

@ -25,6 +25,10 @@
USA. USA.
***/ ***/
#ifndef PACKAGE
#error "Please include config.h before including this file!"
#endif
#include <sys/types.h> #include <sys/types.h>
#include <pulse/mainloop-api.h> #include <pulse/mainloop-api.h>

View file

@ -27,7 +27,6 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -35,6 +34,8 @@
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include <pulsecore/refcnt.h>
#include "ioline.h" #include "ioline.h"
@ -42,10 +43,11 @@
#define READ_SIZE (1024) #define READ_SIZE (1024)
struct pa_ioline { struct pa_ioline {
PA_REFCNT_DECLARE;
pa_iochannel *io; pa_iochannel *io;
pa_defer_event *defer_event; pa_defer_event *defer_event;
pa_mainloop_api *mainloop; pa_mainloop_api *mainloop;
int ref;
int dead; int dead;
char *wbuf; char *wbuf;
@ -65,9 +67,10 @@ static void defer_callback(pa_mainloop_api*m, pa_defer_event*e, void *userdata);
pa_ioline* pa_ioline_new(pa_iochannel *io) { pa_ioline* pa_ioline_new(pa_iochannel *io) {
pa_ioline *l; pa_ioline *l;
assert(io); pa_assert(io);
l = pa_xnew(pa_ioline, 1); l = pa_xnew(pa_ioline, 1);
PA_REFCNT_INIT(l);
l->io = io; l->io = io;
l->dead = 0; l->dead = 0;
@ -79,7 +82,6 @@ pa_ioline* pa_ioline_new(pa_iochannel *io) {
l->callback = NULL; l->callback = NULL;
l->userdata = NULL; l->userdata = NULL;
l->ref = 1;
l->mainloop = pa_iochannel_get_mainloop_api(io); l->mainloop = pa_iochannel_get_mainloop_api(io);
@ -94,7 +96,7 @@ pa_ioline* pa_ioline_new(pa_iochannel *io) {
} }
static void ioline_free(pa_ioline *l) { static void ioline_free(pa_ioline *l) {
assert(l); pa_assert(l);
if (l->io) if (l->io)
pa_iochannel_free(l->io); pa_iochannel_free(l->io);
@ -108,24 +110,24 @@ static void ioline_free(pa_ioline *l) {
} }
void pa_ioline_unref(pa_ioline *l) { void pa_ioline_unref(pa_ioline *l) {
assert(l); pa_assert(l);
assert(l->ref >= 1); pa_assert(PA_REFCNT_VALUE(l) >= 1);
if ((--l->ref) <= 0) if (PA_REFCNT_DEC(l) <= 0)
ioline_free(l); ioline_free(l);
} }
pa_ioline* pa_ioline_ref(pa_ioline *l) { pa_ioline* pa_ioline_ref(pa_ioline *l) {
assert(l); pa_assert(l);
assert(l->ref >= 1); pa_assert(PA_REFCNT_VALUE(l) >= 1);
l->ref++; PA_REFCNT_INC(l);
return l; return l;
} }
void pa_ioline_close(pa_ioline *l) { void pa_ioline_close(pa_ioline *l) {
assert(l); pa_assert(l);
assert(l->ref >= 1); pa_assert(PA_REFCNT_VALUE(l) >= 1);
l->dead = 1; l->dead = 1;
@ -146,9 +148,9 @@ void pa_ioline_close(pa_ioline *l) {
void pa_ioline_puts(pa_ioline *l, const char *c) { void pa_ioline_puts(pa_ioline *l, const char *c) {
size_t len; size_t len;
assert(l); pa_assert(l);
assert(l->ref >= 1); pa_assert(PA_REFCNT_VALUE(l) >= 1);
assert(c); pa_assert(c);
if (l->dead) if (l->dead)
return; return;
@ -158,7 +160,7 @@ void pa_ioline_puts(pa_ioline *l, const char *c) {
len = BUFFER_LIMIT - l->wbuf_valid_length; len = BUFFER_LIMIT - l->wbuf_valid_length;
if (len) { if (len) {
assert(l->wbuf_length >= l->wbuf_valid_length); pa_assert(l->wbuf_length >= l->wbuf_valid_length);
/* In case the allocated buffer is too small, enlarge it. */ /* In case the allocated buffer is too small, enlarge it. */
if (l->wbuf_valid_length + len > l->wbuf_length) { if (l->wbuf_valid_length + len > l->wbuf_length) {
@ -178,7 +180,7 @@ void pa_ioline_puts(pa_ioline *l, const char *c) {
l->wbuf_index = 0; l->wbuf_index = 0;
} }
assert(l->wbuf_index + l->wbuf_valid_length + len <= l->wbuf_length); pa_assert(l->wbuf_index + l->wbuf_valid_length + len <= l->wbuf_length);
/* Append the new string */ /* Append the new string */
memcpy(l->wbuf + l->wbuf_index + l->wbuf_valid_length, c, len); memcpy(l->wbuf + l->wbuf_index + l->wbuf_valid_length, c, len);
@ -189,17 +191,17 @@ void pa_ioline_puts(pa_ioline *l, const char *c) {
} }
void pa_ioline_set_callback(pa_ioline*l, void (*callback)(pa_ioline*io, const char *s, void *userdata), void *userdata) { void pa_ioline_set_callback(pa_ioline*l, void (*callback)(pa_ioline*io, const char *s, void *userdata), void *userdata) {
assert(l); pa_assert(l);
assert(l->ref >= 1); pa_assert(PA_REFCNT_VALUE(l) >= 1);
l->callback = callback; l->callback = callback;
l->userdata = userdata; l->userdata = userdata;
} }
static void failure(pa_ioline *l, int process_leftover) { static void failure(pa_ioline *l, int process_leftover) {
assert(l); pa_assert(l);
assert(l->ref >= 1); pa_assert(PA_REFCNT_VALUE(l) >= 1);
assert(!l->dead); pa_assert(!l->dead);
if (process_leftover && l->rbuf_valid_length > 0) { if (process_leftover && l->rbuf_valid_length > 0) {
/* Pass the last missing bit to the client */ /* Pass the last missing bit to the client */
@ -220,7 +222,9 @@ static void failure(pa_ioline *l, int process_leftover) {
} }
static void scan_for_lines(pa_ioline *l, size_t skip) { static void scan_for_lines(pa_ioline *l, size_t skip) {
assert(l && l->ref >= 1 && skip < l->rbuf_valid_length); pa_assert(l);
pa_assert(PA_REFCNT_VALUE(l) >= 1);
pa_assert(skip < l->rbuf_valid_length);
while (!l->dead && l->rbuf_valid_length > skip) { while (!l->dead && l->rbuf_valid_length > skip) {
char *e, *p; char *e, *p;
@ -255,7 +259,8 @@ static void scan_for_lines(pa_ioline *l, size_t skip) {
static int do_write(pa_ioline *l); static int do_write(pa_ioline *l);
static int do_read(pa_ioline *l) { static int do_read(pa_ioline *l) {
assert(l && l->ref >= 1); pa_assert(l);
pa_assert(PA_REFCNT_VALUE(l) >= 1);
while (!l->dead && pa_iochannel_is_readable(l->io)) { while (!l->dead && pa_iochannel_is_readable(l->io)) {
ssize_t r; ssize_t r;
@ -289,7 +294,7 @@ static int do_read(pa_ioline *l) {
len = l->rbuf_length - l->rbuf_index - l->rbuf_valid_length; len = l->rbuf_length - l->rbuf_index - l->rbuf_valid_length;
assert(len >= READ_SIZE); pa_assert(len >= READ_SIZE);
/* Read some data */ /* Read some data */
if ((r = pa_iochannel_read(l->io, l->rbuf+l->rbuf_index+l->rbuf_valid_length, len)) <= 0) { if ((r = pa_iochannel_read(l->io, l->rbuf+l->rbuf_index+l->rbuf_valid_length, len)) <= 0) {
@ -314,7 +319,9 @@ static int do_read(pa_ioline *l) {
/* Try to flush the buffer */ /* Try to flush the buffer */
static int do_write(pa_ioline *l) { static int do_write(pa_ioline *l) {
ssize_t r; ssize_t r;
assert(l && l->ref >= 1);
pa_assert(l);
pa_assert(PA_REFCNT_VALUE(l) >= 1);
while (!l->dead && pa_iochannel_is_writable(l->io) && l->wbuf_valid_length) { while (!l->dead && pa_iochannel_is_writable(l->io) && l->wbuf_valid_length) {
@ -341,8 +348,8 @@ static int do_write(pa_ioline *l) {
/* Try to flush read/write data */ /* Try to flush read/write data */
static void do_work(pa_ioline *l) { static void do_work(pa_ioline *l) {
assert(l); pa_assert(l);
assert(l->ref >= 1); pa_assert(PA_REFCNT_VALUE(l) >= 1);
pa_ioline_ref(l); pa_ioline_ref(l);
@ -362,21 +369,28 @@ static void do_work(pa_ioline *l) {
static void io_callback(pa_iochannel*io, void *userdata) { static void io_callback(pa_iochannel*io, void *userdata) {
pa_ioline *l = userdata; pa_ioline *l = userdata;
assert(io && l && l->ref >= 1);
pa_assert(io);
pa_assert(l);
pa_assert(PA_REFCNT_VALUE(l) >= 1);
do_work(l); do_work(l);
} }
static void defer_callback(pa_mainloop_api*m, pa_defer_event*e, void *userdata) { static void defer_callback(pa_mainloop_api*m, pa_defer_event*e, void *userdata) {
pa_ioline *l = userdata; pa_ioline *l = userdata;
assert(l && l->ref >= 1 && l->mainloop == m && l->defer_event == e);
pa_assert(l);
pa_assert(PA_REFCNT_VALUE(l) >= 1);
pa_assert(l->mainloop == m);
pa_assert(l->defer_event == e);
do_work(l); do_work(l);
} }
void pa_ioline_defer_close(pa_ioline *l) { void pa_ioline_defer_close(pa_ioline *l) {
assert(l); pa_assert(l);
assert(l->ref >= 1); pa_assert(PA_REFCNT_VALUE(l) >= 1);
l->defer_close = 1; l->defer_close = 1;
@ -388,8 +402,8 @@ void pa_ioline_printf(pa_ioline *l, const char *format, ...) {
char *t; char *t;
va_list ap; va_list ap;
assert(l); pa_assert(l);
assert(l->ref >= 1); pa_assert(PA_REFCNT_VALUE(l) >= 1);
va_start(ap, format); va_start(ap, format);
t = pa_vsprintf_malloc(format, ap); t = pa_vsprintf_malloc(format, ap);

View file

@ -46,13 +46,13 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#endif #endif
#include "winsock.h"
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/llist.h> #include <pulsecore/llist.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include <pulsecore/winsock.h>
#ifndef HAVE_INET_PTON #ifndef HAVE_INET_PTON
#include "inet_pton.h" #include "inet_pton.h"
@ -77,7 +77,7 @@ pa_ip_acl* pa_ip_acl_new(const char *s) {
char *a; char *a;
pa_ip_acl *acl; pa_ip_acl *acl;
assert(s); pa_assert(s);
acl = pa_xnew(pa_ip_acl, 1); acl = pa_xnew(pa_ip_acl, 1);
PA_LLIST_HEAD_INIT(struct acl_entry, acl->entries); PA_LLIST_HEAD_INIT(struct acl_entry, acl->entries);
@ -91,7 +91,7 @@ pa_ip_acl* pa_ip_acl_new(const char *s) {
*slash = 0; *slash = 0;
slash++; slash++;
if (pa_atou(slash, &bits) < 0) { if (pa_atou(slash, &bits) < 0) {
pa_log("failed to parse number of bits: %s", slash); pa_log_warn("Failed to parse number of bits: %s", slash);
goto fail; goto fail;
} }
} else } else
@ -102,7 +102,7 @@ pa_ip_acl* pa_ip_acl_new(const char *s) {
e.bits = bits == (uint32_t) -1 ? 32 : (int) bits; e.bits = bits == (uint32_t) -1 ? 32 : (int) bits;
if (e.bits > 32) { if (e.bits > 32) {
pa_log("number of bits out of range: %i", e.bits); pa_log_warn("Number of bits out of range: %i", e.bits);
goto fail; goto fail;
} }
@ -116,7 +116,7 @@ pa_ip_acl* pa_ip_acl_new(const char *s) {
e.bits = bits == (uint32_t) -1 ? 128 : (int) bits; e.bits = bits == (uint32_t) -1 ? 128 : (int) bits;
if (e.bits > 128) { if (e.bits > 128) {
pa_log("number of bits out of range: %i", e.bits); pa_log_warn("Number of bits out of range: %i", e.bits);
goto fail; goto fail;
} }
e.family = AF_INET6; e.family = AF_INET6;
@ -142,7 +142,7 @@ pa_ip_acl* pa_ip_acl_new(const char *s) {
} }
} else { } else {
pa_log("failed to parse address: %s", a); pa_log_warn("Failed to parse address: %s", a);
goto fail; goto fail;
} }
@ -162,7 +162,7 @@ fail:
} }
void pa_ip_acl_free(pa_ip_acl *acl) { void pa_ip_acl_free(pa_ip_acl *acl) {
assert(acl); pa_assert(acl);
while (acl->entries) { while (acl->entries) {
struct acl_entry *e = acl->entries; struct acl_entry *e = acl->entries;
@ -178,8 +178,8 @@ int pa_ip_acl_check(pa_ip_acl *acl, int fd) {
struct acl_entry *e; struct acl_entry *e;
socklen_t salen; socklen_t salen;
assert(acl); pa_assert(acl);
assert(fd >= 0); pa_assert(fd >= 0);
salen = sizeof(sa); salen = sizeof(sa);
if (getpeername(fd, (struct sockaddr*) &sa, &salen) < 0) if (getpeername(fd, (struct sockaddr*) &sa, &salen) < 0)

View file

@ -27,10 +27,10 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h>
#include <string.h> #include <string.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulsecore/macro.h>
#include "mcalign.h" #include "mcalign.h"
@ -41,7 +41,7 @@ struct pa_mcalign {
pa_mcalign *pa_mcalign_new(size_t base) { pa_mcalign *pa_mcalign_new(size_t base) {
pa_mcalign *m; pa_mcalign *m;
assert(base); pa_assert(base);
m = pa_xnew(pa_mcalign, 1); m = pa_xnew(pa_mcalign, 1);
@ -53,7 +53,7 @@ pa_mcalign *pa_mcalign_new(size_t base) {
} }
void pa_mcalign_free(pa_mcalign *m) { void pa_mcalign_free(pa_mcalign *m) {
assert(m); pa_assert(m);
if (m->leftover.memblock) if (m->leftover.memblock)
pa_memblock_unref(m->leftover.memblock); pa_memblock_unref(m->leftover.memblock);
@ -65,13 +65,13 @@ void pa_mcalign_free(pa_mcalign *m) {
} }
void pa_mcalign_push(pa_mcalign *m, const pa_memchunk *c) { void pa_mcalign_push(pa_mcalign *m, const pa_memchunk *c) {
assert(m); pa_assert(m);
assert(c); pa_assert(c);
assert(c->memblock); pa_assert(c->memblock);
assert(c->length > 0); pa_assert(c->length > 0);
assert(!m->current.memblock); pa_assert(!m->current.memblock);
/* Append to the leftover memory block */ /* Append to the leftover memory block */
if (m->leftover.memblock) { if (m->leftover.memblock) {
@ -94,7 +94,7 @@ void pa_mcalign_push(pa_mcalign *m, const pa_memchunk *c) {
void *lo_data, *m_data; void *lo_data, *m_data;
/* We have to copy */ /* We have to copy */
assert(m->leftover.length < m->base); pa_assert(m->leftover.length < m->base);
l = m->base - m->leftover.length; l = m->base - m->leftover.length;
if (l > c->length) if (l > c->length)
@ -110,8 +110,8 @@ void pa_mcalign_push(pa_mcalign *m, const pa_memchunk *c) {
pa_memblock_release(c->memblock); pa_memblock_release(c->memblock);
m->leftover.length += l; m->leftover.length += l;
assert(m->leftover.length <= m->base); pa_assert(m->leftover.length <= m->base);
assert(m->leftover.length <= pa_memblock_get_length(m->leftover.memblock)); pa_assert(m->leftover.length <= pa_memblock_get_length(m->leftover.memblock));
if (c->length > l) { if (c->length > l) {
/* Save the remainder of the memory block */ /* Save the remainder of the memory block */
@ -134,12 +134,13 @@ void pa_mcalign_push(pa_mcalign *m, const pa_memchunk *c) {
} }
int pa_mcalign_pop(pa_mcalign *m, pa_memchunk *c) { int pa_mcalign_pop(pa_mcalign *m, pa_memchunk *c) {
assert(m); pa_assert(m);
assert(c); pa_assert(c);
/* First test if there's a leftover memory block available */ /* First test if there's a leftover memory block available */
if (m->leftover.memblock) { if (m->leftover.memblock) {
assert(m->leftover.length > 0 && m->leftover.length <= m->base); pa_assert(m->leftover.length > 0);
pa_assert(m->leftover.length <= m->base);
/* The leftover memory block is not yet complete */ /* The leftover memory block is not yet complete */
if (m->leftover.length < m->base) if (m->leftover.length < m->base)
@ -161,13 +162,13 @@ int pa_mcalign_pop(pa_mcalign *m, pa_memchunk *c) {
/* Now let's see if there is other data available */ /* Now let's see if there is other data available */
if (m->current.memblock) { if (m->current.memblock) {
size_t l; size_t l;
assert(m->current.length >= m->base); pa_assert(m->current.length >= m->base);
/* The length of the returned memory block */ /* The length of the returned memory block */
l = m->current.length; l = m->current.length;
l /= m->base; l /= m->base;
l *= m->base; l *= m->base;
assert(l > 0); pa_assert(l > 0);
/* Prepare the returned block */ /* Prepare the returned block */
*c = m->current; *c = m->current;
@ -175,7 +176,7 @@ int pa_mcalign_pop(pa_mcalign *m, pa_memchunk *c) {
c->length = l; c->length = l;
/* Drop that from the current memory block */ /* Drop that from the current memory block */
assert(l <= m->current.length); pa_assert(l <= m->current.length);
m->current.index += l; m->current.index += l;
m->current.length -= l; m->current.length -= l;
@ -184,7 +185,7 @@ int pa_mcalign_pop(pa_mcalign *m, pa_memchunk *c) {
pa_memblock_unref(m->current.memblock); pa_memblock_unref(m->current.memblock);
else { else {
/* Move the raimainder to leftover */ /* Move the raimainder to leftover */
assert(m->current.length < m->base && !m->leftover.memblock); pa_assert(m->current.length < m->base && !m->leftover.memblock);
m->leftover = m->current; m->leftover = m->current;
} }
@ -200,10 +201,10 @@ int pa_mcalign_pop(pa_mcalign *m, pa_memchunk *c) {
} }
size_t pa_mcalign_csize(pa_mcalign *m, size_t l) { size_t pa_mcalign_csize(pa_mcalign *m, size_t l) {
assert(m); pa_assert(m);
assert(l > 0); pa_assert(l > 0);
assert(!m->current.memblock); pa_assert(!m->current.memblock);
if (m->leftover.memblock) if (m->leftover.memblock)
l += m->leftover.length; l += m->leftover.length;

View file

@ -28,7 +28,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>

View file

@ -27,7 +27,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
@ -42,8 +41,8 @@ pa_memchunk* pa_memchunk_make_writable(pa_memchunk *c, size_t min) {
size_t l; size_t l;
void *tdata, *sdata; void *tdata, *sdata;
assert(c); pa_assert(c);
assert(c->memblock); pa_assert(c->memblock);
if (pa_memblock_ref_is_one(c->memblock) && if (pa_memblock_ref_is_one(c->memblock) &&
!pa_memblock_is_read_only(c->memblock) && !pa_memblock_is_read_only(c->memblock) &&
@ -68,7 +67,7 @@ pa_memchunk* pa_memchunk_make_writable(pa_memchunk *c, size_t min) {
} }
pa_memchunk* pa_memchunk_reset(pa_memchunk *c) { pa_memchunk* pa_memchunk_reset(pa_memchunk *c) {
assert(c); pa_assert(c);
c->memblock = NULL; c->memblock = NULL;
c->length = c->index = 0; c->length = c->index = 0;

View file

@ -26,7 +26,6 @@
#endif #endif
#include <ctype.h> #include <ctype.h>
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -39,6 +38,7 @@
#include <pulsecore/sink.h> #include <pulsecore/sink.h>
#include <pulsecore/source.h> #include <pulsecore/source.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/macro.h>
#include "modargs.h" #include "modargs.h"
@ -48,7 +48,10 @@ struct entry {
static int add_key_value(pa_hashmap *map, char *key, char *value, const char* const valid_keys[]) { static int add_key_value(pa_hashmap *map, char *key, char *value, const char* const valid_keys[]) {
struct entry *e; struct entry *e;
assert(map && key && value);
pa_assert(map);
pa_assert(key);
pa_assert(value);
if (valid_keys) { if (valid_keys) {
const char*const* v; const char*const* v;
@ -63,10 +66,11 @@ static int add_key_value(pa_hashmap *map, char *key, char *value, const char* co
} }
} }
e = pa_xmalloc(sizeof(struct entry)); e = pa_xnew(struct entry, 1);
e->key = key; e->key = key;
e->value = value; e->value = value;
pa_hashmap_put(map, key, e); pa_hashmap_put(map, key, e);
return 0; return 0;
} }
@ -74,7 +78,6 @@ pa_modargs *pa_modargs_new(const char *args, const char* const* valid_keys) {
pa_hashmap *map = NULL; pa_hashmap *map = NULL;
map = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); map = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
assert(map);
if (args) { if (args) {
enum { WHITESPACE, KEY, VALUE_START, VALUE_SIMPLE, VALUE_DOUBLE_QUOTES, VALUE_TICKS } state; enum { WHITESPACE, KEY, VALUE_START, VALUE_SIMPLE, VALUE_DOUBLE_QUOTES, VALUE_TICKS } state;
@ -166,10 +169,10 @@ fail:
return NULL; return NULL;
} }
static void free_func(void *p, PA_GCC_UNUSED void*userdata) { static void free_func(void *p, PA_GCC_UNUSED void*userdata) {
struct entry *e = p; struct entry *e = p;
assert(e); pa_assert(e);
pa_xfree(e->key); pa_xfree(e->key);
pa_xfree(e->value); pa_xfree(e->value);
pa_xfree(e); pa_xfree(e);
@ -192,7 +195,10 @@ const char *pa_modargs_get_value(pa_modargs *ma, const char *key, const char *de
int pa_modargs_get_value_u32(pa_modargs *ma, const char *key, uint32_t *value) { int pa_modargs_get_value_u32(pa_modargs *ma, const char *key, uint32_t *value) {
const char *v; const char *v;
assert(ma && key && value);
pa_assert(ma);
pa_assert(key);
pa_assert(value);
if (!(v = pa_modargs_get_value(ma, key, NULL))) if (!(v = pa_modargs_get_value(ma, key, NULL)))
return 0; return 0;
@ -205,7 +211,10 @@ int pa_modargs_get_value_u32(pa_modargs *ma, const char *key, uint32_t *value) {
int pa_modargs_get_value_s32(pa_modargs *ma, const char *key, int32_t *value) { int pa_modargs_get_value_s32(pa_modargs *ma, const char *key, int32_t *value) {
const char *v; const char *v;
assert(ma && key && value);
pa_assert(ma);
pa_assert(key);
pa_assert(value);
if (!(v = pa_modargs_get_value(ma, key, NULL))) if (!(v = pa_modargs_get_value(ma, key, NULL)))
return 0; return 0;
@ -219,7 +228,10 @@ int pa_modargs_get_value_s32(pa_modargs *ma, const char *key, int32_t *value) {
int pa_modargs_get_value_boolean(pa_modargs *ma, const char *key, int *value) { int pa_modargs_get_value_boolean(pa_modargs *ma, const char *key, int *value) {
const char *v; const char *v;
int r; int r;
assert(ma && key && value);
pa_assert(ma);
pa_assert(key);
pa_assert(value);
if (!(v = pa_modargs_get_value(ma, key, NULL))) if (!(v = pa_modargs_get_value(ma, key, NULL)))
return 0; return 0;
@ -238,9 +250,9 @@ int pa_modargs_get_sample_spec(pa_modargs *ma, pa_sample_spec *rss) {
const char *format; const char *format;
uint32_t channels; uint32_t channels;
pa_sample_spec ss; pa_sample_spec ss;
assert(ma && rss);
/* DEBUG_TRAP;*/ pa_assert(ma);
pa_assert(rss);
ss = *rss; ss = *rss;
if ((pa_modargs_get_value_u32(ma, "rate", &ss.rate)) < 0) if ((pa_modargs_get_value_u32(ma, "rate", &ss.rate)) < 0)
@ -267,8 +279,8 @@ int pa_modargs_get_channel_map(pa_modargs *ma, pa_channel_map *rmap) {
pa_channel_map map; pa_channel_map map;
const char *cm; const char *cm;
assert(ma); pa_assert(ma);
assert(rmap); pa_assert(rmap);
map = *rmap; map = *rmap;
@ -287,9 +299,9 @@ int pa_modargs_get_sample_spec_and_channel_map(pa_modargs *ma, pa_sample_spec *r
pa_sample_spec ss; pa_sample_spec ss;
pa_channel_map map; pa_channel_map map;
assert(ma); pa_assert(ma);
assert(rss); pa_assert(rss);
assert(rmap); pa_assert(rmap);
ss = *rss; ss = *rss;

View file

@ -82,7 +82,7 @@ pa_modinfo *pa_modinfo_get_by_name(const char *name) {
} }
void pa_modinfo_free(pa_modinfo *i) { void pa_modinfo_free(pa_modinfo *i) {
assert(i); pa_assert(i);
pa_xfree(i->author); pa_xfree(i->author);
pa_xfree(i->description); pa_xfree(i->description);

View file

@ -157,7 +157,8 @@ static void pa_module_free(pa_module *m) {
} }
void pa_module_unload(pa_core *c, pa_module *m) { void pa_module_unload(pa_core *c, pa_module *m) {
pa_assert(c && m); pa_assert(c);
pa_assert(m);
pa_assert(c->modules); pa_assert(c->modules);
if (!(m = pa_idxset_remove_by_data(c->modules, m, NULL))) if (!(m = pa_idxset_remove_by_data(c->modules, m, NULL)))

View file

@ -25,18 +25,13 @@
#include <config.h> #include <config.h>
#endif #endif
#include <assert.h>
#include <pthread.h> #include <pthread.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulsecore/macro.h>
#include "mutex.h" #include "mutex.h"
#define ASSERT_SUCCESS(x) do { \
int _r = (x); \
assert(_r == 0); \
} while(0)
struct pa_mutex { struct pa_mutex {
pthread_mutex_t mutex; pthread_mutex_t mutex;
}; };
@ -52,61 +47,59 @@ pa_mutex* pa_mutex_new(int recursive) {
pthread_mutexattr_init(&attr); pthread_mutexattr_init(&attr);
if (recursive) if (recursive)
ASSERT_SUCCESS(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE)); pa_assert_se(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) == 0);
m = pa_xnew(pa_mutex, 1); m = pa_xnew(pa_mutex, 1);
pa_assert_se(pthread_mutex_init(&m->mutex, &attr) == 0);
ASSERT_SUCCESS(pthread_mutex_init(&m->mutex, &attr));
return m; return m;
} }
void pa_mutex_free(pa_mutex *m) { void pa_mutex_free(pa_mutex *m) {
assert(m); pa_assert(m);
ASSERT_SUCCESS(pthread_mutex_destroy(&m->mutex)); pa_assert_se(pthread_mutex_destroy(&m->mutex) == 0);
pa_xfree(m); pa_xfree(m);
} }
void pa_mutex_lock(pa_mutex *m) { void pa_mutex_lock(pa_mutex *m) {
assert(m); pa_assert(m);
ASSERT_SUCCESS(pthread_mutex_lock(&m->mutex)); pa_assert_se(pthread_mutex_lock(&m->mutex) == 0);
} }
void pa_mutex_unlock(pa_mutex *m) { void pa_mutex_unlock(pa_mutex *m) {
assert(m); pa_assert(m);
ASSERT_SUCCESS(pthread_mutex_unlock(&m->mutex)); pa_assert_se(pthread_mutex_unlock(&m->mutex) == 0);
} }
pa_cond *pa_cond_new(void) { pa_cond *pa_cond_new(void) {
pa_cond *c; pa_cond *c;
c = pa_xnew(pa_cond, 1); c = pa_xnew(pa_cond, 1);
pa_assert_se(pthread_cond_init(&c->cond, NULL) == 0);
ASSERT_SUCCESS(pthread_cond_init(&c->cond, NULL));
return c; return c;
} }
void pa_cond_free(pa_cond *c) { void pa_cond_free(pa_cond *c) {
assert(c); pa_assert(c);
ASSERT_SUCCESS(pthread_cond_destroy(&c->cond)); pa_assert_se(pthread_cond_destroy(&c->cond) == 0);
pa_xfree(c); pa_xfree(c);
} }
void pa_cond_signal(pa_cond *c, int broadcast) { void pa_cond_signal(pa_cond *c, int broadcast) {
assert(c); pa_assert(c);
if (broadcast) if (broadcast)
ASSERT_SUCCESS(pthread_cond_broadcast(&c->cond)); pa_assert_se(pthread_cond_broadcast(&c->cond) == 0);
else else
ASSERT_SUCCESS(pthread_cond_signal(&c->cond)); pa_assert_se(pthread_cond_signal(&c->cond) == 0);
} }
int pa_cond_wait(pa_cond *c, pa_mutex *m) { int pa_cond_wait(pa_cond *c, pa_mutex *m) {
assert(c); pa_assert(c);
assert(m); pa_assert(m);
return pthread_cond_wait(&c->cond, &m->mutex); return pthread_cond_wait(&c->cond, &m->mutex);
} }

View file

@ -27,7 +27,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -38,6 +37,7 @@
#include <pulsecore/sink.h> #include <pulsecore/sink.h>
#include <pulsecore/core-subscribe.h> #include <pulsecore/core-subscribe.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/macro.h>
#include "namereg.h" #include "namereg.h"
@ -90,23 +90,22 @@ static char* cleanup_name(const char *name) {
} }
void pa_namereg_free(pa_core *c) { void pa_namereg_free(pa_core *c) {
assert(c); pa_assert(c);
if (!c->namereg) if (!c->namereg)
return; return;
assert(pa_hashmap_size(c->namereg) == 0); pa_assert(pa_hashmap_size(c->namereg) == 0);
pa_hashmap_free(c->namereg, NULL, NULL); pa_hashmap_free(c->namereg, NULL, NULL);
} }
const char *pa_namereg_register(pa_core *c, const char *name, pa_namereg_type_t type, void *data, int fail) { const char *pa_namereg_register(pa_core *c, const char *name, pa_namereg_type_t type, void *data, int fail) {
struct namereg_entry *e; struct namereg_entry *e;
char *n = NULL; char *n = NULL;
int r;
assert(c); pa_assert(c);
assert(name); pa_assert(name);
assert(data); pa_assert(data);
if (!*name) if (!*name)
return NULL; return NULL;
@ -163,8 +162,7 @@ const char *pa_namereg_register(pa_core *c, const char *name, pa_namereg_type_t
e->name = n ? n : pa_xstrdup(name); e->name = n ? n : pa_xstrdup(name);
e->data = data; e->data = data;
r = pa_hashmap_put(c->namereg, e->name, e); pa_assert_se(pa_hashmap_put(c->namereg, e->name, e) >= 0);
assert (r >= 0);
return e->name; return e->name;
} }
@ -172,11 +170,10 @@ const char *pa_namereg_register(pa_core *c, const char *name, pa_namereg_type_t
void pa_namereg_unregister(pa_core *c, const char *name) { void pa_namereg_unregister(pa_core *c, const char *name) {
struct namereg_entry *e; struct namereg_entry *e;
assert(c); pa_assert(c);
assert(name); pa_assert(name);
e = pa_hashmap_remove(c->namereg, name); pa_assert_se(e = pa_hashmap_remove(c->namereg, name));
assert(e);
pa_xfree(e->name); pa_xfree(e->name);
pa_xfree(e); pa_xfree(e);
@ -185,7 +182,7 @@ void pa_namereg_unregister(pa_core *c, const char *name) {
void* pa_namereg_get(pa_core *c, const char *name, pa_namereg_type_t type, int autoload) { void* pa_namereg_get(pa_core *c, const char *name, pa_namereg_type_t type, int autoload) {
struct namereg_entry *e; struct namereg_entry *e;
uint32_t idx; uint32_t idx;
assert(c); pa_assert(c);
if (!name) { if (!name) {
@ -245,8 +242,8 @@ void* pa_namereg_get(pa_core *c, const char *name, pa_namereg_type_t type, int a
int pa_namereg_set_default(pa_core*c, const char *name, pa_namereg_type_t type) { int pa_namereg_set_default(pa_core*c, const char *name, pa_namereg_type_t type) {
char **s; char **s;
assert(c); pa_assert(c);
assert(type == PA_NAMEREG_SINK || type == PA_NAMEREG_SOURCE); pa_assert(type == PA_NAMEREG_SINK || type == PA_NAMEREG_SOURCE);
s = type == PA_NAMEREG_SINK ? &c->default_sink_name : &c->default_source_name; s = type == PA_NAMEREG_SINK ? &c->default_sink_name : &c->default_source_name;
@ -269,7 +266,7 @@ int pa_namereg_set_default(pa_core*c, const char *name, pa_namereg_type_t type)
const char *pa_namereg_get_default_sink_name(pa_core *c) { const char *pa_namereg_get_default_sink_name(pa_core *c) {
pa_sink *s; pa_sink *s;
assert(c); pa_assert(c);
if (c->default_sink_name) if (c->default_sink_name)
return c->default_sink_name; return c->default_sink_name;
@ -284,7 +281,7 @@ const char *pa_namereg_get_default_source_name(pa_core *c) {
pa_source *s; pa_source *s;
uint32_t idx; uint32_t idx;
assert(c); pa_assert(c);
if (c->default_source_name) if (c->default_source_name)
return c->default_source_name; return c->default_source_name;

View file

@ -25,22 +25,22 @@
#include <config.h> #include <config.h>
#endif #endif
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulsecore/macro.h>
#include "packet.h" #include "packet.h"
pa_packet* pa_packet_new(size_t length) { pa_packet* pa_packet_new(size_t length) {
pa_packet *p; pa_packet *p;
assert(length); pa_assert(length > 0);
p = pa_xmalloc(sizeof(pa_packet)+length); p = pa_xmalloc(PA_ALIGN(sizeof(pa_packet)) + length);
p->ref = 1; PA_REFCNT_INIT(p);
p->length = length; p->length = length;
p->data = (uint8_t*) (p+1); p->data = (uint8_t*) p + PA_ALIGN(sizeof(pa_packet));
p->type = PA_PACKET_APPENDED; p->type = PA_PACKET_APPENDED;
return p; return p;
@ -49,11 +49,11 @@ pa_packet* pa_packet_new(size_t length) {
pa_packet* pa_packet_new_dynamic(void* data, size_t length) { pa_packet* pa_packet_new_dynamic(void* data, size_t length) {
pa_packet *p; pa_packet *p;
assert(data); pa_assert(data);
assert(length); pa_assert(length > 0);
p = pa_xnew(pa_packet, 1); p = pa_xnew(pa_packet, 1);
p->ref = 1; PA_REFCNT_INIT(p);
p->length = length; p->length = length;
p->data = data; p->data = data;
p->type = PA_PACKET_DYNAMIC; p->type = PA_PACKET_DYNAMIC;
@ -62,18 +62,18 @@ pa_packet* pa_packet_new_dynamic(void* data, size_t length) {
} }
pa_packet* pa_packet_ref(pa_packet *p) { pa_packet* pa_packet_ref(pa_packet *p) {
assert(p); pa_assert(p);
assert(p->ref >= 1); pa_assert(PA_REFCNT_VALUE(p) >= 1);
p->ref++; PA_REFCNT_INC(p);
return p; return p;
} }
void pa_packet_unref(pa_packet *p) { void pa_packet_unref(pa_packet *p) {
assert(p); pa_assert(p);
assert(p->ref >= 1); pa_assert(PA_REFCNT_VALUE(p) >= 1);
if (--p->ref == 0) { if (PA_REFCNT_DEC(p) <= 0) {
if (p->type == PA_PACKET_DYNAMIC) if (p->type == PA_PACKET_DYNAMIC)
pa_xfree(p->data); pa_xfree(p->data);
pa_xfree(p); pa_xfree(p);

View file

@ -27,9 +27,11 @@
#include <sys/types.h> #include <sys/types.h>
#include <inttypes.h> #include <inttypes.h>
#include <pulsecore/refcnt.h>
typedef struct pa_packet { typedef struct pa_packet {
PA_REFCNT_DECLARE;
enum { PA_PACKET_APPENDED, PA_PACKET_DYNAMIC } type; enum { PA_PACKET_APPENDED, PA_PACKET_DYNAMIC } type;
unsigned ref;
size_t length; size_t length;
uint8_t *data; uint8_t *data;
} pa_packet; } pa_packet;

View file

@ -26,13 +26,13 @@
#endif #endif
#include <string.h> #include <string.h>
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulse/util.h> #include <pulse/util.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/macro.h>
#include "parseaddr.h" #include "parseaddr.h"
@ -45,7 +45,9 @@
* Return a newly allocated string of the hostname and fill in *ret_port if specified */ * Return a newly allocated string of the hostname and fill in *ret_port if specified */
static char *parse_host(const char *s, uint16_t *ret_port) { static char *parse_host(const char *s, uint16_t *ret_port) {
assert(s && ret_port); pa_assert(s);
pa_assert(ret_port);
if (*s == '[') { if (*s == '[') {
char *e; char *e;
if (!(e = strchr(s+1, ']'))) if (!(e = strchr(s+1, ']')))
@ -70,7 +72,10 @@ static char *parse_host(const char *s, uint16_t *ret_port) {
int pa_parse_address(const char *name, pa_parsed_address *ret_p) { int pa_parse_address(const char *name, pa_parsed_address *ret_p) {
const char *p; const char *p;
assert(name && ret_p);
pa_assert(name);
pa_assert(ret_p);
memset(ret_p, 0, sizeof(pa_parsed_address)); memset(ret_p, 0, sizeof(pa_parsed_address));
ret_p->type = PA_PARSED_ADDRESS_TCP_AUTO; ret_p->type = PA_PARSED_ADDRESS_TCP_AUTO;
@ -112,6 +117,5 @@ int pa_parse_address(const char *name, pa_parsed_address *ret_p) {
if (!(ret_p->path_or_host = parse_host(p, &ret_p->port))) if (!(ret_p->path_or_host = parse_host(p, &ret_p->port)))
return -1; return -1;
return 0; return 0;
} }

View file

@ -28,7 +28,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h>
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
@ -37,6 +36,8 @@
#include <pulsecore/llist.h> #include <pulsecore/llist.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/macro.h>
#include <pulsecore/refcnt.h>
#include "pdispatch.h" #include "pdispatch.h"
@ -108,7 +109,7 @@ struct reply_info {
}; };
struct pa_pdispatch { struct pa_pdispatch {
int ref; PA_REFCNT_DECLARE;
pa_mainloop_api *mainloop; pa_mainloop_api *mainloop;
const pa_pdispatch_cb_t *callback_table; const pa_pdispatch_cb_t *callback_table;
unsigned n_commands; unsigned n_commands;
@ -119,7 +120,9 @@ struct pa_pdispatch {
}; };
static void reply_info_free(struct reply_info *r) { static void reply_info_free(struct reply_info *r) {
assert(r && r->pdispatch && r->pdispatch->mainloop); pa_assert(r);
pa_assert(r->pdispatch);
pa_assert(r->pdispatch->mainloop);
if (r->time_event) if (r->time_event)
r->pdispatch->mainloop->time_free(r->time_event); r->pdispatch->mainloop->time_free(r->time_event);
@ -131,12 +134,12 @@ static void reply_info_free(struct reply_info *r) {
pa_pdispatch* pa_pdispatch_new(pa_mainloop_api *mainloop, const pa_pdispatch_cb_t*table, unsigned entries) { pa_pdispatch* pa_pdispatch_new(pa_mainloop_api *mainloop, const pa_pdispatch_cb_t*table, unsigned entries) {
pa_pdispatch *pd; pa_pdispatch *pd;
assert(mainloop); pa_assert(mainloop);
assert((entries && table) || (!entries && !table)); pa_assert((entries && table) || (!entries && !table));
pd = pa_xmalloc(sizeof(pa_pdispatch)); pd = pa_xnew(pa_pdispatch, 1);
pd->ref = 1; PA_REFCNT_INIT(pd);
pd->mainloop = mainloop; pd->mainloop = mainloop;
pd->callback_table = table; pd->callback_table = table;
pd->n_commands = entries; pd->n_commands = entries;
@ -149,7 +152,7 @@ pa_pdispatch* pa_pdispatch_new(pa_mainloop_api *mainloop, const pa_pdispatch_cb_
} }
static void pdispatch_free(pa_pdispatch *pd) { static void pdispatch_free(pa_pdispatch *pd) {
assert(pd); pa_assert(pd);
while (pd->replies) { while (pd->replies) {
if (pd->replies->free_cb) if (pd->replies->free_cb)
@ -165,7 +168,7 @@ static void run_action(pa_pdispatch *pd, struct reply_info *r, uint32_t command,
pa_pdispatch_cb_t callback; pa_pdispatch_cb_t callback;
void *userdata; void *userdata;
uint32_t tag; uint32_t tag;
assert(r); pa_assert(r);
pa_pdispatch_ref(pd); pa_pdispatch_ref(pd);
@ -187,7 +190,12 @@ int pa_pdispatch_run(pa_pdispatch *pd, pa_packet*packet, const pa_creds *creds,
uint32_t tag, command; uint32_t tag, command;
pa_tagstruct *ts = NULL; pa_tagstruct *ts = NULL;
int ret = -1; int ret = -1;
assert(pd && packet && packet->data);
pa_assert(pd);
pa_assert(PA_REFCNT_VALUE(pd) >= 1);
pa_assert(packet);
pa_assert(PA_REFCNT_VALUE(packet) >= 1);
pa_assert(packet->data);
pa_pdispatch_ref(pd); pa_pdispatch_ref(pd);
@ -195,7 +203,6 @@ int pa_pdispatch_run(pa_pdispatch *pd, pa_packet*packet, const pa_creds *creds,
goto finish; goto finish;
ts = pa_tagstruct_new(packet->data, packet->length); ts = pa_tagstruct_new(packet->data, packet->length);
assert(ts);
if (pa_tagstruct_getu32(ts, &command) < 0 || if (pa_tagstruct_getu32(ts, &command) < 0 ||
pa_tagstruct_getu32(ts, &tag) < 0) pa_tagstruct_getu32(ts, &tag) < 0)
@ -248,7 +255,12 @@ finish:
static void timeout_callback(pa_mainloop_api*m, pa_time_event*e, PA_GCC_UNUSED const struct timeval *tv, void *userdata) { static void timeout_callback(pa_mainloop_api*m, pa_time_event*e, PA_GCC_UNUSED const struct timeval *tv, void *userdata) {
struct reply_info*r = userdata; struct reply_info*r = userdata;
assert(r && r->time_event == e && r->pdispatch && r->pdispatch->mainloop == m && r->callback);
pa_assert(r);
pa_assert(r->time_event == e);
pa_assert(r->pdispatch);
pa_assert(r->pdispatch->mainloop == m);
pa_assert(r->callback);
run_action(r->pdispatch, r, PA_COMMAND_TIMEOUT, NULL); run_action(r->pdispatch, r, PA_COMMAND_TIMEOUT, NULL);
} }
@ -256,7 +268,10 @@ static void timeout_callback(pa_mainloop_api*m, pa_time_event*e, PA_GCC_UNUSED c
void pa_pdispatch_register_reply(pa_pdispatch *pd, uint32_t tag, int timeout, pa_pdispatch_cb_t cb, void *userdata, pa_free_cb_t free_cb) { void pa_pdispatch_register_reply(pa_pdispatch *pd, uint32_t tag, int timeout, pa_pdispatch_cb_t cb, void *userdata, pa_free_cb_t free_cb) {
struct reply_info *r; struct reply_info *r;
struct timeval tv; struct timeval tv;
assert(pd && pd->ref >= 1 && cb);
pa_assert(pd);
pa_assert(PA_REFCNT_VALUE(pd) >= 1);
pa_assert(cb);
r = pa_xnew(struct reply_info, 1); r = pa_xnew(struct reply_info, 1);
r->pdispatch = pd; r->pdispatch = pd;
@ -268,21 +283,22 @@ void pa_pdispatch_register_reply(pa_pdispatch *pd, uint32_t tag, int timeout, pa
pa_gettimeofday(&tv); pa_gettimeofday(&tv);
tv.tv_sec += timeout; tv.tv_sec += timeout;
r->time_event = pd->mainloop->time_new(pd->mainloop, &tv, timeout_callback, r); pa_assert_se(r->time_event = pd->mainloop->time_new(pd->mainloop, &tv, timeout_callback, r));
assert(r->time_event);
PA_LLIST_PREPEND(struct reply_info, pd->replies, r); PA_LLIST_PREPEND(struct reply_info, pd->replies, r);
} }
int pa_pdispatch_is_pending(pa_pdispatch *pd) { int pa_pdispatch_is_pending(pa_pdispatch *pd) {
assert(pd); pa_assert(pd);
pa_assert(PA_REFCNT_VALUE(pd) >= 1);
return !!pd->replies; return !!pd->replies;
} }
void pa_pdispatch_set_drain_callback(pa_pdispatch *pd, void (*cb)(pa_pdispatch *pd, void *userdata), void *userdata) { void pa_pdispatch_set_drain_callback(pa_pdispatch *pd, void (*cb)(pa_pdispatch *pd, void *userdata), void *userdata) {
assert(pd); pa_assert(pd);
assert(!cb || pa_pdispatch_is_pending(pd)); pa_assert(PA_REFCNT_VALUE(pd) >= 1);
pa_assert(!cb || pa_pdispatch_is_pending(pd));
pd->drain_callback = cb; pd->drain_callback = cb;
pd->drain_userdata = userdata; pd->drain_userdata = userdata;
@ -290,7 +306,9 @@ void pa_pdispatch_set_drain_callback(pa_pdispatch *pd, void (*cb)(pa_pdispatch *
void pa_pdispatch_unregister_reply(pa_pdispatch *pd, void *userdata) { void pa_pdispatch_unregister_reply(pa_pdispatch *pd, void *userdata) {
struct reply_info *r, *n; struct reply_info *r, *n;
assert(pd);
pa_assert(pd);
pa_assert(PA_REFCNT_VALUE(pd) >= 1);
for (r = pd->replies; r; r = n) { for (r = pd->replies; r; r = n) {
n = r->next; n = r->next;
@ -301,21 +319,24 @@ void pa_pdispatch_unregister_reply(pa_pdispatch *pd, void *userdata) {
} }
void pa_pdispatch_unref(pa_pdispatch *pd) { void pa_pdispatch_unref(pa_pdispatch *pd) {
assert(pd && pd->ref >= 1); pa_assert(pd);
pa_assert(PA_REFCNT_VALUE(pd) >= 1);
if (!(--(pd->ref))) if (PA_REFCNT_DEC(pd) <= 0)
pdispatch_free(pd); pdispatch_free(pd);
} }
pa_pdispatch* pa_pdispatch_ref(pa_pdispatch *pd) { pa_pdispatch* pa_pdispatch_ref(pa_pdispatch *pd) {
assert(pd && pd->ref >= 1); pa_assert(pd);
pd->ref++; pa_assert(PA_REFCNT_VALUE(pd) >= 1);
PA_REFCNT_INC(pd);
return pd; return pd;
} }
const pa_creds * pa_pdispatch_creds(pa_pdispatch *pd) { const pa_creds * pa_pdispatch_creds(pa_pdispatch *pd) {
assert(pd); pa_assert(pd);
assert(pd->ref >= 1); pa_assert(PA_REFCNT_VALUE(pd) >= 1);
return pd->creds; return pd->creds;
} }

View file

@ -33,7 +33,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <limits.h> #include <limits.h>
#include <signal.h> #include <signal.h>
@ -47,6 +46,7 @@
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include "pid.h" #include "pid.h"
@ -57,7 +57,8 @@ static pid_t read_pid(const char *fn, int fd) {
char t[20], *e; char t[20], *e;
uint32_t pid; uint32_t pid;
assert(fn && fd >= 0); pa_assert(fn);
pa_assert(fd >= 0);
if ((r = pa_loop_read(fd, t, sizeof(t)-1, NULL)) < 0) { if ((r = pa_loop_read(fd, t, sizeof(t)-1, NULL)) < 0) {
pa_log_warn("WARNING: failed to read PID file '%s': %s", pa_log_warn("WARNING: failed to read PID file '%s': %s",
@ -73,7 +74,7 @@ static pid_t read_pid(const char *fn, int fd) {
*e = 0; *e = 0;
if (pa_atou(t, &pid) < 0) { if (pa_atou(t, &pid) < 0) {
pa_log("WARNING: failed to parse PID file '%s'", fn); pa_log_warn("WARNING: failed to parse PID file '%s'", fn);
return (pid_t) -1; return (pid_t) -1;
} }
@ -83,6 +84,8 @@ static pid_t read_pid(const char *fn, int fd) {
static int open_pid_file(const char *fn, int mode) { static int open_pid_file(const char *fn, int mode) {
int fd = -1; int fd = -1;
pa_assert(fn);
for (;;) { for (;;) {
struct stat st; struct stat st;
@ -238,7 +241,7 @@ fail:
if (fd >= 0) { if (fd >= 0) {
pa_lock_fd(fd, 0); pa_lock_fd(fd, 0);
close(fd); pa_assert_se(close(fd) == 0);
} }
return ret; return ret;
@ -280,7 +283,7 @@ fail:
if (fd >= 0) { if (fd >= 0) {
pa_lock_fd(fd, 0); pa_lock_fd(fd, 0);
close(fd); pa_assert_se(close(fd) == 0);
} }
return ret; return ret;

View file

@ -25,11 +25,9 @@
#include <config.h> #include <config.h>
#endif #endif
#include <assert.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include "props.h" #include "props.h"
@ -41,9 +39,11 @@ typedef struct pa_property {
/* Allocate a new property object */ /* Allocate a new property object */
static pa_property* property_new(const char *name, void *data) { static pa_property* property_new(const char *name, void *data) {
pa_property* p; pa_property* p;
assert(name && data);
p = pa_xmalloc(sizeof(pa_property)); pa_assert(name);
pa_assert(data);
p = pa_xnew(pa_property, 1);
p->name = pa_xstrdup(name); p->name = pa_xstrdup(name);
p->data = data; p->data = data;
@ -52,7 +52,7 @@ static pa_property* property_new(const char *name, void *data) {
/* Free a property object */ /* Free a property object */
static void property_free(pa_property *p) { static void property_free(pa_property *p) {
assert(p); pa_assert(p);
pa_xfree(p->name); pa_xfree(p->name);
pa_xfree(p); pa_xfree(p);
@ -60,7 +60,10 @@ static void property_free(pa_property *p) {
void* pa_property_get(pa_core *c, const char *name) { void* pa_property_get(pa_core *c, const char *name) {
pa_property *p; pa_property *p;
assert(c && name && c->properties);
pa_assert(c);
pa_assert(name);
pa_assert(c->properties);
if (!(p = pa_hashmap_get(c->properties, name))) if (!(p = pa_hashmap_get(c->properties, name)))
return NULL; return NULL;
@ -70,7 +73,11 @@ void* pa_property_get(pa_core *c, const char *name) {
int pa_property_set(pa_core *c, const char *name, void *data) { int pa_property_set(pa_core *c, const char *name, void *data) {
pa_property *p; pa_property *p;
assert(c && name && data && c->properties);
pa_assert(c);
pa_assert(name);
pa_assert(data);
pa_assert(c->properties);
if (pa_hashmap_get(c->properties, name)) if (pa_hashmap_get(c->properties, name))
return -1; return -1;
@ -82,7 +89,10 @@ int pa_property_set(pa_core *c, const char *name, void *data) {
int pa_property_remove(pa_core *c, const char *name) { int pa_property_remove(pa_core *c, const char *name) {
pa_property *p; pa_property *p;
assert(c && name && c->properties);
pa_assert(c);
pa_assert(name);
pa_assert(c->properties);
if (!(p = pa_hashmap_remove(c->properties, name))) if (!(p = pa_hashmap_remove(c->properties, name)))
return -1; return -1;
@ -92,18 +102,18 @@ int pa_property_remove(pa_core *c, const char *name) {
} }
void pa_property_init(pa_core *c) { void pa_property_init(pa_core *c) {
assert(c); pa_assert(c);
c->properties = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); c->properties = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
} }
void pa_property_cleanup(pa_core *c) { void pa_property_cleanup(pa_core *c) {
assert(c); pa_assert(c);
if (!c->properties) if (!c->properties)
return; return;
assert(!pa_hashmap_size(c->properties)); pa_assert(!pa_hashmap_size(c->properties));
pa_hashmap_free(c->properties, NULL, NULL); pa_hashmap_free(c->properties, NULL, NULL);
c->properties = NULL; c->properties = NULL;
@ -113,14 +123,17 @@ void pa_property_cleanup(pa_core *c) {
void pa_property_dump(pa_core *c, pa_strbuf *s) { void pa_property_dump(pa_core *c, pa_strbuf *s) {
void *state = NULL; void *state = NULL;
pa_property *p; pa_property *p;
assert(c && s);
pa_assert(c);
pa_assert(s);
while ((p = pa_hashmap_iterate(c->properties, &state, NULL))) while ((p = pa_hashmap_iterate(c->properties, &state, NULL)))
pa_strbuf_printf(s, "[%s] -> [%p]\n", p->name, p->data); pa_strbuf_printf(s, "[%s] -> [%p]\n", p->name, p->data);
} }
int pa_property_replace(pa_core *c, const char *name, void *data) { int pa_property_replace(pa_core *c, const char *name, void *data) {
assert(c && name); pa_assert(c);
pa_assert(name);
pa_property_remove(c, name); pa_property_remove(c, name);
return pa_property_set(c, name, data); return pa_property_set(c, name, data);

View file

@ -25,13 +25,13 @@
#include <config.h> #include <config.h>
#endif #endif
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulsecore/cli.h> #include <pulsecore/cli.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include "protocol-cli.h" #include "protocol-cli.h"
@ -47,7 +47,8 @@ struct pa_protocol_cli {
static void cli_eof_cb(pa_cli*c, void*userdata) { static void cli_eof_cb(pa_cli*c, void*userdata) {
pa_protocol_cli *p = userdata; pa_protocol_cli *p = userdata;
assert(p); pa_assert(p);
pa_idxset_remove_by_data(p->connections, c, NULL); pa_idxset_remove_by_data(p->connections, c, NULL);
pa_cli_free(c); pa_cli_free(c);
} }
@ -55,7 +56,10 @@ static void cli_eof_cb(pa_cli*c, void*userdata) {
static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata) { static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata) {
pa_protocol_cli *p = userdata; pa_protocol_cli *p = userdata;
pa_cli *c; pa_cli *c;
assert(s && io && p);
pa_assert(s);
pa_assert(io);
pa_assert(p);
if (pa_idxset_size(p->connections)+1 > MAX_CONNECTIONS) { if (pa_idxset_size(p->connections)+1 > MAX_CONNECTIONS) {
pa_log("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS); pa_log("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS);
@ -64,7 +68,6 @@ static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata)
} }
c = pa_cli_new(p->core, io, p->module); c = pa_cli_new(p->core, io, p->module);
assert(c);
pa_cli_set_eof_callback(c, cli_eof_cb, p); pa_cli_set_eof_callback(c, cli_eof_cb, p);
pa_idxset_put(p->connections, c, NULL); pa_idxset_put(p->connections, c, NULL);
@ -72,9 +75,11 @@ static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata)
pa_protocol_cli* pa_protocol_cli_new(pa_core *core, pa_socket_server *server, pa_module *m, PA_GCC_UNUSED pa_modargs *ma) { pa_protocol_cli* pa_protocol_cli_new(pa_core *core, pa_socket_server *server, pa_module *m, PA_GCC_UNUSED pa_modargs *ma) {
pa_protocol_cli* p; pa_protocol_cli* p;
assert(core && server);
p = pa_xmalloc(sizeof(pa_protocol_cli)); pa_core_assert_ref(core);
pa_assert(server);
p = pa_xnew(pa_protocol_cli, 1);
p->module = m; p->module = m;
p->core = core; p->core = core;
p->server = server; p->server = server;
@ -86,12 +91,13 @@ pa_protocol_cli* pa_protocol_cli_new(pa_core *core, pa_socket_server *server, pa
} }
static void free_connection(void *p, PA_GCC_UNUSED void *userdata) { static void free_connection(void *p, PA_GCC_UNUSED void *userdata) {
assert(p); pa_assert(p);
pa_cli_free(p); pa_cli_free(p);
} }
void pa_protocol_cli_free(pa_protocol_cli *p) { void pa_protocol_cli_free(pa_protocol_cli *p) {
assert(p); pa_assert(p);
pa_idxset_free(p->connections, free_connection, NULL); pa_idxset_free(p->connections, free_connection, NULL);
pa_socket_server_unref(p->server); pa_socket_server_unref(p->server);

View file

@ -25,7 +25,6 @@
#include <config.h> #include <config.h>
#endif #endif
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -34,6 +33,7 @@
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulsecore/ioline.h> #include <pulsecore/ioline.h>
#include <pulsecore/macro.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/namereg.h> #include <pulsecore/namereg.h>
#include <pulsecore/cli-text.h> #include <pulsecore/cli-text.h>
@ -65,9 +65,10 @@ struct pa_protocol_http {
static void http_response(struct connection *c, int code, const char *msg, const char *mime) { static void http_response(struct connection *c, int code, const char *msg, const char *mime) {
char s[256]; char s[256];
assert(c);
assert(msg); pa_assert(c);
assert(mime); pa_assert(msg);
pa_assert(mime);
pa_snprintf(s, sizeof(s), pa_snprintf(s, sizeof(s),
"HTTP/1.0 %i %s\n" "HTTP/1.0 %i %s\n"
@ -83,7 +84,7 @@ static void http_response(struct connection *c, int code, const char *msg, const
static void http_message(struct connection *c, int code, const char *msg, const char *text) { static void http_message(struct connection *c, int code, const char *msg, const char *text) {
char s[256]; char s[256];
assert(c); pa_assert(c);
http_response(c, code, msg, "text/html"); http_response(c, code, msg, "text/html");
@ -103,21 +104,22 @@ static void http_message(struct connection *c, int code, const char *msg, const
static void connection_free(struct connection *c, int del) { static void connection_free(struct connection *c, int del) {
assert(c); pa_assert(c);
if (c->url) if (c->url)
pa_xfree(c->url); pa_xfree(c->url);
if (del) if (del)
pa_idxset_remove_by_data(c->protocol->connections, c, NULL); pa_idxset_remove_by_data(c->protocol->connections, c, NULL);
pa_ioline_unref(c->line); pa_ioline_unref(c->line);
pa_xfree(c); pa_xfree(c);
} }
static void line_callback(pa_ioline *line, const char *s, void *userdata) { static void line_callback(pa_ioline *line, const char *s, void *userdata) {
struct connection *c = userdata; struct connection *c = userdata;
assert(line); pa_assert(line);
assert(c); pa_assert(c);
if (!s) { if (!s) {
/* EOF */ /* EOF */
@ -223,7 +225,10 @@ fail:
static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata) { static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata) {
pa_protocol_http *p = userdata; pa_protocol_http *p = userdata;
struct connection *c; struct connection *c;
assert(s && io && p);
pa_assert(s);
pa_assert(io);
pa_assert(p);
if (pa_idxset_size(p->connections)+1 > MAX_CONNECTIONS) { if (pa_idxset_size(p->connections)+1 > MAX_CONNECTIONS) {
pa_log_warn("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS); pa_log_warn("Warning! Too many connections (%u), dropping incoming connection.", MAX_CONNECTIONS);
@ -231,7 +236,7 @@ static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata)
return; return;
} }
c = pa_xmalloc(sizeof(struct connection)); c = pa_xnew(struct connection, 1);
c->protocol = p; c->protocol = p;
c->line = pa_ioline_new(io); c->line = pa_ioline_new(io);
c->state = REQUEST_LINE; c->state = REQUEST_LINE;
@ -243,9 +248,11 @@ static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata)
pa_protocol_http* pa_protocol_http_new(pa_core *core, pa_socket_server *server, pa_module *m, PA_GCC_UNUSED pa_modargs *ma) { pa_protocol_http* pa_protocol_http_new(pa_core *core, pa_socket_server *server, pa_module *m, PA_GCC_UNUSED pa_modargs *ma) {
pa_protocol_http* p; pa_protocol_http* p;
assert(core && server);
p = pa_xmalloc(sizeof(pa_protocol_http)); pa_core_assert_ref(core);
pa_assert(server);
p = pa_xnew(pa_protocol_http, 1);
p->module = m; p->module = m;
p->core = core; p->core = core;
p->server = server; p->server = server;
@ -257,12 +264,12 @@ pa_protocol_http* pa_protocol_http_new(pa_core *core, pa_socket_server *server,
} }
static void free_connection(void *p, PA_GCC_UNUSED void *userdata) { static void free_connection(void *p, PA_GCC_UNUSED void *userdata) {
assert(p); pa_assert(p);
connection_free(p, 0); connection_free(p, 0);
} }
void pa_protocol_http_free(pa_protocol_http *p) { void pa_protocol_http_free(pa_protocol_http *p) {
assert(p); pa_assert(p);
pa_idxset_free(p->connections, free_connection, NULL); pa_idxset_free(p->connections, free_connection, NULL);
pa_socket_server_unref(p->server); pa_socket_server_unref(p->server);

View file

@ -25,9 +25,8 @@
#include <config.h> #include <config.h>
#endif #endif
#include <assert.h>
#include <pulsecore/native-common.h> #include <pulsecore/native-common.h>
#include <pulsecore/macro.h>
#include "pstream-util.h" #include "pstream-util.h"
@ -35,20 +34,20 @@ void pa_pstream_send_tagstruct_with_creds(pa_pstream *p, pa_tagstruct *t, const
size_t length; size_t length;
uint8_t *data; uint8_t *data;
pa_packet *packet; pa_packet *packet;
assert(p);
assert(t);
data = pa_tagstruct_free_data(t, &length); pa_assert(p);
assert(data && length); pa_assert(t);
packet = pa_packet_new_dynamic(data, length);
assert(packet); pa_assert_se(data = pa_tagstruct_free_data(t, &length));
pa_assert_se(packet = pa_packet_new_dynamic(data, length));
pa_pstream_send_packet(p, packet, creds); pa_pstream_send_packet(p, packet, creds);
pa_packet_unref(packet); pa_packet_unref(packet);
} }
void pa_pstream_send_error(pa_pstream *p, uint32_t tag, uint32_t error) { void pa_pstream_send_error(pa_pstream *p, uint32_t tag, uint32_t error) {
pa_tagstruct *t = pa_tagstruct_new(NULL, 0); pa_tagstruct *t;
assert(t);
pa_assert_se(t = pa_tagstruct_new(NULL, 0));
pa_tagstruct_putu32(t, PA_COMMAND_ERROR); pa_tagstruct_putu32(t, PA_COMMAND_ERROR);
pa_tagstruct_putu32(t, tag); pa_tagstruct_putu32(t, tag);
pa_tagstruct_putu32(t, error); pa_tagstruct_putu32(t, error);
@ -56,8 +55,9 @@ void pa_pstream_send_error(pa_pstream *p, uint32_t tag, uint32_t error) {
} }
void pa_pstream_send_simple_ack(pa_pstream *p, uint32_t tag) { void pa_pstream_send_simple_ack(pa_pstream *p, uint32_t tag) {
pa_tagstruct *t = pa_tagstruct_new(NULL, 0); pa_tagstruct *t;
assert(t);
pa_assert_se(t = pa_tagstruct_new(NULL, 0));
pa_tagstruct_putu32(t, PA_COMMAND_REPLY); pa_tagstruct_putu32(t, PA_COMMAND_REPLY);
pa_tagstruct_putu32(t, tag); pa_tagstruct_putu32(t, tag);
pa_pstream_send_tagstruct(p, t); pa_pstream_send_tagstruct(p, t);

View file

@ -72,6 +72,9 @@ void pa_queue_free(pa_queue* q, void (*destroy)(void *p, void *userdata), void *
void pa_queue_push(pa_queue *q, void *p) { void pa_queue_push(pa_queue *q, void *p) {
struct queue_entry *e; struct queue_entry *e;
pa_assert(q);
pa_assert(p);
if (!(e = pa_flist_pop(PA_STATIC_FLIST_GET(entries)))) if (!(e = pa_flist_pop(PA_STATIC_FLIST_GET(entries))))
e = pa_xnew(struct queue_entry, 1); e = pa_xnew(struct queue_entry, 1);

View file

@ -31,21 +31,22 @@
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h>
#include <time.h> #include <time.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include "random.h" #include "random.h"
static int has_whined = 0; static int has_whined = 0;
static const char *devices[] = { "/dev/urandom", "/dev/random", NULL }; static const char * const devices[] = { "/dev/urandom", "/dev/random", NULL };
static int random_proper(void *ret_data, size_t length) { static int random_proper(void *ret_data, size_t length) {
#ifdef OS_IS_WIN32 #ifdef OS_IS_WIN32
assert(ret_data && length); pa_assert(ret_data);
pa_assert(length > 0);
return -1; return -1;
@ -53,9 +54,10 @@ static int random_proper(void *ret_data, size_t length) {
int fd, ret = -1; int fd, ret = -1;
ssize_t r = 0; ssize_t r = 0;
const char **device; const char *const * device;
assert(ret_data && length); pa_assert(ret_data);
pa_assert(length > 0);
device = devices; device = devices;
@ -84,7 +86,7 @@ void pa_random_seed(void) {
if (random_proper(&seed, sizeof(unsigned int)) < 0) { if (random_proper(&seed, sizeof(unsigned int)) < 0) {
if (!has_whined) if (!has_whined)
pa_log_warn("failed to get proper entropy. Falling back to seeding with current time."); pa_log_warn("Failed to get proper entropy. Falling back to seeding with current time.");
has_whined = 1; has_whined = 1;
seed = (unsigned int) time(NULL); seed = (unsigned int) time(NULL);
@ -97,13 +99,14 @@ void pa_random(void *ret_data, size_t length) {
uint8_t *p; uint8_t *p;
size_t l; size_t l;
assert(ret_data && length); pa_assert(ret_data);
pa_assert(length > 0);
if (random_proper(ret_data, length) >= 0) if (random_proper(ret_data, length) >= 0)
return; return;
if (!has_whined) if (!has_whined)
pa_log_warn("failed to get proper entropy. Falling back to unsecure pseudo RNG."); pa_log_warn("Failed to get proper entropy. Falling back to unsecure pseudo RNG.");
has_whined = 1; has_whined = 1;
for (p = ret_data, l = length; l > 0; p++, l--) for (p = ret_data, l = length; l > 0; p++, l--)

View file

@ -26,7 +26,6 @@
#include <config.h> #include <config.h>
#endif #endif
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
@ -63,10 +62,10 @@ int pa_shm_create_rw(pa_shm *m, size_t size, int shared, mode_t mode) {
char fn[32]; char fn[32];
int fd = -1; int fd = -1;
assert(m); pa_assert(m);
assert(size > 0); pa_assert(size > 0);
assert(size < MAX_SHM_SIZE); pa_assert(size < MAX_SHM_SIZE);
assert(mode >= 0600); pa_assert(mode >= 0600);
if (!shared) { if (!shared) {
m->id = 0; m->id = 0;
@ -128,7 +127,7 @@ fail:
#ifdef HAVE_SHM_OPEN #ifdef HAVE_SHM_OPEN
if (fd >= 0) { if (fd >= 0) {
shm_unlink(fn); shm_unlink(fn);
close(fd); pa_assert_se(close(fd) >= 0);
} }
#endif #endif
@ -136,12 +135,12 @@ fail:
} }
void pa_shm_free(pa_shm *m) { void pa_shm_free(pa_shm *m) {
assert(m); pa_assert(m);
assert(m->ptr); pa_assert(m->ptr);
assert(m->size > 0); pa_assert(m->size > 0);
#ifdef MAP_FAILED #ifdef MAP_FAILED
assert(m->ptr != MAP_FAILED); pa_assert(m->ptr != MAP_FAILED);
#endif #endif
if (!m->shared) { if (!m->shared) {
@ -179,13 +178,13 @@ void pa_shm_punch(pa_shm *m, size_t offset, size_t size) {
void *ptr; void *ptr;
size_t o, ps; size_t o, ps;
assert(m); pa_assert(m);
assert(m->ptr); pa_assert(m->ptr);
assert(m->size > 0); pa_assert(m->size > 0);
assert(offset+size <= m->size); pa_assert(offset+size <= m->size);
#ifdef MAP_FAILED #ifdef MAP_FAILED
assert(m->ptr != MAP_FAILED); pa_assert(m->ptr != MAP_FAILED);
#endif #endif
/* You're welcome to implement this as NOOP on systems that don't /* You're welcome to implement this as NOOP on systems that don't
@ -225,7 +224,7 @@ int pa_shm_attach_ro(pa_shm *m, unsigned id) {
int fd = -1; int fd = -1;
struct stat st; struct stat st;
assert(m); pa_assert(m);
segment_name(fn, sizeof(fn), m->id = id); segment_name(fn, sizeof(fn), m->id = id);
@ -254,13 +253,13 @@ int pa_shm_attach_ro(pa_shm *m, unsigned id) {
m->do_unlink = 0; m->do_unlink = 0;
m->shared = 1; m->shared = 1;
close(fd); pa_assert_se(close(fd) >= 0);
return 0; return 0;
fail: fail:
if (fd >= 0) if (fd >= 0)
close(fd); pa_assert_se(close(fd) >= 0);
return -1; return -1;
} }

View file

@ -27,7 +27,6 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <assert.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -64,7 +63,6 @@ pa_sink* pa_sink_new(
pa_sink *s; pa_sink *s;
char *n = NULL; char *n = NULL;
char st[256]; char st[256];
int r;
pa_channel_map tmap; pa_channel_map tmap;
pa_assert(core); pa_assert(core);
@ -120,8 +118,7 @@ pa_sink* pa_sink_new(
s->rtpoll = NULL; s->rtpoll = NULL;
s->silence = NULL; s->silence = NULL;
r = pa_idxset_put(core->sinks, s, &s->index); pa_assert_se(pa_idxset_put(core->sinks, s, &s->index) >= 0);
pa_assert(s->index != PA_IDXSET_INVALID && r >= 0);
pa_sample_spec_snprint(st, sizeof(st), spec); pa_sample_spec_snprint(st, sizeof(st), spec);
pa_log_info("Created sink %u \"%s\" with sample spec \"%s\"", s->index, s->name, st); pa_log_info("Created sink %u \"%s\" with sample spec \"%s\"", s->index, s->name, st);

View file

@ -25,21 +25,17 @@
#include <config.h> #include <config.h>
#endif #endif
#include <assert.h> #include <pulsecore/macro.h>
#include <pulsecore/atomic.h>
#include "sioman.h" #include "sioman.h"
static int stdio_inuse = 0; static pa_atomic_t stdio_inuse = PA_ATOMIC_INIT(0);
int pa_stdio_acquire(void) { int pa_stdio_acquire(void) {
if (stdio_inuse) return pa_atomic_cmpxchg(&stdio_inuse, 0, 1) ? 0 : -1;
return -1;
stdio_inuse = 1;
return 0;
} }
void pa_stdio_release(void) { void pa_stdio_release(void) {
assert(stdio_inuse); pa_assert_se(pa_atomic_cmpxchg(&stdio_inuse, 1, 0));
stdio_inuse = 0;
} }

View file

@ -32,7 +32,6 @@
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef HAVE_SYS_SOCKET_H #ifdef HAVE_SYS_SOCKET_H
@ -55,23 +54,24 @@
#include <asyncns.h> #include <asyncns.h>
#endif #endif
#include "winsock.h"
#include <pulse/timeval.h> #include <pulse/timeval.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulsecore/winsock.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/socket-util.h> #include <pulsecore/socket-util.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/parseaddr.h> #include <pulsecore/parseaddr.h>
#include <pulsecore/macro.h>
#include <pulsecore/refcnt.h>
#include "socket-client.h" #include "socket-client.h"
#define CONNECT_TIMEOUT 5 #define CONNECT_TIMEOUT 5
struct pa_socket_client { struct pa_socket_client {
int ref; PA_REFCNT_DECLARE;
pa_mainloop_api *mainloop; pa_mainloop_api *mainloop;
int fd; int fd;
pa_io_event *io_event; pa_io_event *io_event;
@ -89,10 +89,10 @@ struct pa_socket_client {
static pa_socket_client*pa_socket_client_new(pa_mainloop_api *m) { static pa_socket_client*pa_socket_client_new(pa_mainloop_api *m) {
pa_socket_client *c; pa_socket_client *c;
assert(m); pa_assert(m);
c = pa_xmalloc(sizeof(pa_socket_client)); c = pa_xnew(pa_socket_client, 1);
c->ref = 1; PA_REFCNT_INIT(c);
c->mainloop = m; c->mainloop = m;
c->fd = -1; c->fd = -1;
c->io_event = NULL; c->io_event = NULL;
@ -112,7 +112,7 @@ static pa_socket_client*pa_socket_client_new(pa_mainloop_api *m) {
} }
static void free_events(pa_socket_client *c) { static void free_events(pa_socket_client *c) {
assert(c); pa_assert(c);
if (c->io_event) { if (c->io_event) {
c->mainloop->io_free(c->io_event); c->mainloop->io_free(c->io_event);
@ -134,7 +134,10 @@ static void do_call(pa_socket_client *c) {
pa_iochannel *io = NULL; pa_iochannel *io = NULL;
int error; int error;
socklen_t lerror; socklen_t lerror;
assert(c && c->callback);
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1);
pa_assert(c->callback);
pa_socket_client_ref(c); pa_socket_client_ref(c);
@ -159,7 +162,7 @@ static void do_call(pa_socket_client *c) {
} }
io = pa_iochannel_new(c->mainloop, c->fd, c->fd); io = pa_iochannel_new(c->mainloop, c->fd, c->fd);
assert(io); pa_assert(io);
finish: finish:
if (!io && c->fd >= 0) if (!io && c->fd >= 0)
@ -168,7 +171,7 @@ finish:
free_events(c); free_events(c);
assert(c->callback); pa_assert(c->callback);
c->callback(c, io, c->userdata); c->callback(c, io, c->userdata);
pa_socket_client_unref(c); pa_socket_client_unref(c);
@ -176,19 +179,34 @@ finish:
static void connect_fixed_cb(pa_mainloop_api *m, pa_defer_event *e, void *userdata) { static void connect_fixed_cb(pa_mainloop_api *m, pa_defer_event *e, void *userdata) {
pa_socket_client *c = userdata; pa_socket_client *c = userdata;
assert(m && c && c->defer_event == e);
pa_assert(m);
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1);
pa_assert(c->defer_event == e);
do_call(c); do_call(c);
} }
static void connect_io_cb(pa_mainloop_api*m, pa_io_event *e, int fd, PA_GCC_UNUSED pa_io_event_flags_t f, void *userdata) { static void connect_io_cb(pa_mainloop_api*m, pa_io_event *e, int fd, PA_GCC_UNUSED pa_io_event_flags_t f, void *userdata) {
pa_socket_client *c = userdata; pa_socket_client *c = userdata;
assert(m && c && c->io_event == e && fd >= 0);
pa_assert(m);
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1);
pa_assert(c->io_event == e);
pa_assert(fd >= 0);
do_call(c); do_call(c);
} }
static int do_connect(pa_socket_client *c, const struct sockaddr *sa, socklen_t len) { static int do_connect(pa_socket_client *c, const struct sockaddr *sa, socklen_t len) {
int r; int r;
assert(c && sa && len);
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1);
pa_assert(sa);
pa_assert(len > 0);
pa_make_nonblock_fd(c->fd); pa_make_nonblock_fd(c->fd);
@ -203,19 +221,18 @@ static int do_connect(pa_socket_client *c, const struct sockaddr *sa, socklen_t
return -1; return -1;
} }
c->io_event = c->mainloop->io_new(c->mainloop, c->fd, PA_IO_EVENT_OUTPUT, connect_io_cb, c); pa_assert_se(c->io_event = c->mainloop->io_new(c->mainloop, c->fd, PA_IO_EVENT_OUTPUT, connect_io_cb, c));
assert(c->io_event); } else
} else { pa_assert_se(c->defer_event = c->mainloop->defer_new(c->mainloop, connect_fixed_cb, c));
c->defer_event = c->mainloop->defer_new(c->mainloop, connect_fixed_cb, c);
assert(c->defer_event);
}
return 0; return 0;
} }
pa_socket_client* pa_socket_client_new_ipv4(pa_mainloop_api *m, uint32_t address, uint16_t port) { pa_socket_client* pa_socket_client_new_ipv4(pa_mainloop_api *m, uint32_t address, uint16_t port) {
struct sockaddr_in sa; struct sockaddr_in sa;
assert(m && port > 0);
pa_assert(m);
pa_assert(port > 0);
memset(&sa, 0, sizeof(sa)); memset(&sa, 0, sizeof(sa));
sa.sin_family = AF_INET; sa.sin_family = AF_INET;
@ -229,7 +246,9 @@ pa_socket_client* pa_socket_client_new_ipv4(pa_mainloop_api *m, uint32_t address
pa_socket_client* pa_socket_client_new_unix(pa_mainloop_api *m, const char *filename) { pa_socket_client* pa_socket_client_new_unix(pa_mainloop_api *m, const char *filename) {
struct sockaddr_un sa; struct sockaddr_un sa;
assert(m && filename);
pa_assert(m);
pa_assert(filename);
memset(&sa, 0, sizeof(sa)); memset(&sa, 0, sizeof(sa));
sa.sun_family = AF_UNIX; sa.sun_family = AF_UNIX;
@ -248,9 +267,9 @@ pa_socket_client* pa_socket_client_new_unix(pa_mainloop_api *m, const char *file
#endif /* HAVE_SYS_UN_H */ #endif /* HAVE_SYS_UN_H */
static int sockaddr_prepare(pa_socket_client *c, const struct sockaddr *sa, size_t salen) { static int sockaddr_prepare(pa_socket_client *c, const struct sockaddr *sa, size_t salen) {
assert(c); pa_assert(c);
assert(sa); pa_assert(sa);
assert(salen); pa_assert(salen);
switch (sa->sa_family) { switch (sa->sa_family) {
case AF_UNIX: case AF_UNIX:
@ -288,9 +307,12 @@ static int sockaddr_prepare(pa_socket_client *c, const struct sockaddr *sa, size
pa_socket_client* pa_socket_client_new_sockaddr(pa_mainloop_api *m, const struct sockaddr *sa, size_t salen) { pa_socket_client* pa_socket_client_new_sockaddr(pa_mainloop_api *m, const struct sockaddr *sa, size_t salen) {
pa_socket_client *c; pa_socket_client *c;
assert(m && sa);
c = pa_socket_client_new(m); pa_assert(m);
assert(c); pa_assert(sa);
pa_assert(salen > 0);
pa_assert_se(c = pa_socket_client_new(m));
if (sockaddr_prepare(c, sa, salen) < 0) if (sockaddr_prepare(c, sa, salen) < 0)
goto fail; goto fail;
@ -300,12 +322,11 @@ pa_socket_client* pa_socket_client_new_sockaddr(pa_mainloop_api *m, const struct
fail: fail:
pa_socket_client_unref(c); pa_socket_client_unref(c);
return NULL; return NULL;
} }
static void socket_client_free(pa_socket_client *c) { static void socket_client_free(pa_socket_client *c) {
assert(c && c->mainloop); pa_assert(c);
pa_assert(c->mainloop);
free_events(c); free_events(c);
@ -325,20 +346,25 @@ static void socket_client_free(pa_socket_client *c) {
} }
void pa_socket_client_unref(pa_socket_client *c) { void pa_socket_client_unref(pa_socket_client *c) {
assert(c && c->ref >= 1); pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1);
if (!(--(c->ref))) if (PA_REFCNT_DEC(c) < 0)
socket_client_free(c); socket_client_free(c);
} }
pa_socket_client* pa_socket_client_ref(pa_socket_client *c) { pa_socket_client* pa_socket_client_ref(pa_socket_client *c) {
assert(c && c->ref >= 1); pa_assert(c);
c->ref++; pa_assert(PA_REFCNT_VALUE(c) >= 1);
PA_REFCNT_INC(c);
return c; return c;
} }
void pa_socket_client_set_callback(pa_socket_client *c, void (*on_connection)(pa_socket_client *c, pa_iochannel*io, void *userdata), void *userdata) { void pa_socket_client_set_callback(pa_socket_client *c, void (*on_connection)(pa_socket_client *c, pa_iochannel*io, void *userdata), void *userdata) {
assert(c); pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1);
c->callback = on_connection; c->callback = on_connection;
c->userdata = userdata; c->userdata = userdata;
} }
@ -346,6 +372,10 @@ void pa_socket_client_set_callback(pa_socket_client *c, void (*on_connection)(pa
pa_socket_client* pa_socket_client_new_ipv6(pa_mainloop_api *m, uint8_t address[16], uint16_t port) { pa_socket_client* pa_socket_client_new_ipv6(pa_mainloop_api *m, uint8_t address[16], uint16_t port) {
struct sockaddr_in6 sa; struct sockaddr_in6 sa;
pa_assert(m);
pa_assert(address);
pa_assert(port > 0);
memset(&sa, 0, sizeof(sa)); memset(&sa, 0, sizeof(sa));
sa.sin6_family = AF_INET6; sa.sin6_family = AF_INET6;
sa.sin6_port = htons(port); sa.sin6_port = htons(port);
@ -360,7 +390,12 @@ static void asyncns_cb(pa_mainloop_api*m, pa_io_event *e, int fd, PA_GCC_UNUSED
pa_socket_client *c = userdata; pa_socket_client *c = userdata;
struct addrinfo *res = NULL; struct addrinfo *res = NULL;
int ret; int ret;
assert(m && c && c->asyncns_io_event == e && fd >= 0);
pa_assert(m);
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1);
pa_assert(c->asyncns_io_event == e);
pa_assert(fd >= 0);
if (asyncns_wait(c->asyncns, 0) < 0) if (asyncns_wait(c->asyncns, 0) < 0)
goto fail; goto fail;
@ -397,10 +432,11 @@ fail:
static void timeout_cb(pa_mainloop_api *m, pa_time_event *e, const struct timeval *tv, void *userdata) { static void timeout_cb(pa_mainloop_api *m, pa_time_event *e, const struct timeval *tv, void *userdata) {
pa_socket_client *c = userdata; pa_socket_client *c = userdata;
assert(m);
assert(e); pa_assert(m);
assert(tv); pa_assert(e);
assert(c); pa_assert(tv);
pa_assert(c);
if (c->fd >= 0) { if (c->fd >= 0) {
pa_close(c->fd); pa_close(c->fd);
@ -413,8 +449,8 @@ static void timeout_cb(pa_mainloop_api *m, pa_time_event *e, const struct timeva
static void start_timeout(pa_socket_client *c) { static void start_timeout(pa_socket_client *c) {
struct timeval tv; struct timeval tv;
assert(c); pa_assert(c);
assert(!c->timeout_event); pa_assert(!c->timeout_event);
pa_gettimeofday(&tv); pa_gettimeofday(&tv);
pa_timeval_add(&tv, CONNECT_TIMEOUT * 1000000); pa_timeval_add(&tv, CONNECT_TIMEOUT * 1000000);
@ -424,7 +460,9 @@ static void start_timeout(pa_socket_client *c) {
pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, const char*name, uint16_t default_port) { pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, const char*name, uint16_t default_port) {
pa_socket_client *c = NULL; pa_socket_client *c = NULL;
pa_parsed_address a; pa_parsed_address a;
assert(m && name);
pa_assert(m);
pa_assert(name);
if (pa_parse_address(name, &a) < 0) if (pa_parse_address(name, &a) < 0)
return NULL; return NULL;
@ -462,7 +500,7 @@ pa_socket_client* pa_socket_client_new_string(pa_mainloop_api *m, const char*nam
c->asyncns = asyncns; c->asyncns = asyncns;
c->asyncns_io_event = m->io_new(m, asyncns_fd(c->asyncns), PA_IO_EVENT_INPUT, asyncns_cb, c); c->asyncns_io_event = m->io_new(m, asyncns_fd(c->asyncns), PA_IO_EVENT_INPUT, asyncns_cb, c);
c->asyncns_query = asyncns_getaddrinfo(c->asyncns, a.path_or_host, port, &hints); c->asyncns_query = asyncns_getaddrinfo(c->asyncns, a.path_or_host, port, &hints);
assert(c->asyncns_query); pa_assert(c->asyncns_query);
start_timeout(c); start_timeout(c);
} }
#else /* HAVE_LIBASYNCNS */ #else /* HAVE_LIBASYNCNS */
@ -524,6 +562,8 @@ finish:
local. "local" means UNIX socket or TCP socket on localhost. Other local. "local" means UNIX socket or TCP socket on localhost. Other
local IP addresses are not considered local. */ local IP addresses are not considered local. */
int pa_socket_client_is_local(pa_socket_client *c) { int pa_socket_client_is_local(pa_socket_client *c) {
assert(c); pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1);
return c->local; return c->local;
} }

View file

@ -27,7 +27,6 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <assert.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
@ -72,12 +71,14 @@
#include <pulsecore/socket-util.h> #include <pulsecore/socket-util.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/refcnt.h>
#include "socket-server.h" #include "socket-server.h"
struct pa_socket_server { struct pa_socket_server {
int ref; PA_REFCNT_DECLARE;
int fd; int fd;
char *filename; char *filename;
char *tcpwrap_service; char *tcpwrap_service;
@ -94,7 +95,14 @@ static void callback(pa_mainloop_api *mainloop, pa_io_event *e, int fd, PA_GCC_U
pa_socket_server *s = userdata; pa_socket_server *s = userdata;
pa_iochannel *io; pa_iochannel *io;
int nfd; int nfd;
assert(s && s->mainloop == mainloop && s->io_event == e && e && fd >= 0 && fd == s->fd);
pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
pa_assert(s->mainloop == mainloop);
pa_assert(s->io_event == e);
pa_assert(e);
pa_assert(fd >= 0);
pa_assert(fd == s->fd);
pa_socket_server_ref(s); pa_socket_server_ref(s);
@ -133,8 +141,7 @@ static void callback(pa_mainloop_api *mainloop, pa_io_event *e, int fd, PA_GCC_U
else else
pa_socket_low_delay(fd); pa_socket_low_delay(fd);
io = pa_iochannel_new(s->mainloop, nfd, nfd); pa_assert_se(io = pa_iochannel_new(s->mainloop, nfd, nfd));
assert(io);
s->on_connection(s, io, s->userdata); s->on_connection(s, io, s->userdata);
finish: finish:
@ -143,10 +150,12 @@ finish:
pa_socket_server* pa_socket_server_new(pa_mainloop_api *m, int fd) { pa_socket_server* pa_socket_server_new(pa_mainloop_api *m, int fd) {
pa_socket_server *s; pa_socket_server *s;
assert(m && fd >= 0);
s = pa_xmalloc(sizeof(pa_socket_server)); pa_assert(m);
s->ref = 1; pa_assert(fd >= 0);
s = pa_xnew(pa_socket_server, 1);
PA_REFCNT_INIT(s);
s->fd = fd; s->fd = fd;
s->filename = NULL; s->filename = NULL;
s->on_connection = NULL; s->on_connection = NULL;
@ -154,8 +163,7 @@ pa_socket_server* pa_socket_server_new(pa_mainloop_api *m, int fd) {
s->tcpwrap_service = NULL; s->tcpwrap_service = NULL;
s->mainloop = m; s->mainloop = m;
s->io_event = m->io_new(m, fd, PA_IO_EVENT_INPUT, callback, s); pa_assert_se(s->io_event = m->io_new(m, fd, PA_IO_EVENT_INPUT, callback, s));
assert(s->io_event);
s->type = SOCKET_SERVER_GENERIC; s->type = SOCKET_SERVER_GENERIC;
@ -163,8 +171,10 @@ pa_socket_server* pa_socket_server_new(pa_mainloop_api *m, int fd) {
} }
pa_socket_server* pa_socket_server_ref(pa_socket_server *s) { pa_socket_server* pa_socket_server_ref(pa_socket_server *s) {
assert(s && s->ref >= 1); pa_assert(s);
s->ref++; pa_assert(PA_REFCNT_VALUE(s) >= 1);
PA_REFCNT_INC(s);
return s; return s;
} }
@ -175,7 +185,8 @@ pa_socket_server* pa_socket_server_new_unix(pa_mainloop_api *m, const char *file
struct sockaddr_un sa; struct sockaddr_un sa;
pa_socket_server *s; pa_socket_server *s;
assert(m && filename); pa_assert(m);
pa_assert(filename);
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) { if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
pa_log("socket(): %s", pa_cstrerror(errno)); pa_log("socket(): %s", pa_cstrerror(errno));
@ -206,8 +217,7 @@ pa_socket_server* pa_socket_server_new_unix(pa_mainloop_api *m, const char *file
goto fail; goto fail;
} }
s = pa_socket_server_new(m, fd); pa_assert_se(s = pa_socket_server_new(m, fd));
assert(s);
s->filename = pa_xstrdup(filename); s->filename = pa_xstrdup(filename);
s->type = SOCKET_SERVER_UNIX; s->type = SOCKET_SERVER_UNIX;
@ -235,7 +245,8 @@ pa_socket_server* pa_socket_server_new_ipv4(pa_mainloop_api *m, uint32_t address
struct sockaddr_in sa; struct sockaddr_in sa;
int on = 1; int on = 1;
assert(m && port); pa_assert(m);
pa_assert(port);
if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) { if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
pa_log("socket(PF_INET): %s", pa_cstrerror(errno)); pa_log("socket(PF_INET): %s", pa_cstrerror(errno));
@ -286,7 +297,8 @@ pa_socket_server* pa_socket_server_new_ipv6(pa_mainloop_api *m, const uint8_t ad
struct sockaddr_in6 sa; struct sockaddr_in6 sa;
int on = 1; int on = 1;
assert(m && port); pa_assert(m);
pa_assert(port > 0);
if ((fd = socket(PF_INET6, SOCK_STREAM, 0)) < 0) { if ((fd = socket(PF_INET6, SOCK_STREAM, 0)) < 0) {
pa_log("socket(PF_INET6): %s", pa_cstrerror(errno)); pa_log("socket(PF_INET6): %s", pa_cstrerror(errno));
@ -337,29 +349,29 @@ fail:
} }
pa_socket_server* pa_socket_server_new_ipv4_loopback(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service) { pa_socket_server* pa_socket_server_new_ipv4_loopback(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service) {
assert(m); pa_assert(m);
assert(port > 0); pa_assert(port > 0);
return pa_socket_server_new_ipv4(m, INADDR_LOOPBACK, port, tcpwrap_service); return pa_socket_server_new_ipv4(m, INADDR_LOOPBACK, port, tcpwrap_service);
} }
pa_socket_server* pa_socket_server_new_ipv6_loopback(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service) { pa_socket_server* pa_socket_server_new_ipv6_loopback(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service) {
assert(m); pa_assert(m);
assert(port > 0); pa_assert(port > 0);
return pa_socket_server_new_ipv6(m, in6addr_loopback.s6_addr, port, tcpwrap_service); return pa_socket_server_new_ipv6(m, in6addr_loopback.s6_addr, port, tcpwrap_service);
} }
pa_socket_server* pa_socket_server_new_ipv4_any(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service) { pa_socket_server* pa_socket_server_new_ipv4_any(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service) {
assert(m); pa_assert(m);
assert(port > 0); pa_assert(port > 0);
return pa_socket_server_new_ipv4(m, INADDR_ANY, port, tcpwrap_service); return pa_socket_server_new_ipv4(m, INADDR_ANY, port, tcpwrap_service);
} }
pa_socket_server* pa_socket_server_new_ipv6_any(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service) { pa_socket_server* pa_socket_server_new_ipv6_any(pa_mainloop_api *m, uint16_t port, const char *tcpwrap_service) {
assert(m); pa_assert(m);
assert(port > 0); pa_assert(port > 0);
return pa_socket_server_new_ipv6(m, in6addr_any.s6_addr, port, tcpwrap_service); return pa_socket_server_new_ipv6(m, in6addr_any.s6_addr, port, tcpwrap_service);
} }
@ -367,9 +379,9 @@ pa_socket_server* pa_socket_server_new_ipv6_any(pa_mainloop_api *m, uint16_t por
pa_socket_server* pa_socket_server_new_ipv4_string(pa_mainloop_api *m, const char *name, uint16_t port, const char *tcpwrap_service) { pa_socket_server* pa_socket_server_new_ipv4_string(pa_mainloop_api *m, const char *name, uint16_t port, const char *tcpwrap_service) {
struct in_addr ipv4; struct in_addr ipv4;
assert(m); pa_assert(m);
assert(name); pa_assert(name);
assert(port > 0); pa_assert(port > 0);
if (inet_pton(AF_INET, name, &ipv4) > 0) if (inet_pton(AF_INET, name, &ipv4) > 0)
return pa_socket_server_new_ipv4(m, ntohl(ipv4.s_addr), port, tcpwrap_service); return pa_socket_server_new_ipv4(m, ntohl(ipv4.s_addr), port, tcpwrap_service);
@ -380,9 +392,9 @@ pa_socket_server* pa_socket_server_new_ipv4_string(pa_mainloop_api *m, const cha
pa_socket_server* pa_socket_server_new_ipv6_string(pa_mainloop_api *m, const char *name, uint16_t port, const char *tcpwrap_service) { pa_socket_server* pa_socket_server_new_ipv6_string(pa_mainloop_api *m, const char *name, uint16_t port, const char *tcpwrap_service) {
struct in6_addr ipv6; struct in6_addr ipv6;
assert(m); pa_assert(m);
assert(name); pa_assert(name);
assert(port > 0); pa_assert(port > 0);
if (inet_pton(AF_INET6, name, &ipv6) > 0) if (inet_pton(AF_INET6, name, &ipv6) > 0)
return pa_socket_server_new_ipv6(m, ipv6.s6_addr, port, tcpwrap_service); return pa_socket_server_new_ipv6(m, ipv6.s6_addr, port, tcpwrap_service);
@ -391,7 +403,7 @@ pa_socket_server* pa_socket_server_new_ipv6_string(pa_mainloop_api *m, const cha
} }
static void socket_server_free(pa_socket_server*s) { static void socket_server_free(pa_socket_server*s) {
assert(s); pa_assert(s);
if (s->filename) { if (s->filename) {
unlink(s->filename); unlink(s->filename);
@ -407,21 +419,26 @@ static void socket_server_free(pa_socket_server*s) {
} }
void pa_socket_server_unref(pa_socket_server *s) { void pa_socket_server_unref(pa_socket_server *s) {
assert(s && s->ref >= 1); pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
if (!(--(s->ref))) if (PA_REFCNT_DEC(s))
socket_server_free(s); socket_server_free(s);
} }
void pa_socket_server_set_callback(pa_socket_server*s, void (*on_connection)(pa_socket_server*s, pa_iochannel *io, void *userdata), void *userdata) { void pa_socket_server_set_callback(pa_socket_server*s, void (*on_connection)(pa_socket_server*s, pa_iochannel *io, void *userdata), void *userdata) {
assert(s && s->ref >= 1); pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
s->on_connection = on_connection; s->on_connection = on_connection;
s->userdata = userdata; s->userdata = userdata;
} }
char *pa_socket_server_get_address(pa_socket_server *s, char *c, size_t l) { char *pa_socket_server_get_address(pa_socket_server *s, char *c, size_t l) {
assert(s && c && l > 0); pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
pa_assert(c);
pa_assert(l > 0);
switch (s->type) { switch (s->type) {
case SOCKET_SERVER_IPV6: { case SOCKET_SERVER_IPV6: {

View file

@ -31,7 +31,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <signal.h> #include <signal.h>
#include <errno.h> #include <errno.h>
#include <assert.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
@ -75,19 +74,19 @@
#include <pulsecore/core-error.h> #include <pulsecore/core-error.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include "socket-util.h" #include "socket-util.h"
void pa_socket_peer_to_string(int fd, char *c, size_t l) { void pa_socket_peer_to_string(int fd, char *c, size_t l) {
struct stat st; struct stat st;
assert(c && l && fd >= 0); pa_assert(fd >= 0);
pa_assert(c);
pa_assert(l > 0);
#ifndef OS_IS_WIN32 #ifndef OS_IS_WIN32
if (fstat(fd, &st) < 0) { pa_assert_se(fstat(fd, &st) == 0);
pa_snprintf(c, l, "Invalid client fd");
return;
}
#endif #endif
#ifndef OS_IS_WIN32 #ifndef OS_IS_WIN32
@ -147,7 +146,7 @@ void pa_socket_peer_to_string(int fd, char *c, size_t l) {
int pa_socket_low_delay(int fd) { int pa_socket_low_delay(int fd) {
#ifdef SO_PRIORITY #ifdef SO_PRIORITY
int priority; int priority;
assert(fd >= 0); pa_assert(fd >= 0);
priority = 7; priority = 7;
if (setsockopt(fd, SOL_SOCKET, SO_PRIORITY, (void*)&priority, sizeof(priority)) < 0) if (setsockopt(fd, SOL_SOCKET, SO_PRIORITY, (void*)&priority, sizeof(priority)) < 0)
@ -160,7 +159,7 @@ int pa_socket_low_delay(int fd) {
int pa_socket_tcp_low_delay(int fd) { int pa_socket_tcp_low_delay(int fd) {
int ret, tos, on; int ret, tos, on;
assert(fd >= 0); pa_assert(fd >= 0);
ret = pa_socket_low_delay(fd); ret = pa_socket_low_delay(fd);
@ -176,8 +175,7 @@ int pa_socket_tcp_low_delay(int fd) {
ret = -1; ret = -1;
#endif #endif
#if defined(IPTOS_LOWDELAY) && defined(IP_TOS) && (defined(SOL_IP) || \ #if defined(IPTOS_LOWDELAY) && defined(IP_TOS) && (defined(SOL_IP) || defined(IPPROTO_IP))
defined(IPPROTO_IP))
tos = IPTOS_LOWDELAY; tos = IPTOS_LOWDELAY;
#ifdef SOL_IP #ifdef SOL_IP
if (setsockopt(fd, SOL_IP, IP_TOS, (void*)&tos, sizeof(tos)) < 0) if (setsockopt(fd, SOL_IP, IP_TOS, (void*)&tos, sizeof(tos)) < 0)
@ -188,27 +186,26 @@ int pa_socket_tcp_low_delay(int fd) {
#endif #endif
return ret; return ret;
} }
int pa_socket_set_rcvbuf(int fd, size_t l) { int pa_socket_set_rcvbuf(int fd, size_t l) {
assert(fd >= 0); pa_assert(fd >= 0);
/* if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (void*)&l, sizeof(l)) < 0) { */ if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (void*)&l, sizeof(l)) < 0) {
/* pa_log("SO_RCVBUF: %s", strerror(errno)); */ pa_log_warn("SO_RCVBUF: %s", pa_cstrerror(errno));
/* return -1; */ return -1;
/* } */ }
return 0; return 0;
} }
int pa_socket_set_sndbuf(int fd, size_t l) { int pa_socket_set_sndbuf(int fd, size_t l) {
assert(fd >= 0); pa_assert(fd >= 0);
/* if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (void*)&l, sizeof(l)) < 0) { */ if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (void*)&l, sizeof(l)) < 0) {
/* pa_log("SO_SNDBUF: %s", strerror(errno)); */ pa_log("SO_SNDBUF: %s", pa_cstrerror(errno));
/* return -1; */ return -1;
/* } */ }
return 0; return 0;
} }
@ -219,6 +216,8 @@ int pa_unix_socket_is_stale(const char *fn) {
struct sockaddr_un sa; struct sockaddr_un sa;
int fd = -1, ret = -1; int fd = -1, ret = -1;
pa_assert(fn);
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) { if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
pa_log("socket(): %s", pa_cstrerror(errno)); pa_log("socket(): %s", pa_cstrerror(errno));
goto finish; goto finish;
@ -244,6 +243,8 @@ finish:
int pa_unix_socket_remove_stale(const char *fn) { int pa_unix_socket_remove_stale(const char *fn) {
int r; int r;
pa_assert(fn);
if ((r = pa_unix_socket_is_stale(fn)) < 0) if ((r = pa_unix_socket_is_stale(fn)) < 0)
return errno != ENOENT ? -1 : 0; return errno != ENOENT ? -1 : 0;

View file

@ -27,7 +27,6 @@
#endif #endif
#include <stdio.h> #include <stdio.h>
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -56,12 +55,11 @@ pa_source* pa_source_new(
pa_source *s; pa_source *s;
char st[256]; char st[256];
int r;
pa_channel_map tmap; pa_channel_map tmap;
assert(core); pa_assert(core);
assert(name); pa_assert(name);
assert(spec); pa_assert(spec);
pa_return_null_if_fail(pa_sample_spec_valid(spec)); pa_return_null_if_fail(pa_sample_spec_valid(spec));
@ -112,8 +110,7 @@ pa_source* pa_source_new(
s->asyncmsgq = NULL; s->asyncmsgq = NULL;
s->rtpoll = NULL; s->rtpoll = NULL;
r = pa_idxset_put(core->sources, s, &s->index); pa_assert_se(pa_idxset_put(core->sources, s, &s->index) >= 0);
assert(s->index != PA_IDXSET_INVALID && r >= 0);
pa_sample_spec_snprint(st, sizeof(st), spec); pa_sample_spec_snprint(st, sizeof(st), spec);
pa_log_info("Created source %u \"%s\" with sample spec \"%s\"", s->index, s->name, st); pa_log_info("Created source %u \"%s\" with sample spec \"%s\"", s->index, s->name, st);

View file

@ -82,7 +82,7 @@ char *pa_strbuf_tostring(pa_strbuf *sb) {
e = t = pa_xnew(char, sb->length+1); e = t = pa_xnew(char, sb->length+1);
for (c = sb->head; c; c = c->next) { for (c = sb->head; c; c = c->next) {
assert((size_t) (e-t) <= sb->length); pa_assert((size_t) (e-t) <= sb->length);
memcpy(e, CHUNK_TO_TEXT(c), c->length); memcpy(e, CHUNK_TO_TEXT(c), c->length);
e += c->length; e += c->length;
} }
@ -90,7 +90,7 @@ char *pa_strbuf_tostring(pa_strbuf *sb) {
/* Trailing NUL */ /* Trailing NUL */
*e = 0; *e = 0;
assert(e == t+sb->length); pa_assert(e == t+sb->length);
return t; return t;
} }

View file

@ -29,19 +29,18 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <sys/time.h> #include <sys/time.h>
#include <assert.h>
#include <stdarg.h> #include <stdarg.h>
#ifdef HAVE_NETINET_IN_H #ifdef HAVE_NETINET_IN_H
#include <netinet/in.h> #include <netinet/in.h>
#endif #endif
#include "winsock.h"
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include "tagstruct.h" #include <pulsecore/winsock.h>
#include <pulsecore/macro.h>
#include "tagstruct.h"
struct pa_tagstruct { struct pa_tagstruct {
uint8_t *data; uint8_t *data;
@ -54,18 +53,20 @@ struct pa_tagstruct {
pa_tagstruct *pa_tagstruct_new(const uint8_t* data, size_t length) { pa_tagstruct *pa_tagstruct_new(const uint8_t* data, size_t length) {
pa_tagstruct*t; pa_tagstruct*t;
assert(!data || (data && length)); pa_assert(!data || (data && length));
t = pa_xmalloc(sizeof(pa_tagstruct)); t = pa_xnew(pa_tagstruct, 1);
t->data = (uint8_t*) data; t->data = (uint8_t*) data;
t->allocated = t->length = data ? length : 0; t->allocated = t->length = data ? length : 0;
t->rindex = 0; t->rindex = 0;
t->dynamic = !data; t->dynamic = !data;
return t; return t;
} }
void pa_tagstruct_free(pa_tagstruct*t) { void pa_tagstruct_free(pa_tagstruct*t) {
assert(t); pa_assert(t);
if (t->dynamic) if (t->dynamic)
pa_xfree(t->data); pa_xfree(t->data);
pa_xfree(t); pa_xfree(t);
@ -73,7 +74,11 @@ void pa_tagstruct_free(pa_tagstruct*t) {
uint8_t* pa_tagstruct_free_data(pa_tagstruct*t, size_t *l) { uint8_t* pa_tagstruct_free_data(pa_tagstruct*t, size_t *l) {
uint8_t *p; uint8_t *p;
assert(t && t->dynamic && l);
pa_assert(t);
pa_assert(t->dynamic);
pa_assert(l);
p = t->data; p = t->data;
*l = t->length; *l = t->length;
pa_xfree(t); pa_xfree(t);
@ -81,8 +86,8 @@ uint8_t* pa_tagstruct_free_data(pa_tagstruct*t, size_t *l) {
} }
static void extend(pa_tagstruct*t, size_t l) { static void extend(pa_tagstruct*t, size_t l) {
assert(t); pa_assert(t);
assert(t->dynamic); pa_assert(t->dynamic);
if (t->length+l <= t->allocated) if (t->length+l <= t->allocated)
return; return;
@ -92,7 +97,8 @@ static void extend(pa_tagstruct*t, size_t l) {
void pa_tagstruct_puts(pa_tagstruct*t, const char *s) { void pa_tagstruct_puts(pa_tagstruct*t, const char *s) {
size_t l; size_t l;
assert(t); pa_assert(t);
if (s) { if (s) {
l = strlen(s)+2; l = strlen(s)+2;
extend(t, l); extend(t, l);
@ -107,7 +113,8 @@ void pa_tagstruct_puts(pa_tagstruct*t, const char *s) {
} }
void pa_tagstruct_putu32(pa_tagstruct*t, uint32_t i) { void pa_tagstruct_putu32(pa_tagstruct*t, uint32_t i) {
assert(t); pa_assert(t);
extend(t, 5); extend(t, 5);
t->data[t->length] = PA_TAG_U32; t->data[t->length] = PA_TAG_U32;
i = htonl(i); i = htonl(i);
@ -116,7 +123,8 @@ void pa_tagstruct_putu32(pa_tagstruct*t, uint32_t i) {
} }
void pa_tagstruct_putu8(pa_tagstruct*t, uint8_t c) { void pa_tagstruct_putu8(pa_tagstruct*t, uint8_t c) {
assert(t); pa_assert(t);
extend(t, 2); extend(t, 2);
t->data[t->length] = PA_TAG_U8; t->data[t->length] = PA_TAG_U8;
*(t->data+t->length+1) = c; *(t->data+t->length+1) = c;
@ -125,7 +133,10 @@ void pa_tagstruct_putu8(pa_tagstruct*t, uint8_t c) {
void pa_tagstruct_put_sample_spec(pa_tagstruct *t, const pa_sample_spec *ss) { void pa_tagstruct_put_sample_spec(pa_tagstruct *t, const pa_sample_spec *ss) {
uint32_t rate; uint32_t rate;
assert(t && ss);
pa_assert(t);
pa_assert(ss);
extend(t, 7); extend(t, 7);
t->data[t->length] = PA_TAG_SAMPLE_SPEC; t->data[t->length] = PA_TAG_SAMPLE_SPEC;
t->data[t->length+1] = (uint8_t) ss->format; t->data[t->length+1] = (uint8_t) ss->format;
@ -137,7 +148,9 @@ void pa_tagstruct_put_sample_spec(pa_tagstruct *t, const pa_sample_spec *ss) {
void pa_tagstruct_put_arbitrary(pa_tagstruct *t, const void *p, size_t length) { void pa_tagstruct_put_arbitrary(pa_tagstruct *t, const void *p, size_t length) {
uint32_t tmp; uint32_t tmp;
assert(t && p);
pa_assert(t);
pa_assert(p);
extend(t, 5+length); extend(t, 5+length);
t->data[t->length] = PA_TAG_ARBITRARY; t->data[t->length] = PA_TAG_ARBITRARY;
@ -149,7 +162,8 @@ void pa_tagstruct_put_arbitrary(pa_tagstruct *t, const void *p, size_t length) {
} }
void pa_tagstruct_put_boolean(pa_tagstruct*t, int b) { void pa_tagstruct_put_boolean(pa_tagstruct*t, int b) {
assert(t); pa_assert(t);
extend(t, 1); extend(t, 1);
t->data[t->length] = b ? PA_TAG_BOOLEAN_TRUE : PA_TAG_BOOLEAN_FALSE; t->data[t->length] = b ? PA_TAG_BOOLEAN_TRUE : PA_TAG_BOOLEAN_FALSE;
t->length += 1; t->length += 1;
@ -157,7 +171,8 @@ void pa_tagstruct_put_boolean(pa_tagstruct*t, int b) {
void pa_tagstruct_put_timeval(pa_tagstruct*t, const struct timeval *tv) { void pa_tagstruct_put_timeval(pa_tagstruct*t, const struct timeval *tv) {
uint32_t tmp; uint32_t tmp;
assert(t); pa_assert(t);
extend(t, 9); extend(t, 9);
t->data[t->length] = PA_TAG_TIMEVAL; t->data[t->length] = PA_TAG_TIMEVAL;
tmp = htonl(tv->tv_sec); tmp = htonl(tv->tv_sec);
@ -169,7 +184,9 @@ void pa_tagstruct_put_timeval(pa_tagstruct*t, const struct timeval *tv) {
void pa_tagstruct_put_usec(pa_tagstruct*t, pa_usec_t u) { void pa_tagstruct_put_usec(pa_tagstruct*t, pa_usec_t u) {
uint32_t tmp; uint32_t tmp;
assert(t);
pa_assert(t);
extend(t, 9); extend(t, 9);
t->data[t->length] = PA_TAG_USEC; t->data[t->length] = PA_TAG_USEC;
tmp = htonl((uint32_t) (u >> 32)); tmp = htonl((uint32_t) (u >> 32));
@ -181,7 +198,9 @@ void pa_tagstruct_put_usec(pa_tagstruct*t, pa_usec_t u) {
void pa_tagstruct_putu64(pa_tagstruct*t, uint64_t u) { void pa_tagstruct_putu64(pa_tagstruct*t, uint64_t u) {
uint32_t tmp; uint32_t tmp;
assert(t);
pa_assert(t);
extend(t, 9); extend(t, 9);
t->data[t->length] = PA_TAG_U64; t->data[t->length] = PA_TAG_U64;
tmp = htonl((uint32_t) (u >> 32)); tmp = htonl((uint32_t) (u >> 32));
@ -193,7 +212,9 @@ void pa_tagstruct_putu64(pa_tagstruct*t, uint64_t u) {
void pa_tagstruct_puts64(pa_tagstruct*t, int64_t u) { void pa_tagstruct_puts64(pa_tagstruct*t, int64_t u) {
uint32_t tmp; uint32_t tmp;
assert(t);
pa_assert(t);
extend(t, 9); extend(t, 9);
t->data[t->length] = PA_TAG_S64; t->data[t->length] = PA_TAG_S64;
tmp = htonl((uint32_t) ((uint64_t) u >> 32)); tmp = htonl((uint32_t) ((uint64_t) u >> 32));
@ -206,7 +227,7 @@ void pa_tagstruct_puts64(pa_tagstruct*t, int64_t u) {
void pa_tagstruct_put_channel_map(pa_tagstruct *t, const pa_channel_map *map) { void pa_tagstruct_put_channel_map(pa_tagstruct *t, const pa_channel_map *map) {
unsigned i; unsigned i;
assert(t); pa_assert(t);
extend(t, 2 + map->channels); extend(t, 2 + map->channels);
t->data[t->length++] = PA_TAG_CHANNEL_MAP; t->data[t->length++] = PA_TAG_CHANNEL_MAP;
@ -220,7 +241,7 @@ void pa_tagstruct_put_cvolume(pa_tagstruct *t, const pa_cvolume *cvolume) {
unsigned i; unsigned i;
pa_volume_t vol; pa_volume_t vol;
assert(t); pa_assert(t);
extend(t, 2 + cvolume->channels * sizeof(pa_volume_t)); extend(t, 2 + cvolume->channels * sizeof(pa_volume_t));
t->data[t->length++] = PA_TAG_CVOLUME; t->data[t->length++] = PA_TAG_CVOLUME;
@ -237,7 +258,9 @@ int pa_tagstruct_gets(pa_tagstruct*t, const char **s) {
int error = 0; int error = 0;
size_t n; size_t n;
char *c; char *c;
assert(t && s);
pa_assert(t);
pa_assert(s);
if (t->rindex+1 > t->length) if (t->rindex+1 > t->length)
return -1; return -1;
@ -271,7 +294,8 @@ int pa_tagstruct_gets(pa_tagstruct*t, const char **s) {
} }
int pa_tagstruct_getu32(pa_tagstruct*t, uint32_t *i) { int pa_tagstruct_getu32(pa_tagstruct*t, uint32_t *i) {
assert(t && i); pa_assert(t);
pa_assert(i);
if (t->rindex+5 > t->length) if (t->rindex+5 > t->length)
return -1; return -1;
@ -286,7 +310,8 @@ int pa_tagstruct_getu32(pa_tagstruct*t, uint32_t *i) {
} }
int pa_tagstruct_getu8(pa_tagstruct*t, uint8_t *c) { int pa_tagstruct_getu8(pa_tagstruct*t, uint8_t *c) {
assert(t && c); pa_assert(t);
pa_assert(c);
if (t->rindex+2 > t->length) if (t->rindex+2 > t->length)
return -1; return -1;
@ -300,7 +325,8 @@ int pa_tagstruct_getu8(pa_tagstruct*t, uint8_t *c) {
} }
int pa_tagstruct_get_sample_spec(pa_tagstruct *t, pa_sample_spec *ss) { int pa_tagstruct_get_sample_spec(pa_tagstruct *t, pa_sample_spec *ss) {
assert(t && ss); pa_assert(t);
pa_assert(ss);
if (t->rindex+7 > t->length) if (t->rindex+7 > t->length)
return -1; return -1;
@ -319,7 +345,9 @@ int pa_tagstruct_get_sample_spec(pa_tagstruct *t, pa_sample_spec *ss) {
int pa_tagstruct_get_arbitrary(pa_tagstruct *t, const void **p, size_t length) { int pa_tagstruct_get_arbitrary(pa_tagstruct *t, const void **p, size_t length) {
uint32_t len; uint32_t len;
assert(t && p);
pa_assert(t);
pa_assert(p);
if (t->rindex+5+length > t->length) if (t->rindex+5+length > t->length)
return -1; return -1;
@ -337,18 +365,23 @@ int pa_tagstruct_get_arbitrary(pa_tagstruct *t, const void **p, size_t length) {
} }
int pa_tagstruct_eof(pa_tagstruct*t) { int pa_tagstruct_eof(pa_tagstruct*t) {
assert(t); pa_assert(t);
return t->rindex >= t->length; return t->rindex >= t->length;
} }
const uint8_t* pa_tagstruct_data(pa_tagstruct*t, size_t *l) { const uint8_t* pa_tagstruct_data(pa_tagstruct*t, size_t *l) {
assert(t && t->dynamic && l); pa_assert(t);
pa_assert(t->dynamic);
pa_assert(l);
*l = t->length; *l = t->length;
return t->data; return t->data;
} }
int pa_tagstruct_get_boolean(pa_tagstruct*t, int *b) { int pa_tagstruct_get_boolean(pa_tagstruct*t, int *b) {
assert(t && b); pa_assert(t);
pa_assert(b);
if (t->rindex+1 > t->length) if (t->rindex+1 > t->length)
return -1; return -1;
@ -366,6 +399,9 @@ int pa_tagstruct_get_boolean(pa_tagstruct*t, int *b) {
int pa_tagstruct_get_timeval(pa_tagstruct*t, struct timeval *tv) { int pa_tagstruct_get_timeval(pa_tagstruct*t, struct timeval *tv) {
pa_assert(t);
pa_assert(tv);
if (t->rindex+9 > t->length) if (t->rindex+9 > t->length)
return -1; return -1;
@ -382,7 +418,9 @@ int pa_tagstruct_get_timeval(pa_tagstruct*t, struct timeval *tv) {
int pa_tagstruct_get_usec(pa_tagstruct*t, pa_usec_t *u) { int pa_tagstruct_get_usec(pa_tagstruct*t, pa_usec_t *u) {
uint32_t tmp; uint32_t tmp;
assert(t && u);
pa_assert(t);
pa_assert(u);
if (t->rindex+9 > t->length) if (t->rindex+9 > t->length)
return -1; return -1;
@ -400,7 +438,9 @@ int pa_tagstruct_get_usec(pa_tagstruct*t, pa_usec_t *u) {
int pa_tagstruct_getu64(pa_tagstruct*t, uint64_t *u) { int pa_tagstruct_getu64(pa_tagstruct*t, uint64_t *u) {
uint32_t tmp; uint32_t tmp;
assert(t && u);
pa_assert(t);
pa_assert(u);
if (t->rindex+9 > t->length) if (t->rindex+9 > t->length)
return -1; return -1;
@ -418,7 +458,9 @@ int pa_tagstruct_getu64(pa_tagstruct*t, uint64_t *u) {
int pa_tagstruct_gets64(pa_tagstruct*t, int64_t *u) { int pa_tagstruct_gets64(pa_tagstruct*t, int64_t *u) {
uint32_t tmp; uint32_t tmp;
assert(t && u);
pa_assert(t);
pa_assert(u);
if (t->rindex+9 > t->length) if (t->rindex+9 > t->length)
return -1; return -1;
@ -437,8 +479,8 @@ int pa_tagstruct_gets64(pa_tagstruct*t, int64_t *u) {
int pa_tagstruct_get_channel_map(pa_tagstruct *t, pa_channel_map *map) { int pa_tagstruct_get_channel_map(pa_tagstruct *t, pa_channel_map *map) {
unsigned i; unsigned i;
assert(t); pa_assert(t);
assert(map); pa_assert(map);
if (t->rindex+2 > t->length) if (t->rindex+2 > t->length)
return -1; return -1;
@ -463,8 +505,8 @@ int pa_tagstruct_get_cvolume(pa_tagstruct *t, pa_cvolume *cvolume) {
unsigned i; unsigned i;
pa_volume_t vol; pa_volume_t vol;
assert(t); pa_assert(t);
assert(cvolume); pa_assert(cvolume);
if (t->rindex+2 > t->length) if (t->rindex+2 > t->length)
return -1; return -1;
@ -489,7 +531,7 @@ int pa_tagstruct_get_cvolume(pa_tagstruct *t, pa_cvolume *cvolume) {
void pa_tagstruct_put(pa_tagstruct *t, ...) { void pa_tagstruct_put(pa_tagstruct *t, ...) {
va_list va; va_list va;
assert(t); pa_assert(t);
va_start(va, t); va_start(va, t);
@ -550,7 +592,7 @@ void pa_tagstruct_put(pa_tagstruct *t, ...) {
break; break;
default: default:
abort(); pa_assert_not_reached();
} }
} }
@ -561,7 +603,7 @@ int pa_tagstruct_get(pa_tagstruct *t, ...) {
va_list va; va_list va;
int ret = 0; int ret = 0;
assert(t); pa_assert(t);
va_start(va, t); va_start(va, t);
while (ret == 0) { while (ret == 0) {
@ -620,9 +662,8 @@ int pa_tagstruct_get(pa_tagstruct *t, ...) {
ret = pa_tagstruct_get_cvolume(t, va_arg(va, pa_cvolume *)); ret = pa_tagstruct_get_cvolume(t, va_arg(va, pa_cvolume *));
break; break;
default: default:
abort(); pa_assert_not_reached();
} }
} }

View file

@ -26,20 +26,16 @@
#endif #endif
#include <string.h> #include <string.h>
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
#include <pulsecore/dynarray.h> #include <pulsecore/dynarray.h>
#include <pulsecore/gccmacro.h> #include <pulsecore/gccmacro.h>
#include <pulsecore/macro.h>
#include "tokenizer.h" #include "tokenizer.h"
struct pa_tokenizer {
pa_dynarray *dynarray;
};
static void token_free(void *p, PA_GCC_UNUSED void *userdata) { static void token_free(void *p, PA_GCC_UNUSED void *userdata) {
pa_xfree(p); pa_xfree(p);
} }
@ -48,7 +44,9 @@ static void parse(pa_dynarray*a, const char *s, unsigned args) {
int infty = 0; int infty = 0;
const char delimiter[] = " \t\n\r"; const char delimiter[] = " \t\n\r";
const char *p; const char *p;
assert(a && s);
pa_assert(a);
pa_assert(s);
if (args == 0) if (args == 0)
infty = 1; infty = 1;
@ -70,23 +68,23 @@ static void parse(pa_dynarray*a, const char *s, unsigned args) {
} }
pa_tokenizer* pa_tokenizer_new(const char *s, unsigned args) { pa_tokenizer* pa_tokenizer_new(const char *s, unsigned args) {
pa_tokenizer *t; pa_dynarray *a;
t = pa_xmalloc(sizeof(pa_tokenizer)); a = pa_dynarray_new();
t->dynarray = pa_dynarray_new(); parse(a, s, args);
assert(t->dynarray); return (pa_tokenizer*) a;
parse(t->dynarray, s, args);
return t;
} }
void pa_tokenizer_free(pa_tokenizer *t) { void pa_tokenizer_free(pa_tokenizer *t) {
assert(t); pa_dynarray *a = (pa_dynarray*) t;
pa_dynarray_free(t->dynarray, token_free, NULL);
pa_xfree(t); pa_assert(a);
pa_dynarray_free(a, token_free, NULL);
} }
const char *pa_tokenizer_get(pa_tokenizer *t, unsigned i) { const char *pa_tokenizer_get(pa_tokenizer *t, unsigned i) {
assert(t); pa_dynarray *a = (pa_dynarray*) t;
return pa_dynarray_get(t->dynarray, i);
pa_assert(a);
return pa_dynarray_get(a, i);
} }

View file

@ -32,7 +32,6 @@
#include "x11prop.h" #include "x11prop.h"
void pa_x11_set_prop(Display *d, const char *name, const char *data) { void pa_x11_set_prop(Display *d, const char *name, const char *data) {
Atom a = XInternAtom(d, name, False); Atom a = XInternAtom(d, name, False);
XChangeProperty(d, RootWindow(d, 0), a, XA_STRING, 8, PropModeReplace, (const unsigned char*) data, strlen(data)+1); XChangeProperty(d, RootWindow(d, 0), a, XA_STRING, 8, PropModeReplace, (const unsigned char*) data, strlen(data)+1);

View file

@ -25,7 +25,6 @@
#include <config.h> #include <config.h>
#endif #endif
#include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <pulse/xmalloc.h> #include <pulse/xmalloc.h>
@ -34,6 +33,7 @@
#include <pulsecore/log.h> #include <pulsecore/log.h>
#include <pulsecore/props.h> #include <pulsecore/props.h>
#include <pulsecore/core-util.h> #include <pulsecore/core-util.h>
#include <pulsecore/macro.h>
#include "x11wrap.h" #include "x11wrap.h"
@ -47,8 +47,8 @@ struct pa_x11_internal {
}; };
struct pa_x11_wrapper { struct pa_x11_wrapper {
PA_REFCNT_DECLARE;
pa_core *core; pa_core *core;
int ref;
char *property_name; char *property_name;
Display *display; Display *display;
@ -69,7 +69,8 @@ struct pa_x11_client {
/* Dispatch all pending X11 events */ /* Dispatch all pending X11 events */
static void work(pa_x11_wrapper *w) { static void work(pa_x11_wrapper *w) {
assert(w && w->ref >= 1); pa_assert(w);
pa_assert(PA_REFCNT_VALUE(w) >= 1);
while (XPending(w->display)) { while (XPending(w->display)) {
pa_x11_client *c; pa_x11_client *c;
@ -77,7 +78,7 @@ static void work(pa_x11_wrapper *w) {
XNextEvent(w->display, &e); XNextEvent(w->display, &e);
for (c = w->clients; c; c = c->next) { for (c = w->clients; c; c = c->next) {
assert(c->callback); pa_assert(c->callback);
if (c->callback(w, &e, c->userdata) != 0) if (c->callback(w, &e, c->userdata) != 0)
break; break;
} }
@ -87,14 +88,24 @@ static void work(pa_x11_wrapper *w) {
/* IO notification event for the X11 display connection */ /* IO notification event for the X11 display connection */
static void display_io_event(pa_mainloop_api *m, pa_io_event *e, int fd, PA_GCC_UNUSED pa_io_event_flags_t f, void *userdata) { static void display_io_event(pa_mainloop_api *m, pa_io_event *e, int fd, PA_GCC_UNUSED pa_io_event_flags_t f, void *userdata) {
pa_x11_wrapper *w = userdata; pa_x11_wrapper *w = userdata;
assert(m && e && fd >= 0 && w && w->ref >= 1);
pa_assert(m);
pa_assert(e);
pa_assert(fd >= 0);
pa_assert(w);
pa_assert(PA_REFCNT_VALUE(w) >= 1);
work(w); work(w);
} }
/* Deferred notification event. Called once each main loop iteration */ /* Deferred notification event. Called once each main loop iteration */
static void defer_event(pa_mainloop_api *m, pa_defer_event *e, void *userdata) { static void defer_event(pa_mainloop_api *m, pa_defer_event *e, void *userdata) {
pa_x11_wrapper *w = userdata; pa_x11_wrapper *w = userdata;
assert(m && e && w && w->ref >= 1);
pa_assert(m);
pa_assert(e);
pa_assert(w);
pa_assert(PA_REFCNT_VALUE(w) >= 1);
m->defer_enable(e, 0); m->defer_enable(e, 0);
@ -104,7 +115,12 @@ static void defer_event(pa_mainloop_api *m, pa_defer_event *e, void *userdata) {
/* IO notification event for X11 internal connections */ /* IO notification event for X11 internal connections */
static void internal_io_event(pa_mainloop_api *m, pa_io_event *e, int fd, PA_GCC_UNUSED pa_io_event_flags_t f, void *userdata) { static void internal_io_event(pa_mainloop_api *m, pa_io_event *e, int fd, PA_GCC_UNUSED pa_io_event_flags_t f, void *userdata) {
pa_x11_wrapper *w = userdata; pa_x11_wrapper *w = userdata;
assert(m && e && fd >= 0 && w && w->ref >= 1);
pa_assert(m);
pa_assert(e);
pa_assert(fd >= 0);
pa_assert(w);
pa_assert(PA_REFCNT_VALUE(w) >= 1);
XProcessInternalConnection(w->display, fd); XProcessInternalConnection(w->display, fd);
@ -114,10 +130,9 @@ static void internal_io_event(pa_mainloop_api *m, pa_io_event *e, int fd, PA_GCC
/* Add a new IO source for the specified X11 internal connection */ /* Add a new IO source for the specified X11 internal connection */
static pa_x11_internal* x11_internal_add(pa_x11_wrapper *w, int fd) { static pa_x11_internal* x11_internal_add(pa_x11_wrapper *w, int fd) {
pa_x11_internal *i; pa_x11_internal *i;
assert(fd >= 0); pa_assert(fd >= 0);
i = pa_xmalloc(sizeof(pa_x11_internal)); i = pa_xnew(pa_x11_internal, 1);
assert(i);
i->wrapper = w; i->wrapper = w;
i->io_event = w->core->mainloop->io_new(w->core->mainloop, fd, PA_IO_EVENT_INPUT, internal_io_event, w); i->io_event = w->core->mainloop->io_new(w->core->mainloop, fd, PA_IO_EVENT_INPUT, internal_io_event, w);
i->fd = fd; i->fd = fd;
@ -128,7 +143,7 @@ static pa_x11_internal* x11_internal_add(pa_x11_wrapper *w, int fd) {
/* Remove an IO source for an X11 internal connection */ /* Remove an IO source for an X11 internal connection */
static void x11_internal_remove(pa_x11_wrapper *w, pa_x11_internal *i) { static void x11_internal_remove(pa_x11_wrapper *w, pa_x11_internal *i) {
assert(i); pa_assert(i);
PA_LLIST_REMOVE(pa_x11_internal, w->internals, i); PA_LLIST_REMOVE(pa_x11_internal, w->internals, i);
w->core->mainloop->io_free(i->io_event); w->core->mainloop->io_free(i->io_event);
@ -138,7 +153,10 @@ static void x11_internal_remove(pa_x11_wrapper *w, pa_x11_internal *i) {
/* Implementation of XConnectionWatchProc */ /* Implementation of XConnectionWatchProc */
static void x11_watch(Display *display, XPointer userdata, int fd, Bool opening, XPointer *watch_data) { static void x11_watch(Display *display, XPointer userdata, int fd, Bool opening, XPointer *watch_data) {
pa_x11_wrapper *w = (pa_x11_wrapper*) userdata; pa_x11_wrapper *w = (pa_x11_wrapper*) userdata;
assert(display && w && fd >= 0);
pa_assert(display);
pa_assert(w);
pa_assert(fd >= 0);
if (opening) if (opening)
*watch_data = (XPointer) x11_internal_add(w, fd); *watch_data = (XPointer) x11_internal_add(w, fd);
@ -149,16 +167,15 @@ static void x11_watch(Display *display, XPointer userdata, int fd, Bool opening,
static pa_x11_wrapper* x11_wrapper_new(pa_core *c, const char *name, const char *t) { static pa_x11_wrapper* x11_wrapper_new(pa_core *c, const char *name, const char *t) {
pa_x11_wrapper*w; pa_x11_wrapper*w;
Display *d; Display *d;
int r;
if (!(d = XOpenDisplay(name))) { if (!(d = XOpenDisplay(name))) {
pa_log("XOpenDisplay() failed"); pa_log("XOpenDisplay() failed");
return NULL; return NULL;
} }
w = pa_xmalloc(sizeof(pa_x11_wrapper)); w = pa_xnew(pa_x11_wrapper, 1);
PA_REFCNT_INIT(w);
w->core = c; w->core = c;
w->ref = 1;
w->property_name = pa_xstrdup(t); w->property_name = pa_xstrdup(t);
w->display = d; w->display = d;
@ -170,20 +187,17 @@ static pa_x11_wrapper* x11_wrapper_new(pa_core *c, const char *name, const char
XAddConnectionWatch(d, x11_watch, (XPointer) w); XAddConnectionWatch(d, x11_watch, (XPointer) w);
r = pa_property_set(c, w->property_name, w); pa_assert_se(pa_property_set(c, w->property_name, w) >= 0);
assert(r >= 0);
return w; return w;
} }
static void x11_wrapper_free(pa_x11_wrapper*w) { static void x11_wrapper_free(pa_x11_wrapper*w) {
int r; pa_assert(w);
assert(w);
r = pa_property_remove(w->core, w->property_name); pa_assert_se(pa_property_remove(w->core, w->property_name) >= 0);
assert(r >= 0);
assert(!w->clients); pa_assert(!w->clients);
XRemoveConnectionWatch(w->display, x11_watch, (XPointer) w); XRemoveConnectionWatch(w->display, x11_watch, (XPointer) w);
XCloseDisplay(w->display); XCloseDisplay(w->display);
@ -201,7 +215,8 @@ static void x11_wrapper_free(pa_x11_wrapper*w) {
pa_x11_wrapper* pa_x11_wrapper_get(pa_core *c, const char *name) { pa_x11_wrapper* pa_x11_wrapper_get(pa_core *c, const char *name) {
char t[256]; char t[256];
pa_x11_wrapper *w; pa_x11_wrapper *w;
assert(c);
pa_core_assert_ref(c);
pa_snprintf(t, sizeof(t), "x11-wrapper%s%s", name ? "-" : "", name ? name : ""); pa_snprintf(t, sizeof(t), "x11-wrapper%s%s", name ? "-" : "", name ? name : "");
if ((w = pa_property_get(c, t))) if ((w = pa_property_get(c, t)))
@ -211,20 +226,24 @@ pa_x11_wrapper* pa_x11_wrapper_get(pa_core *c, const char *name) {
} }
pa_x11_wrapper* pa_x11_wrapper_ref(pa_x11_wrapper *w) { pa_x11_wrapper* pa_x11_wrapper_ref(pa_x11_wrapper *w) {
assert(w && w->ref >= 1); pa_assert(w);
w->ref++; pa_assert(PA_REFCNT_VALUE(w) >= 1);
PA_REFCNT_INC(w);
return w; return w;
} }
void pa_x11_wrapper_unref(pa_x11_wrapper* w) { void pa_x11_wrapper_unref(pa_x11_wrapper* w) {
assert(w && w->ref >= 1); pa_assert(w);
pa_assert(PA_REFCNT_VALUE(w) >= 1);
if (!(--w->ref)) if (PA_REFCNT_DEC(w) <= 0)
x11_wrapper_free(w); x11_wrapper_free(w);
} }
Display *pa_x11_wrapper_get_display(pa_x11_wrapper *w) { Display *pa_x11_wrapper_get_display(pa_x11_wrapper *w) {
assert(w && w->ref >= 1); pa_assert(w);
pa_assert(PA_REFCNT_VALUE(w) >= 1);
/* Somebody is using us, schedule a output buffer flush */ /* Somebody is using us, schedule a output buffer flush */
w->core->mainloop->defer_enable(w->defer_event, 1); w->core->mainloop->defer_enable(w->defer_event, 1);
@ -234,9 +253,11 @@ Display *pa_x11_wrapper_get_display(pa_x11_wrapper *w) {
pa_x11_client* pa_x11_client_new(pa_x11_wrapper *w, int (*cb)(pa_x11_wrapper *w, XEvent *e, void *userdata), void *userdata) { pa_x11_client* pa_x11_client_new(pa_x11_wrapper *w, int (*cb)(pa_x11_wrapper *w, XEvent *e, void *userdata), void *userdata) {
pa_x11_client *c; pa_x11_client *c;
assert(w && w->ref >= 1);
c = pa_xmalloc(sizeof(pa_x11_client)); pa_assert(w);
pa_assert(PA_REFCNT_VALUE(w) >= 1);
c = pa_xnew(pa_x11_client, 1);
c->wrapper = w; c->wrapper = w;
c->callback = cb; c->callback = cb;
c->userdata = userdata; c->userdata = userdata;
@ -247,7 +268,9 @@ pa_x11_client* pa_x11_client_new(pa_x11_wrapper *w, int (*cb)(pa_x11_wrapper *w,
} }
void pa_x11_client_free(pa_x11_client *c) { void pa_x11_client_free(pa_x11_client *c) {
assert(c && c->wrapper && c->wrapper->ref >= 1); pa_assert(c);
pa_assert(c->wrapper);
pa_assert(PA_REFCNT_VALUE(c->wrapper) >= 1);
PA_LLIST_REMOVE(pa_x11_client, c->wrapper->clients, c); PA_LLIST_REMOVE(pa_x11_client, c->wrapper->clients, c);
pa_xfree(c); pa_xfree(c);