From 84cf3e5fcabd89e251c14452e248ba050b74a7df Mon Sep 17 00:00:00 2001 From: flywind Date: Mon, 15 Mar 2021 17:21:25 +0800 Subject: [PATCH] Revert "make system random work in VM" (#17378) --- compiler/vmops.nim | 33 --------------------------------- tests/stdlib/tsysrand.nim | 2 -- 2 files changed, 35 deletions(-) diff --git a/compiler/vmops.nim b/compiler/vmops.nim index 807d4d9b53..5748b41b33 100644 --- a/compiler/vmops.nim +++ b/compiler/vmops.nim @@ -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 diff --git a/tests/stdlib/tsysrand.nim b/tests/stdlib/tsysrand.nim index 2d00dafe0b..c6d43a8fbc 100644 --- a/tests/stdlib/tsysrand.nim +++ b/tests/stdlib/tsysrand.nim @@ -31,6 +31,4 @@ template main() = doAssert urandom(113).len == 113 doAssert urandom(1234) != urandom(1234) # unlikely to fail in practice - -static: main() main()