[m-dev.] diff: fix another transient reg bug

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Sep 15 02:24:14 AEDT 2000


Estimated hours taken: 1

Fix a bug in petdr's recent changes to string__format that
broke things in non-gc grades on sparcs.

runtime/mercury_string.c:
	In MR_make_string(), wrap calls to restore/save_transient_hp()
	around the call to MR_make_aligned_string_msg(), as mentioned
	in the documentation for MR_make_aligned_string_msg().

runtime/mercury_string.h:
	Document that calls to MR_make_string need to be wrapped inside
	calls to save/restore_transient_hp().

library/string.m:
	Wrap calls to MR_make_string inside calls to
	save/restore_transient_hp().

Workspace: /home/pgrad/fjh/ws/hg
Index: library/string.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.129
diff -u -d -r1.129 string.m
--- library/string.m	2000/09/14 08:20:34	1.129
+++ library/string.m	2000/09/14 15:01:43
@@ -1269,7 +1269,9 @@
 :- func format_float(string, float) = string.
 :- pragma c_code(format_float(FormatStr::in, Val::in) = (Str::out),
 		[will_not_call_mercury, thread_safe], "{
+	save_transient_hp();
 	Str = MR_make_string(MR_PROC_LABEL, FormatStr, (long double) Val);
+	restore_transient_hp();
 }").
 
 	% Create a string from a int using the format string.
@@ -1278,7 +1280,9 @@
 :- func format_int(string, int) = string.
 :- pragma c_code(format_int(FormatStr::in, Val::in) = (Str::out),
 		[will_not_call_mercury, thread_safe], "{
+	save_transient_hp();
 	Str = MR_make_string(MR_PROC_LABEL, FormatStr, Val);
+	restore_transient_hp();
 }").
 
 	% Create a string from a string using the format string.
@@ -1296,7 +1300,9 @@
 :- func format_char(string, char) = string.
 :- pragma c_code(format_char(FormatStr::in, Val::in) = (Str::out),
 		[will_not_call_mercury, thread_safe], "{
+	save_transient_hp();
 	Str = MR_make_string(MR_PROC_LABEL, FormatStr, Val);
+	restore_transient_hp();
 }").
 
 %-----------------------------------------------------------------------------%
Index: runtime/mercury_string.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_string.c,v
retrieving revision 1.8
diff -u -d -r1.8 mercury_string.c
--- runtime/mercury_string.c	2000/08/21 17:26:08	1.8
+++ runtime/mercury_string.c	2000/09/14 15:05:01
@@ -74,9 +74,10 @@
 
 	p = fixed;
 #endif
-	      
+	restore_transient_hp();      
 	MR_allocate_aligned_string_msg(result, strlen(p),
 			proclabel);
+	save_transient_hp();
 	strcpy(result, p);
 
 #ifdef HAVE_VSNPRINTF
Index: runtime/mercury_string.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_string.h,v
retrieving revision 1.17
diff -u -d -r1.17 mercury_string.h
--- runtime/mercury_string.h	2000/08/10 09:01:17	1.17
+++ runtime/mercury_string.h	2000/09/14 15:23:05
@@ -174,10 +174,10 @@
 ** allocation as coming from proclabel.  The MR_String returned has been
 ** allocated on the mercury heap using MR_allocate_aligned_string_msg.
 **
-** BEWARE: this may modify `hp', so it must only be called from
-** places where `hp' is valid.  If calling it from inside a C function,
-** rather than inside Mercury code, you may need to call
-** save/restore_transient_hp().
+** BEWARE: this may modify the saved copy of `hp', so it must only be
+** called from places where the saved copy of `hp' is valid.
+** You will generally need to call save/restore_transient_hp()
+** before/after calling this function.
 */
 MR_String MR_make_string(MR_Code *proclabel, const char *fmt, ...);
 

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list