[glib] GMemoryOutputStream: Add new _resizable() constructor usable from bindings
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GMemoryOutputStream: Add new _resizable() constructor usable from bindings
- Date: Wed, 28 Nov 2012 01:51:19 +0000 (UTC)
commit ed5c17e11f3b37b0725e1ca2f62511338fa23f1b
Author: Colin Walters <walters verbum org>
Date: Thu Nov 22 08:23:27 2012 -0500
GMemoryOutputStream: Add new _resizable() constructor usable from bindings
Really, the memory output stream API is too warped around the model
where it's a fixed size buffer that you've already allocated. Even in
C, I find myself always wanting to use it to just accumulate data into
an arbitrary-sized buffer it allocates.
Unfortunately, it's also not usable from bindings because it's not
common to bind g_free() and g_realloc(), but if you just pass NULL, you
get the default of a fixed size, which is useless as per above.
I am going to use this from a gjs test case, and the GSubprocess test
cases also will use it.
https://bugzilla.gnome.org/show_bug.cgi?id=688931
docs/reference/gio/gio-sections.txt | 1 +
gio/gio.symbols | 1 +
gio/gmemoryoutputstream.c | 14 ++++++++++++++
gio/gmemoryoutputstream.h | 2 ++
gio/tests/memory-output-stream.c | 4 ++--
5 files changed, 20 insertions(+), 2 deletions(-)
---
diff --git a/docs/reference/gio/gio-sections.txt b/docs/reference/gio/gio-sections.txt
index 7142227..6bec120 100644
--- a/docs/reference/gio/gio-sections.txt
+++ b/docs/reference/gio/gio-sections.txt
@@ -863,6 +863,7 @@ GBufferedOutputStreamPrivate
GReallocFunc
GMemoryOutputStream
g_memory_output_stream_new
+g_memory_output_stream_new_resizable
g_memory_output_stream_get_data
g_memory_output_stream_get_size
g_memory_output_stream_get_data_size
diff --git a/gio/gio.symbols b/gio/gio.symbols
index afffd7d..9df4fef 100644
--- a/gio/gio.symbols
+++ b/gio/gio.symbols
@@ -573,6 +573,7 @@ g_memory_input_stream_add_bytes
g_memory_input_stream_add_data
g_memory_output_stream_get_type
g_memory_output_stream_new
+g_memory_output_stream_new_resizable
g_memory_output_stream_get_data
g_memory_output_stream_get_data_size
g_memory_output_stream_get_size
diff --git a/gio/gmemoryoutputstream.c b/gio/gmemoryoutputstream.c
index 378bf3c..542732b 100644
--- a/gio/gmemoryoutputstream.c
+++ b/gio/gmemoryoutputstream.c
@@ -382,6 +382,20 @@ g_memory_output_stream_new (gpointer data,
}
/**
+ * g_memory_output_stream_new_resizable:
+ *
+ * Creates a new #GMemoryOutputStream, using g_realloc() and g_free()
+ * for memory allocation.
+ *
+ * Since: 2.36
+ */
+GOutputStream *
+g_memory_output_stream_new_resizable (void)
+{
+ return g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
+}
+
+/**
* g_memory_output_stream_get_data:
* @ostream: a #GMemoryOutputStream
*
diff --git a/gio/gmemoryoutputstream.h b/gio/gmemoryoutputstream.h
index faf0364..8be37e6 100644
--- a/gio/gmemoryoutputstream.h
+++ b/gio/gmemoryoutputstream.h
@@ -88,6 +88,8 @@ GOutputStream *g_memory_output_stream_new (gpointer data,
gsize size,
GReallocFunc realloc_function,
GDestroyNotify destroy_function);
+GLIB_AVAILABLE_IN_2_36
+GOutputStream *g_memory_output_stream_new_resizable (void);
gpointer g_memory_output_stream_get_data (GMemoryOutputStream *ostream);
gsize g_memory_output_stream_get_size (GMemoryOutputStream *ostream);
gsize g_memory_output_stream_get_data_size (GMemoryOutputStream *ostream);
diff --git a/gio/tests/memory-output-stream.c b/gio/tests/memory-output-stream.c
index e9bfc3d..3399bbe 100644
--- a/gio/tests/memory-output-stream.c
+++ b/gio/tests/memory-output-stream.c
@@ -34,7 +34,7 @@ test_truncate (void)
g_test_bug ("540423");
- mo = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
+ mo = g_memory_output_stream_new_resizable ();
g_assert (g_seekable_can_truncate (G_SEEKABLE (mo)));
o = g_data_output_stream_new (mo);
for (i = 0; i < 1000; i++)
@@ -86,7 +86,7 @@ test_data_size (void)
g_test_bug ("540459");
- mo = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
+ mo = g_memory_output_stream_new_resizable ();
o = g_data_output_stream_new (mo);
g_data_output_stream_put_byte (o, 1, NULL, NULL);
pos = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (mo));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]