From 47afea8fcf8619989ef251b199454921ad16dfb0 Mon Sep 17 00:00:00 2001 From: Dan McGregor Date: Tue, 20 Feb 2024 13:32:01 -0600 Subject: [PATCH 1/5] support getrandom syscall on non-linux At least FreeBSD and NetBSD also implement getrandom using the same semantics as Linux >= 3.17. They don't define any of it it in linux/random.h, however. They do define all the necessary bits in sys/random.h. glibc >= 2.25 also defines it there as well as in linux/random.h. Simply use sys/random.h when checking for its existence. --- Modules/posixmodule.c | 3 +++ configure | 2 +- configure.ac | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index ef90ac5de09c65..2daf31866d7c60 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -148,6 +148,9 @@ # include #endif +#ifdef HAVE_SYS_RANDOM_H +# include // GRND_RANDOM on !Linux +#endif #ifdef HAVE_LINUX_RANDOM_H # include // GRND_RANDOM #endif diff --git a/configure b/configure index c826a1bb85667b..2d88c50d89edb9 100755 --- a/configure +++ b/configure @@ -30324,7 +30324,7 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext #include #include #include - #include + #include int main(void) { char buffer[1]; diff --git a/configure.ac b/configure.ac index 322d33dd0e3c99..6a994090ce21eb 100644 --- a/configure.ac +++ b/configure.ac @@ -7377,7 +7377,7 @@ AC_LINK_IFELSE( #include #include #include - #include + #include int main(void) { char buffer[1]; From f3af163693ca59cc14aa71e49198ad8d79af70dc Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 22 Jan 2026 15:54:58 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2026-01-22-15-54-57.gh-issue-144130.QaHIxE.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2026-01-22-15-54-57.gh-issue-144130.QaHIxE.rst diff --git a/Misc/NEWS.d/next/Library/2026-01-22-15-54-57.gh-issue-144130.QaHIxE.rst b/Misc/NEWS.d/next/Library/2026-01-22-15-54-57.gh-issue-144130.QaHIxE.rst new file mode 100644 index 00000000000000..34ad9506fd3b1a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-01-22-15-54-57.gh-issue-144130.QaHIxE.rst @@ -0,0 +1 @@ +Add support for FreeBSD's implementation of getrandom, so :func:`os.getrandom` works there too. From 7df1eb77afb77887b25e105835a2ba58883a40d6 Mon Sep 17 00:00:00 2001 From: Dan McGregor Date: Fri, 23 Jan 2026 10:00:53 -0600 Subject: [PATCH 3/5] posixmodule: Be more specific in include comment. --- Modules/posixmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 2daf31866d7c60..331cb52d139dda 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -149,7 +149,7 @@ #endif #ifdef HAVE_SYS_RANDOM_H -# include // GRND_RANDOM on !Linux +# include // GRND_RANDOM on FreeBSD and NetBSD #endif #ifdef HAVE_LINUX_RANDOM_H # include // GRND_RANDOM From a3d486856cd25f8f58b654f834b5432fd8a956c9 Mon Sep 17 00:00:00 2001 From: Dan McGregor Date: Fri, 23 Jan 2026 10:09:08 -0600 Subject: [PATCH 4/5] bootstrap_hash: add note about GRND_NONBLOCK on the BSDs --- Python/bootstrap_hash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/bootstrap_hash.c b/Python/bootstrap_hash.c index f0fb87c4a5d15e..76673bc8b3db26 100644 --- a/Python/bootstrap_hash.c +++ b/Python/bootstrap_hash.c @@ -20,7 +20,7 @@ # include // GRND_NONBLOCK # endif # if defined(HAVE_SYS_RANDOM_H) && (defined(HAVE_GETRANDOM) || defined(HAVE_GETENTROPY)) -# include // getrandom() +# include // getrandom(), GRND_NONBLOCK on FreeBSD and NetBSD # endif # if !defined(HAVE_GETRANDOM) && defined(HAVE_GETRANDOM_SYSCALL) # include // SYS_getrandom From b2033996e7a4ccd15564ea4fa35c86c34a636c4b Mon Sep 17 00:00:00 2001 From: Dan McGregor Date: Fri, 23 Jan 2026 10:43:41 -0600 Subject: [PATCH 5/5] Update Modules/posixmodule.c Co-authored-by: Victor Stinner --- Modules/posixmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 331cb52d139dda..4ac03ed9a406f7 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -149,7 +149,7 @@ #endif #ifdef HAVE_SYS_RANDOM_H -# include // GRND_RANDOM on FreeBSD and NetBSD +# include // GRND_RANDOM on FreeBSD and NetBSD #endif #ifdef HAVE_LINUX_RANDOM_H # include // GRND_RANDOM