[m-rev.] diff: remove destructive update modes of string__set_char

Simon Taylor stayl at cs.mu.OZ.AU
Fri Oct 26 17:44:31 AEST 2001


On 26-Oct-2001, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> On 26-Oct-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> > On 26-Oct-2001, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> > > 
> > > Estimated hours taken: 0.25
> > > Branches: main, release
> > > 
> > > NEWS:
> > > library/string.m:
> > > 	Remove the buggy destructive update modes of string__set_char,
> > > 	string__set_char_det and string__unsafe_set_char (they cause
> > > 	crashes when applied to constant strings).
> > 
> > These modes are not buggy.  The bug is storing strings or other data
> > structures in read-only memory when they are passed to procedures with
> > mode `di'.
> 
> I'll change the NEWS file entry. The chances of this being fixed
> properly any time soon aren't good.

I'll also restore the modes, but leave them commented out.
This diff is relative to the revision before my previous change.

Simon.


Index: string.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.162
diff -u -u -r1.162 string.m
--- string.m	9 Oct 2001 04:03:14 -0000	1.162
+++ string.m	26 Oct 2001 07:40:10 -0000
@@ -252,7 +252,9 @@
 
 :- pred string__set_char(char, int, string, string).
 :- mode string__set_char(in, in, in, out) is semidet.
-:- mode string__set_char(in, in, di, uo) is semidet.
+% XXX This mode is disabled because the compiler puts constant
+% strings into static data even when they might be updated.
+%:- mode string__set_char(in, in, di, uo) is semidet.
 %	string__set_char(Char, Index, String0, String):
 %	`String' is `String0' with the (`Index' + 1)-th character
 %	set to `Char'.
@@ -262,7 +264,9 @@
 :- func string__set_char_det(char, int, string) = string.
 :- pred string__set_char_det(char, int, string, string).
 :- mode string__set_char_det(in, in, in, out) is det.
-:- mode string__set_char_det(in, in, di, uo) is det.
+% XXX This mode is disabled because the compiler puts constant
+% strings into static data even when they might be updated.
+%:- mode string__set_char_det(in, in, di, uo) is det.
 %	string__set_char_det(Char, Index, String0, String):
 %	`String' is `String0' with the (`Index' + 1)-th character
 %	set to `Char'.
@@ -271,10 +275,15 @@
 
 :- func string__unsafe_set_char(char, int, string) = string.
 :- mode string__unsafe_set_char(in, in, in) = out is det.
-:- mode string__unsafe_set_char(in, in, di) = uo is det.
+% XXX This mode is disabled because the compiler puts constant
+% strings into static data even when they might be updated.
+%:- mode string__unsafe_set_char(in, in, di) = uo is det.
+
 :- pred string__unsafe_set_char(char, int, string, string).
 :- mode string__unsafe_set_char(in, in, in, out) is det.
-:- mode string__unsafe_set_char(in, in, di, uo) is det.
+% XXX This mode is disabled because the compiler puts constant
+% strings into static data even when they might be updated.
+%:- mode string__unsafe_set_char(in, in, di, uo) is det.
 %	string__unsafe_set_char(Char, Index, String0, String):
 %	`String' is `String0' with the (`Index' + 1)-th character
 %	set to `Char'.
@@ -1901,6 +1910,7 @@
 :- pred string__set_char(char, int, string, string).
 :- mode string__set_char(in, in, di, uo) is semidet.
 */
+/*
 :- pragma foreign_proc("C",
 	string__set_char(Ch::in, Index::in, Str0::di, Str::uo),
 		[will_not_call_mercury, thread_safe], "
@@ -1925,6 +1935,7 @@
 		SUCCESS_INDICATOR = TRUE;
 	}
 ").
+*/
 
 /*-----------------------------------------------------------------------*/
 
@@ -1952,6 +1963,7 @@
 :- pred string__unsafe_set_char(char, int, string, string).
 :- mode string__unsafe_set_char(in, in, di, uo) is det.
 */
+/*
 :- pragma foreign_proc("C",
 	string__unsafe_set_char(Ch::in, Index::in, Str0::di, Str::uo),
 		[will_not_call_mercury, thread_safe], "
@@ -1965,6 +1977,7 @@
 		System::Convert::ToString(Ch), 
 		Str0->Substring(Index + 1));
 ").
+*/
 
 /*-----------------------------------------------------------------------*/
 
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list