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 594376 - File.load_contents should have "out uint8[]" instead of "out string"
File.load_contents should have "out uint8[]" instead of "out string"
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Bindings: GLib
unspecified
Other All
: Normal trivial
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on: 529866
Blocks:
 
 
Reported: 2009-09-07 13:52 UTC by zarevucky.jiri
Modified: 2011-05-11 20:26 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description zarevucky.jiri 2009-09-07 13:52:43 UTC
Rationale:
It's very simple to convert from char array to string, but for the other direction you need to copy it.
Comment 1 Evan Nemerson 2009-11-24 09:40:02 UTC
I don't disagree with you, but I'd prefer to see bug #529866 fixed first so that the API only need be changed once, to this:

public static bool get_contents (string filename,
  [CCode (array_length_type = "size_t")] out char[] contents) throws FileError;
public static bool set_contents (string filename,
  [CCode (array_length_type = "ssize_t")] char[] contents) throws FileError;

Meanwhile, recent versions of valac have a string.to_utf8() method (see http://git.gnome.org/cgit/vala/commit/?id=6f4c7dec8d16ede148824da2203b447d77db5763) which should help... it still makes a copy, but at least it's easy.
Comment 2 zarevucky.jiri 2009-11-24 21:26:57 UTC
Thanks for response. Yep, that one needs to be fixed first.
By the way, there is another problem with file's content not necessarily being UTF-8 encoded text. It can be a different encoding or some arbitrary binary data (with NUL characters), in which case to_utf8() can't be used.
Comment 3 Sam 2010-05-03 12:36:04 UTC
The receive, receive_from, send and send_to methods on GIO's Socket class also have string arguments for what are really byte arrays. Should a separate bug be opened for each discovered case of this same problem?
Comment 4 Evan Nemerson 2010-06-21 06:46:39 UTC
Sam, no, I'll make sure to include them. Thanks for reporting them, though.

FWIW, I think I'm going to have to go through all everything that comes up in `grep -P 'string [^,]+\, [a-z0-9_]+ (len|size)' *.vapi` (~200 methods).
Comment 5 Luca Bruno 2011-05-11 20:26:26 UTC
commit d51a3caec9bda0536b066aef066b744d494d92c1
Author: Luca Bruno <lucabru@src.gnome.org>
Date:   Wed May 11 22:23:13 2011 +0200

    gio-2.0: Use out uint8[] for File.load_* methods
    
    Fixes bug 594376.

This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.