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 679668 - gio: g_input_stream_read_bytes() reads all bytes
gio: g_input_stream_read_bytes() reads all bytes
Status: RESOLVED DUPLICATE of bug 679662
Product: glib
Classification: Platform
Component: gio
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2012-07-10 08:43 UTC by Stef Walter
Modified: 2012-07-11 09:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gio: g_input_stream_read_bytes() reads all bytes (9.37 KB, patch)
2012-07-10 08:43 UTC, Stef Walter
needs-work Details | Review

Description Stef Walter 2012-07-10 08:43:48 UTC
Currently using g_input_stream_read_bytes() is pretty strange because
you need to be prepared to call it multiple times in order to get the
data that you're expecting. In the end you can have N GBytes that you
can't easily join or use together.

So this changes it so we try to get the number of bytes requested
and g_input_stream_read_bytes() becomes more like g_input_stream_read_all().

We could also change @count to be gssize, and if set to -1 try to
read until EOF. This would be similar to python's fd.read() when no
size is specified. What do you think?
Comment 1 Stef Walter 2012-07-10 08:43:52 UTC
Created attachment 218402 [details] [review]
gio: g_input_stream_read_bytes() reads all bytes

 * Make g_input_stream_read_bytes() and friends behave more
   like g_input_stream_read_all(). Read all bytes requested
   until error or EOF.
 * These functions become much less awkward to use with GBytes,
   especially since you can't join bytes together, and generally
   shouldn't try to write to the data inside a GBytes.
Comment 2 Colin Walters 2012-07-10 12:48:27 UTC
Review of attachment 218402 [details] [review]:

We don't have tests for this one?  Code looks fine.

::: gio/ginputstream.c
@@ +684,3 @@
+  gsize nread;
+  int io_priority;
+} ReadBytesClosure;

Looking forward to GTask landing...

@@ +691,3 @@
+  ReadBytesClosure *closure = data;
+  if (closure->cancellable)
+    g_object_unref (closure->cancellable);

g_clear_object() ?
Comment 3 Colin Walters 2012-07-10 12:48:28 UTC
Review of attachment 218402 [details] [review]:

We don't have tests for this one?  Code looks fine.

::: gio/ginputstream.c
@@ +684,3 @@
+  gsize nread;
+  int io_priority;
+} ReadBytesClosure;

Looking forward to GTask landing...

@@ +691,3 @@
+  ReadBytesClosure *closure = data;
+  if (closure->cancellable)
+    g_object_unref (closure->cancellable);

g_clear_object() ?
Comment 4 Dan Winship 2012-07-10 13:08:41 UTC
Comment on attachment 218402 [details] [review]
gio: g_input_stream_read_bytes() reads all bytes

same bindings API issue as the write_bytes patch
Comment 5 Stef Walter 2012-07-11 09:41:56 UTC
Lets discuss this on at bug #679662. Would be nice if there was symmetry between the two solutions.

*** This bug has been marked as a duplicate of bug 679662 ***