[Spice-devel] [PATCH spice-common] Marshaller: rename _add_ref() to _add_by_ref()

Jonathon Jongsma jjongsma at redhat.com
Mon Dec 5 22:19:04 UTC 2016


The spice_marshaller_add_ref() family of functions is confusing since it
sounds like you're incrementing a reference on the marshaller. What it
is actually doing is adding a data buffer to the marshaller by reference
rather than by value. Changing the function names to _add_by_ref() makes
this clearer.

The old functions are deprecated and are simply inline functions that
call the new functions.
---
 common/marshaller.c | 14 +++++++-------
 common/marshaller.h | 21 +++++++++++++++++----
 2 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/common/marshaller.c b/common/marshaller.c
index 00a7123..2fccd52 100644
--- a/common/marshaller.c
+++ b/common/marshaller.c
@@ -317,8 +317,8 @@ void spice_marshaller_unreserve_space(SpiceMarshaller *m, size_t size)
     item->len -= size;
 }
 
-uint8_t *spice_marshaller_add_ref_full(SpiceMarshaller *m, uint8_t *data, size_t size,
-                                       spice_marshaller_item_free_func free_data, void *opaque)
+uint8_t *spice_marshaller_add_by_ref_full(SpiceMarshaller *m, uint8_t *data, size_t size,
+                                          spice_marshaller_item_free_func free_data, void *opaque)
 {
     MarshallerItem *item;
     SpiceMarshallerData *d;
@@ -349,21 +349,21 @@ uint8_t *spice_marshaller_add(SpiceMarshaller *m, const uint8_t *data, size_t si
     return ptr;
 }
 
-uint8_t *spice_marshaller_add_ref(SpiceMarshaller *m, const uint8_t *data, size_t size)
+uint8_t *spice_marshaller_add_by_ref(SpiceMarshaller *m, const uint8_t *data, size_t size)
 {
     /* the cast to no-const here is safe as data is used for writing only if
      * free_data pointer is not NULL
      */
-    return spice_marshaller_add_ref_full(m, (uint8_t *) data, size, NULL, NULL);
+    return spice_marshaller_add_by_ref_full(m, (uint8_t *) data, size, NULL, NULL);
 }
 
-void spice_marshaller_add_ref_chunks(SpiceMarshaller *m, SpiceChunks *chunks)
+void spice_marshaller_add_chunks_by_ref(SpiceMarshaller *m, SpiceChunks *chunks)
 {
     unsigned int i;
 
     for (i = 0; i < chunks->num_chunks; i++) {
-        spice_marshaller_add_ref(m, chunks->chunk[i].data,
-                                 chunks->chunk[i].len);
+        spice_marshaller_add_by_ref(m, chunks->chunk[i].data,
+                                    chunks->chunk[i].len);
     }
 }
 
diff --git a/common/marshaller.h b/common/marshaller.h
index 316184e..9ae1bdf 100644
--- a/common/marshaller.h
+++ b/common/marshaller.h
@@ -38,10 +38,23 @@ void spice_marshaller_destroy(SpiceMarshaller *m);
 uint8_t *spice_marshaller_reserve_space(SpiceMarshaller *m, size_t size);
 void spice_marshaller_unreserve_space(SpiceMarshaller *m, size_t size);
 uint8_t *spice_marshaller_add(SpiceMarshaller *m, const uint8_t *data, size_t size);
-uint8_t *spice_marshaller_add_ref(SpiceMarshaller *m, const uint8_t *data, size_t size);
-uint8_t *spice_marshaller_add_ref_full(SpiceMarshaller *m, uint8_t *data, size_t size,
-                                       spice_marshaller_item_free_func free_data, void *opaque);
-void     spice_marshaller_add_ref_chunks(SpiceMarshaller *m, SpiceChunks *chunks);
+uint8_t *spice_marshaller_add_by_ref(SpiceMarshaller *m, const uint8_t *data, size_t size);
+uint8_t *spice_marshaller_add_by_ref_full(SpiceMarshaller *m, uint8_t *data, size_t size,
+                                          spice_marshaller_item_free_func free_data, void *opaque);
+void spice_marshaller_add_chunks_by_ref(SpiceMarshaller *m, SpiceChunks *chunks);
+SPICE_GNUC_DEPRECATED inline uint8_t *spice_marshaller_add_ref(SpiceMarshaller *m, const uint8_t *data, size_t size)
+{
+    return spice_marshaller_add_by_ref(m, data, size);
+}
+SPICE_GNUC_DEPRECATED inline uint8_t *spice_marshaller_add_ref_full(SpiceMarshaller *m, uint8_t *data, size_t size,
+                                              spice_marshaller_item_free_func free_data, void *opaque)
+{
+    return spice_marshaller_add_by_ref_full(m, data, size, free_data, opaque);
+}
+SPICE_GNUC_DEPRECATED inline void spice_marshaller_add_ref_chunks(SpiceMarshaller *m, SpiceChunks *chunks)
+{
+    spice_marshaller_add_chunks_by_ref(m, chunks);
+}
 void spice_marshaller_flush(SpiceMarshaller *m);
 void spice_marshaller_set_base(SpiceMarshaller *m, size_t base);
 uint8_t *spice_marshaller_linearize(SpiceMarshaller *m, size_t skip,
-- 
2.7.4



More information about the Spice-devel mailing list