Skip to content

Commit 87326ec

Browse files
committed
fix(pyconfig): c_defined reverted;getrandom never declared
1 parent e0f0749 commit 87326ec

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

src/pylib/Lib/os_impl/randoms.nim

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,6 @@ when have_getrandom_syscall:
6868
import ../signal_impl/c_api
6969
import ../../pyerrors/oserr
7070
71-
let SYS_getrandom {.importc, header: "<sys/syscall.h>".}: clong
72-
const syscallHeader = """#include <unistd.h>
73-
#include <sys/syscall.h>"""
74-
proc syscall(n: clong): clong {.
75-
importc: "syscall", varargs, header: syscallHeader.}
76-
77-
7871
proc getrandom*(size: int, flags = 0): seq[uint8] =
7972
8073
if size < 0:

src/pylib/pyconfig/bootstrap_hash.nim

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,32 @@
22

33
when defined(linux):
44
import ./util
5-
c_defined have_getrandom, "HAVE_GETRANDOM", ["<sys/random.h>"]
6-
c_defined have_getrandom_syscall, "HAVE_GETRANDOM_SYSCALL", ["<sys/random.h>"]
5+
AC_LINK_IFELSE have_getrandom, false:
6+
proc getrandom(buf: pointer, buflen: uint, flags: cuint): int{.importc,
7+
header: "<sys/random.h>".}
8+
var buffer: char
9+
let buflen = uint 1
10+
let flags = cuint 0
11+
# ignore the result, Python checks for ENOSYS at runtime
12+
discard getrandom(addr buffer, buflen, flags)
13+
14+
template syscalChkAndExport(def){.dirty.} =
15+
AC_LINK_IFELSE have_getrandom_syscall, false:
16+
def
17+
var buffer: char
18+
let buflen = uint 1
19+
let flags{.importc: "GRND_NONBLOCK", header: "<sys/random.h>".}: cint
20+
# ignore the result, Python checks for ENOSYS at runtime
21+
discard syscall(SYS_getrandom, addr buffer, buflen, flags)
22+
when have_getrandom_syscall:
23+
def
24+
25+
syscalChkAndExport:
26+
let SYS_getrandom* {.importc, header: "<sys/syscall.h>".}: clong
27+
const syscallHeader = """#include <unistd.h>
28+
#include <sys/syscall.h>"""
29+
proc syscall*(n: clong): clong {.
30+
importc: "syscall", varargs, header: syscallHeader.}
731
else:
832
const
933
have_getrandom* = false

src/pylib/pyconfig/util.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ template c_defined*(variable; c_macro: string; headers: openArray = []) =
162162
"""
163163
exit(
164164
#if defined(""" & c_macro & """)
165-
1
166-
#else
167165
0
166+
#else
167+
1
168168
#endif
169169
);
170170
""".}

0 commit comments

Comments
 (0)