[m-rev.] diff: mark io.write_bytes as obsolete

Simon Taylor staylr at gmail.com
Sat Feb 24 21:23:06 AEDT 2007


Estimated hours taken: 0.25
Branches: main

NEWS:
library/io.m:
compiler/bytecode_data.m:
	Mark io.write_bytes as obsolete, because strings are a poor
	choice of representation for binary data.  Use bitmaps and
	io.write_bitmap instead.


Index: NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.447
diff -u -u -r1.447 NEWS
--- NEWS	15 Feb 2007 00:41:47 -0000	1.447
+++ NEWS	16 Feb 2007 04:28:46 -0000
@@ -85,7 +85,8 @@
 	copy_bytes_in_bitmap/4
 
 * The io module now contains predicates io.read_bitmap/{4,5,6,7} and
-  io.write_bitmap{3,4,5,6}.
+  io.write_bitmap{3,4,5,6}.  io.write_bytes/{3,4} are now marked as
+  obsolete.
 
 * The operations in bitmap.m and version_bitmap.m which treat bitmaps
   as sets have been modified to throw an exception when the input
Index: compiler/bytecode_data.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/bytecode_data.m,v
retrieving revision 1.22
diff -u -u -r1.22 bytecode_data.m
--- compiler/bytecode_data.m	27 Sep 2006 06:16:47 -0000	1.22
+++ compiler/bytecode_data.m	13 Feb 2007 03:29:06 -0000
@@ -72,13 +72,8 @@
 %-----------------------------------------------------------------------------%
 
 output_string(Val, !IO) :-
-    % XXX this assumes strings contain 8-bit characters
-    %     Using write_bytes here is wrong; the output will depend
-    %     on the Mercury implementation's representation of chars,
-    %     so it may be different for different Mercury implementations.
-    %     In particular, it will do the wrong thing for Mercury
-    %     implementations which represent characters in Unicode.
-    io.write_bytes(Val, !IO),
+    string_to_byte_list(Val, List),
+    list.foldl(io.write_byte, List, !IO),
     io.write_byte(0, !IO).
 
 string_to_byte_list(Val, List) :-
Index: library/io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.372
diff -u -u -r1.372 io.m
--- library/io.m	13 Feb 2007 01:58:53 -0000	1.372
+++ library/io.m	13 Feb 2007 03:03:34 -0000
@@ -946,16 +946,20 @@
 
     % Writes several bytes to the current binary output stream.
     % The bytes are taken from a string.
+    % A string is poor choice of data structure to hold raw bytes.
+    % Use io.write_bitmap/3 instead.
     %
 :- pred io.write_bytes(string::in, io::di, io::uo) is det.
-    % A string is not a suitable structure to hold a sequence of bytes.
+:- pragma obsolete(io.write_bytes/3).
 
     % Writes several bytes to the specified binary output stream.
     % The bytes are taken from a string.
+    % A string is poor choice of data structure to hold raw bytes.
+    % Use io.write_bitmap/4 instead.
     %
 :- pred io.write_bytes(io.binary_output_stream::in, string::in,
     io::di, io::uo) is det.
-    % A string is not a suitable structure to hold a sequence of bytes.
+:- pragma obsolete(io.write_bytes/4).
 
     % Write a bitmap to the current binary output stream.
     % The bitmap must not contain a partial final byte.
@@ -1458,7 +1462,6 @@
 :- instance stream.stream(io.binary_output_stream, io).
 :- instance stream.output(io.binary_output_stream, io).
 :- instance stream.writer(io.binary_output_stream, int, io).
-:- instance stream.writer(io.binary_output_stream, string, io).
 :- instance stream.seekable(io.binary_output_stream, io).
 
 :- instance stream.stream(io.binary_input_stream,  io).
@@ -9160,12 +9163,6 @@
     pred(put/4) is io.write_byte
 ].
 
-:- instance stream.writer(io.binary_output_stream, string, io)
-    where
-[
-    pred(put/4) is io.write_bytes
-].
-
 :- instance stream.seekable(io.binary_output_stream, io)
     where
 [

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list