mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-15 22:03:26 +00:00
Fix a bug in petdr's recent changes to string__format that
Estimated hours taken: 1.5 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().
This commit is contained in:
@@ -1269,7 +1269,9 @@ make_format(Flags, MaybeWidth, MaybePrec, LengthMod, Spec) = String :-
|
||||
:- 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 @@ make_format(Flags, MaybeWidth, MaybePrec, LengthMod, Spec) = String :-
|
||||
:- 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 @@ make_format(Flags, MaybeWidth, MaybePrec, LengthMod, Spec) = String :-
|
||||
:- 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();
|
||||
}").
|
||||
|
||||
%-----------------------------------------------------------------------------%
|
||||
|
||||
@@ -74,9 +74,10 @@ MR_make_string(MR_Code *proclabel, const char *fmt, ...) {
|
||||
|
||||
p = fixed;
|
||||
#endif
|
||||
|
||||
restore_transient_hp();
|
||||
MR_allocate_aligned_string_msg(result, strlen(p),
|
||||
proclabel);
|
||||
save_transient_hp();
|
||||
strcpy(result, p);
|
||||
|
||||
#ifdef HAVE_VSNPRINTF
|
||||
|
||||
@@ -174,10 +174,10 @@ int MR_hash_string(MR_Word);
|
||||
** 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, ...);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user