mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-05-09 23:43:11 +02: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>
|
2009-02-26 Alexander Larsson <alexl@redhat.com>
|
||||||
|
|
||||||
Bug 543183 – Clarify docs for g_file_has_prefix
|
Bug 543183 – Clarify docs for g_file_has_prefix
|
||||||
|
@ -48,6 +48,7 @@ struct _GMemoryOutputStreamPrivate {
|
|||||||
|
|
||||||
gpointer data;
|
gpointer data;
|
||||||
gsize len;
|
gsize len;
|
||||||
|
gsize valid_len; /* The part of data that has been written to */
|
||||||
|
|
||||||
goffset pos;
|
goffset pos;
|
||||||
|
|
||||||
@ -205,6 +206,7 @@ g_memory_output_stream_new (gpointer data,
|
|||||||
priv->destroy = destroy;
|
priv->destroy = destroy;
|
||||||
|
|
||||||
priv->pos = 0;
|
priv->pos = 0;
|
||||||
|
priv->valid_len = 0;
|
||||||
|
|
||||||
return stream;
|
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);
|
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->data = data;
|
||||||
priv->len = size;
|
priv->len = size;
|
||||||
|
|
||||||
|
if (priv->len < priv->valid_len)
|
||||||
|
priv->valid_len = priv->len;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,6 +402,9 @@ g_memory_output_stream_write (GOutputStream *stream,
|
|||||||
memcpy (dest, buffer, count);
|
memcpy (dest, buffer, count);
|
||||||
priv->pos += count;
|
priv->pos += count;
|
||||||
|
|
||||||
|
if (priv->pos > priv->valid_len)
|
||||||
|
priv->valid_len = priv->pos;
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,6 +72,15 @@ test_data_size (void)
|
|||||||
pos = g_seekable_tell (G_SEEKABLE (mo));
|
pos = g_seekable_tell (G_SEEKABLE (mo));
|
||||||
g_assert_cmpint (pos, ==, 1);
|
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 (o);
|
||||||
g_object_unref (mo);
|
g_object_unref (mo);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user