Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace usage of rand_r with nrand48 #817

Merged
merged 4 commits into from
Jan 15, 2025
Merged

Replace usage of rand_r with nrand48 #817

merged 4 commits into from
Jan 15, 2025

Conversation

dnewhall
Copy link

@dnewhall dnewhall commented Jan 8, 2025

This replaces the call to rand_r with nrand48 and changes rand_seed to be an array instead of an unsigned int.

With rand_r being deprecated in POSIX 2024, the best replacement is nrand48, which stores its intermediate values as a 48-bit integer in an array of shorts instead of an unsigned int and returns a 32-bit value not constrained by RAND_MAX.

nrand48 has been in the POSIX spec. since 2004 and on the large UNIX systems since SVr4. Only things that could be affected are BSDs older than ~2004, but those are presumably old enough that we can ignore them.

bin/package test returned with all tests passing (particularly tests/subshell.sh and tests/variables.sh) and monkey testing shows getting and setting RANDOM works.

dnewhall and others added 2 commits January 7, 2025 23:31
It has been unused in the entire history of the ast-open-archive
repo as well as ours.

Also stop generating the public ast_mmap.h header, which is also
unused (it's a copy of FEATURE/mmap which is used internally by
libast).
@McDutchie
Copy link

Sorry for the delay in getting to this, I've been busy elsewhere. It looks good to me at first glance. Hopefully I'll find some time to take a closer look and test it in the next few days.

Bump version date
Update ANNOUNCE and NEWS

Undo whitespace fixes in function declarations (I'll save those for an
accumulated cleanups commit that will also be backported to 1.0)
@McDutchie McDutchie merged commit adfb9de into ksh93:dev Jan 15, 2025
McDutchie pushed a commit that referenced this pull request Jan 15, 2025
This replaces the call to rand_r with nrand48 and changes rand_seed
to be an array instead of an unsigned int.

With rand_r being deprecated in POSIX 2024, the best replacement is
nrand48, which stores its intermediate values as a 48-bit integer
in an array of shorts instead of an unsigned int and returns a
32-bit value not constrained by RAND_MAX.

nrand48 has been in the POSIX spec. since 2004 and on the large
UNIX systems since SVr4. Only things that could be affected are
BSDs older than ~2004, but those are presumably old enough that we
can ignore them.

bin/package test returned with all tests passing (particularly
tests/subshell.sh and tests/variables.sh) and monkey testing shows
getting and setting RANDOM works.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants