After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 547481 - g_data_input_stream_read_line behaves not as stated in the docs
g_data_input_stream_read_line behaves not as stated in the docs
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Alexander Larsson
gtkdev
Depends on:
Blocks:
 
 
Reported: 2008-08-12 19:26 UTC by Paul Pogonyshev
Modified: 2008-12-01 19:11 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Paul Pogonyshev 2008-08-12 19:26:00 UTC
I'm wrapping the function in PyGObject.  It apparently doesn't return line with newlines included as it claims in the docs: "Returns: a string with the line that was read in (including the newlines). Set length to a gsize to get the length of the read line. Returns NULL on an error."

If this can help, here is a test case in Python:

class TestDataInputStream(unittest.TestCase):
    def setUp(self):
        self.base_stream = gio.MemoryInputStream()
        self.data_stream = gio.DataInputStream(self.base_stream)

    def test_read_line(self):
        self.base_stream.add_data('foo\nbar\n\nbaz')
        self.assertEquals('foo\n', self.data_stream.read_line())
        self.assertEquals('bar\n', self.data_stream.read_line())
        self.assertEquals('\n', self.data_stream.read_line())
        self.assertEquals('baz', self.data_stream.read_line())

As I see, it returns 'foo', 'bar', '', 'baz' instead of expected values.
Comment 1 Matthias Clasen 2008-11-28 07:45:53 UTC
2008-11-28  Matthias Clasen  <mclasen@redhat.com>

        Bug 547481 – g_data_input_stream_read_line behaves not as stated in
        the docs

        * gdatainputstream.c (g_data_input_stream_read_line): Behave as
        documented and include the line end in the returned string.
        Pointed out by Paul Pogonyshev.

        * tests/data-input-stream.c: Fix the read_line test to test the
        documented behaviour.

Comment 2 Alexander Larsson 2008-12-01 13:44:56 UTC
Uhm? Why not change the docs instead of breaking all apps that currently use this?
Comment 3 Matthias Clasen 2008-12-01 19:06:48 UTC
I honestly wasn't sure which way to go here. If you prefer to keep it the way it was and update the docs.

I've reverted it to the old behaviour now.
Comment 4 Paul Pogonyshev 2008-12-01 19:11:06 UTC
For the record, I think this way (to change docs) is better now.  I'd prefer having newlines returned, but not after one stable version already strips them.