summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorflywind <xzsflywind@gmail.com>2021-03-15 17:21:25 +0800
committerGitHub <noreply@github.com>2021-03-15 10:21:25 +0100
commit84cf3e5fcabd89e251c14452e248ba050b74a7df (patch)
treeffc868473a8f2e2c6d1b3cb9b228ad330607fa8f
parent7937abab4439ef2cd317d4ef70551327f55711e1 (diff)
downloadNim-84cf3e5fcabd89e251c14452e248ba050b74a7df.tar.gz
Revert "make system random work in VM" (#17378)
-rw-r--r--compiler/vmops.nim33
-rw-r--r--tests/stdlib/tsysrand.nim2
2 files changed, 0 insertions, 35 deletions
diff --git a/compiler/vmops.nim b/compiler/vmops.nim
index 807d4d9b5..5748b41b3 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 2d00dafe0..c6d43a8fb 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()