GNOME Bugzilla – Bug 594376
File.load_contents should have "out uint8[]" instead of "out string"
Last modified: 2011-05-11 20:26:26 UTC
Rationale: It's very simple to convert from char array to string, but for the other direction you need to copy it.
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.
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.
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?
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).
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.