Fix use of MR_strerror.

extras/posix/posix.strerror.m:
    Fix use of MR_strerror (it may return a pointer to a static string
    instead of modifying the provided buffer).

    Allocate string such that it will be attributed to the predicate
    when profiling memory retention.
This commit is contained in:
Peter Wang
2019-10-31 17:51:03 +11:00
parent da5fe0974e
commit 33da7c82b4

View File

@@ -1,4 +1,4 @@
%-------------------------------------_--------------------------------------%
%----------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%----------------------------------------------------------------------------%
% Copyright (C) 2019 The Mercury team.
@@ -30,12 +30,12 @@ strerror(Err, Msg, !IO) :-
:- pred strerror0(int::in, string::out, io::di, io::uo) is det.
:- pragma foreign_proc("C",
strerror0(Errno::in, Txt::out, _IO1::di, _IO2::uo),
strerror0(Errno::in, Msg::out, _IO0::di, _IO::uo),
[promise_pure, will_not_call_mercury, thread_safe, tabled_for_io],
"
char buf[200];
MR_strerror(Errno, buf, 200);
MR_make_aligned_string_copy(Txt, buf);
char buf[MR_STRERROR_BUF_SIZE];
MR_make_aligned_string_copy_msg(Msg, MR_strerror(Errno, buf, sizeof(buf)),
MR_ALLOC_ID);
").
%----------------------------------------------------------------------------%