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.
This commit is contained in:
Lyndon Brown 2018-06-07 02:43:56 +01:00 committed by Arun Raghavan
parent 9472bebcb0
commit f727cd9ac0
2 changed files with 11 additions and 4 deletions

View file

@ -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) {

View file

@ -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;