[m-rev.] for review: add uint64 to string conversin for bases 8 and 16
Peter Wang
novalazy at gmail.com
Tue Dec 15 20:09:14 AEDT 2020
On Sun, 13 Dec 2020 19:37:01 +1100 Julien Fischer <jfischer at opturion.com> wrote:
>
> For review by anyone.
>
> --------------------
>
> Add uint64 to string conversion for bases 8 and 16.
>
> library/string.m:
> Add functions for converting uint64s to strings of base 8 or base 16
> digits. For most integer types we can cast to a uint and then use the
> uint versions of these operations but for 64-bit types we cannot since
> on some of our supported platforms uints are 32-bit.
>
> NEWS:
> Announce the additions.
>
> tests/hard_coded/Mmakefile:
> tests/hard_coded/uint64_string_conv.{m,exp}:
> Add a test of the new functions.
> diff --git a/library/string.m b/library/string.m
> index 35519ea..c02beab 100644
> --- a/library/string.m
> +++ b/library/string.m
> @@ -5857,6 +5871,86 @@ int_to_base_string_group_2(NegN, Base, Curr, GroupLength, Sep, Str) :-
>
> %---------------------%
>
> +:- pragma foreign_proc("C",
> + uint64_to_hex_string(U64::in) = (S::uo),
> + [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail],
> +"
> + char buffer[21]; // 20 for digits, 1 for nul.
Should be 17. Not that it matters particularly.
> + sprintf(buffer, ""%"" PRIx64, U64);
> + MR_allocate_aligned_string_msg(S, strlen(buffer), MR_ALLOC_ID);
> + strcpy(S, buffer);
> +").
> +%---------------------%
> +
> +:- pragma foreign_proc("C",
> + uint64_to_uc_hex_string(U64::in) = (S::uo),
> + [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail],
> +"
> + char buffer[21]; // 20 for digits, 1 for nul.
Ditto.
> + sprintf(buffer, ""%"" PRIX64, U64);
> + MR_allocate_aligned_string_msg(S, strlen(buffer), MR_ALLOC_ID);
> + strcpy(S, buffer);
> +").
> +
That looks fine, otherwise.
Peter
More information about the reviews
mailing list