mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-09 19:06:15 +01:00
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
This commit is contained in:
parent
1ab68f9ee9
commit
b89e432e8d
@ -1,3 +1,12 @@
|
||||
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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user