mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 01:14:41 +00:00
Revert "make system random work in VM" (#17378)
This commit is contained in:
@@ -27,7 +27,6 @@ from std/md5 import getMD5
|
||||
from std/times import cpuTime
|
||||
from std/hashes import hash
|
||||
from std/osproc import nil
|
||||
from std/sysrand import urandom
|
||||
|
||||
from sighashes import symBodyDigest
|
||||
|
||||
@@ -317,35 +316,3 @@ proc registerAdditionalOps*(c: PCtx) =
|
||||
let fn = getNode(a, 0)
|
||||
setResult(a, (fn.typ != nil and tfNoSideEffect in fn.typ.flags) or
|
||||
(fn.kind == nkSym and fn.sym.kind == skFunc))
|
||||
|
||||
if vmopsDanger in c.config.features:
|
||||
proc urandomImpl(a: VmArgs) =
|
||||
doAssert a.numArgs == 1
|
||||
let kind = a.slots[a.rb+1].kind
|
||||
case kind
|
||||
of rkInt:
|
||||
setResult(a, urandom(a.getInt(0)).toLit)
|
||||
of rkNode, rkNodeAddr:
|
||||
let n =
|
||||
if kind == rkNode:
|
||||
a.getNode(0)
|
||||
else:
|
||||
a.getNodeAddr(0)
|
||||
|
||||
let length = n.len
|
||||
|
||||
## TODO refactor using vmconv.fromLit
|
||||
var res = newSeq[uint8](length)
|
||||
for i in 0 ..< length:
|
||||
res[i] = byte(n[i].intVal)
|
||||
|
||||
let isSuccess = urandom(res)
|
||||
|
||||
for i in 0 ..< length:
|
||||
n[i].intVal = BiggestInt(res[i])
|
||||
|
||||
setResult(a, isSuccess)
|
||||
else:
|
||||
doAssert false, $kind
|
||||
|
||||
registerCallback c, "stdlib.sysrand.urandom", urandomImpl
|
||||
|
||||
@@ -31,6 +31,4 @@ template main() =
|
||||
doAssert urandom(113).len == 113
|
||||
doAssert urandom(1234) != urandom(1234) # unlikely to fail in practice
|
||||
|
||||
|
||||
static: main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user