[libgsf] GsfOutputMemory: allow stealing the buffer.



commit 6fc7f14c28112531680e6486187126b9574c3e64
Author: Morten Welinder <terra gnome org>
Date:   Wed Oct 16 19:47:14 2019 -0400

    GsfOutputMemory: allow stealing the buffer.

 ChangeLog               |  5 +++++
 NEWS                    |  3 +++
 gsf/gsf-output-memory.c | 20 ++++++++++++++++++++
 gsf/gsf-output-memory.h |  1 +
 4 files changed, 29 insertions(+)
---
diff --git a/ChangeLog b/ChangeLog
index bf47d94..4290099 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2019-10-16  Morten Welinder  <terra gnome org>
+
+       * gsf/gsf-output-memory.c (gsf_output_memory_steal_bytes): New
+       function.  Code from Allin Cottrell.
+
 2019-05-04  Morten Welinder <terra gnome org>
 
        * configure.ac: Post-release bump.
diff --git a/NEWS b/NEWS
index 8762381..7c165ae 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
 libgsf 1.14.47
 
+Allin Cottrell:
+       * GsfOutputMemory improvement.
+
 --------------------------------------------------------------------------
 libgsf 1.14.46
 
diff --git a/gsf/gsf-output-memory.c b/gsf/gsf-output-memory.c
index 57ef07a..5cb80e5 100644
--- a/gsf/gsf-output-memory.c
+++ b/gsf/gsf-output-memory.c
@@ -197,6 +197,26 @@ gsf_output_memory_get_bytes (GsfOutputMemory * mem)
        return mem->buffer;
 }
 
+/**
+ * gsf_output_memory_steal_bytes:
+ * @mem: the output device.
+ *
+ * Returns: (array) (nullable): The data that has been written to @mem.
+ * The caller takes ownership and the buffer belonging to @mem is set
+ * to %NULL.
+ **/
+guint8 *
+gsf_output_memory_steal_bytes (GsfOutputMemory * mem)
+{
+       guint8 *bytes;
+
+       g_return_val_if_fail (mem != NULL, NULL);
+       bytes = mem->buffer;
+       mem->buffer = NULL;
+       mem->capacity = 0;
+       return bytes;
+}
+
 GSF_CLASS (GsfOutputMemory, gsf_output_memory,
           gsf_output_memory_class_init, gsf_output_memory_init,
           GSF_OUTPUT_TYPE)
diff --git a/gsf/gsf-output-memory.h b/gsf/gsf-output-memory.h
index 8b3875a..1054fa3 100644
--- a/gsf/gsf-output-memory.h
+++ b/gsf/gsf-output-memory.h
@@ -38,6 +38,7 @@ GType gsf_output_memory_get_type      (void);
 
 GsfOutput *gsf_output_memory_new      (void);
 const guint8* gsf_output_memory_get_bytes (GsfOutputMemory * mem);
+guint8* gsf_output_memory_steal_bytes (GsfOutputMemory * mem);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]