summaryrefslogtreecommitdiff
path: root/gio
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2009-02-26 15:41:29 +0000
committerAlexander Larsson <alexl@src.gnome.org>2009-02-26 15:41:29 +0000
commitb89e432e8da002c574571abb9ebc8a977bb24a1d (patch)
tree9075150124ed5e230b6470a02003baf845520d66 /gio
parent1ab68f9ee988ecfd9825c250ff8524118bc206c6 (diff)
Bug 540461 – g_memory_output_stream_get_data_size() doesn't behave as
2009-02-26 Alexander Larsson <alexl@redhat.com> Bug 540461 – g_memory_output_stream_get_data_size() doesn't behave as document * gmemoryoutputstream.c: Track actual valid size, even if we later seek back. * tests/memory-output-stream.c: Add testcase svn path=/trunk/; revision=7916
Diffstat (limited to 'gio')
-rw-r--r--gio/ChangeLog9
-rw-r--r--gio/gmemoryoutputstream.c10
-rw-r--r--gio/tests/memory-output-stream.c9
3 files changed, 27 insertions, 1 deletions
diff --git a/gio/ChangeLog b/gio/ChangeLog
index 9baa476b1..e1f97d9bf 100644
--- a/gio/ChangeLog
+++ b/gio/ChangeLog
@@ -1,5 +1,14 @@
2009-02-26 Alexander Larsson <alexl@redhat.com>
+ Bug 540461 – g_memory_output_stream_get_data_size() doesn't behave as document
+ * gmemoryoutputstream.c:
+ Track actual valid size, even if we later seek back.
+
+ * tests/memory-output-stream.c:
+ Add testcase
+
+2009-02-26 Alexander Larsson <alexl@redhat.com>
+
Bug 543183 – Clarify docs for g_file_has_prefix
* gfile.c: (g_file_has_prefix):
diff --git a/gio/gmemoryoutputstream.c b/gio/gmemoryoutputstream.c
index 066d60e24..6da57612a 100644
--- a/gio/gmemoryoutputstream.c
+++ b/gio/gmemoryoutputstream.c
@@ -48,6 +48,7 @@ struct _GMemoryOutputStreamPrivate {
gpointer data;
gsize len;
+ gsize valid_len; /* The part of data that has been written to */
goffset pos;
@@ -205,6 +206,7 @@ g_memory_output_stream_new (gpointer data,
priv->destroy = destroy;
priv->pos = 0;
+ priv->valid_len = 0;
return stream;
}
@@ -271,7 +273,7 @@ g_memory_output_stream_get_data_size (GMemoryOutputStream *ostream)
{
g_return_val_if_fail (G_IS_MEMORY_OUTPUT_STREAM (ostream), 0);
- return ostream->priv->pos;
+ return ostream->priv->valid_len;
}
@@ -346,6 +348,9 @@ array_resize (GMemoryOutputStream *ostream,
priv->data = data;
priv->len = size;
+ if (priv->len < priv->valid_len)
+ priv->valid_len = priv->len;
+
return TRUE;
}
@@ -396,6 +401,9 @@ g_memory_output_stream_write (GOutputStream *stream,
dest = (guint8 *)priv->data + priv->pos;
memcpy (dest, buffer, count);
priv->pos += count;
+
+ if (priv->pos > priv->valid_len)
+ priv->valid_len = priv->pos;
return count;
}
diff --git a/gio/tests/memory-output-stream.c b/gio/tests/memory-output-stream.c
index c340e79ca..cc1e1ea37 100644
--- a/gio/tests/memory-output-stream.c
+++ b/gio/tests/memory-output-stream.c
@@ -72,6 +72,15 @@ test_data_size (void)
pos = g_seekable_tell (G_SEEKABLE (mo));
g_assert_cmpint (pos, ==, 1);
+ g_test_bug ("540461");
+
+ g_seekable_seek (G_SEEKABLE (mo), 0, G_SEEK_SET, NULL, NULL);
+ pos = g_seekable_tell (G_SEEKABLE (mo));
+ g_assert_cmpint (pos, ==, 0);
+
+ pos = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (mo));
+ g_assert_cmpint (pos, ==, 1);
+
g_object_unref (o);
g_object_unref (mo);
}