Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for FreeBSD's implementation of getrandom, so :func:`os.getrandom` works there too.
5 changes: 4 additions & 1 deletion Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,11 @@
#ifdef HAVE_LINUX_RANDOM_H
# include <linux/random.h> // GRND_RANDOM
#endif
#if defined(HAVE_SYS_RANDOM_H) && (defined(HAVE_GETRANDOM) || defined(HAVE_GETENTROPY))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code below does not use getentropy(), so it should be removed.

# include <sys/random.h> // getrandom(), GRND_NONBLOCK on FreeBSD and NetBSD
#endif
#ifdef HAVE_GETRANDOM_SYSCALL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#ifdef HAVE_GETRANDOM_SYSCALL
#if !defined(HAVE_GETRANDOM) && defined(HAVE_GETRANDOM_SYSCALL)

Also, in the code below which checks HAVE_GETRANDOM_SYSCALL, we should also check HAVE_GETRANDOM and use getrandom() if available.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to leave the PR as it is (#ifdef HAVE_GETRANDOM_SYSCALL). I will write a following PR to reuse Python/bootstrap_hash.c code in Modules/posixmodule.c. The bootstrap_hash.c code is more complete, it handles properly Solaris for example.

# include <sys/syscall.h> // syscall()
# include <sys/syscall.h> // SYS_getrandom
#endif

#ifdef HAVE_POSIX_SPAWN
Expand Down
2 changes: 1 addition & 1 deletion Python/bootstrap_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# include <linux/random.h> // GRND_NONBLOCK
# endif
# if defined(HAVE_SYS_RANDOM_H) && (defined(HAVE_GETRANDOM) || defined(HAVE_GETENTROPY))
# include <sys/random.h> // getrandom()
# include <sys/random.h> // getrandom(), GRND_NONBLOCK on FreeBSD and NetBSD
# endif
# if !defined(HAVE_GETRANDOM) && defined(HAVE_GETRANDOM_SYSCALL)
# include <sys/syscall.h> // SYS_getrandom
Expand Down
2 changes: 1 addition & 1 deletion configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7439,7 +7439,7 @@ AC_LINK_IFELSE(
#include <stddef.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <linux/random.h>
#include <sys/random.h>

int main(void) {
char buffer[1];
Expand Down
Loading