From 5b4c9453f3b1c53290fc5f136716ef7af5193ef3 Mon Sep 17 00:00:00 2001 From: Lyndon Brown Date: Thu, 7 Jun 2018 02:43:56 +0100 Subject: context: hide error attr behind pointer Paves the way towards more of the API using const pointers. Some pa_context_* functions return their errors by setting the context error, even when there's no other change in the context state. This prevented constifying the pa_context arguments of such functions. This patch puts the error in its own struct behind a pointer, so that setting the error doesn't any more count as modifying the pa_context object. --- src/pulse/context.c | 9 ++++++--- src/pulse/internal.h | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/pulse/context.c b/src/pulse/context.c index adbeb1531..d298ae3ec 100644 --- a/src/pulse/context.c +++ b/src/pulse/context.c @@ -139,6 +139,9 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char * c = pa_xnew0(pa_context, 1); PA_REFCNT_INIT(c); + c->error = pa_xnew0(pa_context_error, 1); + assert(c->error); + c->proplist = p ? pa_proplist_copy(p) : pa_proplist_new(); if (name) @@ -156,7 +159,7 @@ pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char * PA_LLIST_HEAD_INIT(pa_stream, c->streams); PA_LLIST_HEAD_INIT(pa_operation, c->operations); - c->error = PA_OK; + c->error->error = PA_OK; c->state = PA_CONTEXT_UNCONNECTED; reset_callbacks(c); @@ -315,7 +318,7 @@ int pa_context_set_error(pa_context *c, int error) { pa_assert(error < PA_ERR_MAX); if (c) - c->error = error; + c->error->error = error; return error; } @@ -1072,7 +1075,7 @@ int pa_context_errno(pa_context *c) { pa_assert(PA_REFCNT_VALUE(c) >= 1); - return c->error; + return c->error->error; } void pa_context_set_state_callback(pa_context *c, pa_context_notify_cb_t cb, void *userdata) { diff --git a/src/pulse/internal.h b/src/pulse/internal.h index 01d2b6e4e..04f35e9a3 100644 --- a/src/pulse/internal.h +++ b/src/pulse/internal.h @@ -55,6 +55,10 @@ #define PA_PROTOCOL_FLAG_SHM 0x80000000U #define PA_PROTOCOL_FLAG_MEMFD 0x40000000U +typedef struct pa_context_error { + int error; +} pa_context_error; + struct pa_context { PA_REFCNT_DECLARE; @@ -80,7 +84,7 @@ struct pa_context { uint32_t version; uint32_t ctag; uint32_t csyncid; - int error; + pa_context_error *error; pa_context_state_t state; pa_context_notify_cb_t state_callback; -- cgit v1.2.1