context: hide error attr behind pointer
authorLyndon Brown <jnqnfe@gmail.com>
Thu, 7 Jun 2018 01:43:56 +0000 (02:43 +0100)
committerArun Raghavan <arun@arunraghavan.net>
Thu, 21 Jun 2018 01:00:25 +0000 (06:30 +0530)
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
src/pulse/internal.h

index adbeb15..d298ae3 100644 (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) {
index 01d2b6e..04f35e9 100644 (file)
 #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;