diff options
-rw-r--r-- | gio/ChangeLog | 9 | ||||
-rw-r--r-- | gio/gmemoryoutputstream.c | 10 | ||||
-rw-r--r-- | gio/tests/memory-output-stream.c | 9 |
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); } |