diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2018-05-29 09:07:24 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-05-29 09:07:24 +0200 |
commit | 688c54d8f158ff977161a234374b1cd321ba95f3 (patch) | |
tree | e55216bb241ac468dc79cd761fbe9b1e93a37934 /tests/compilerapi | |
parent | a5701d6b71853e683f4d655b6b5ea4a13bec993b (diff) | |
download | Nim-688c54d8f158ff977161a234374b1cd321ba95f3.tar.gz |
compiler API: final cleanups; improve security by diabling 'gorge' and friends
Diffstat (limited to 'tests/compilerapi')
-rw-r--r-- | tests/compilerapi/myscript.nim | 2 | ||||
-rw-r--r-- | tests/compilerapi/tcompilerapi.nim | 13 |
2 files changed, 14 insertions, 1 deletions
diff --git a/tests/compilerapi/myscript.nim b/tests/compilerapi/myscript.nim index 083385b6f..539b07de1 100644 --- a/tests/compilerapi/myscript.nim +++ b/tests/compilerapi/myscript.nim @@ -5,3 +5,5 @@ echo "top level statements are executed!" proc hostProgramRunsThis*(a, b: float): float = result = addFloats(a, b, 1.0) + +let hostProgramWantsThis* = "my secret" diff --git a/tests/compilerapi/tcompilerapi.nim b/tests/compilerapi/tcompilerapi.nim index 00c9bc523..90d343264 100644 --- a/tests/compilerapi/tcompilerapi.nim +++ b/tests/compilerapi/tcompilerapi.nim @@ -1,6 +1,7 @@ discard """ output: '''top level statements are executed! 2.0 +my secret ''' """ @@ -16,7 +17,7 @@ proc main() = quit "cannot find Nim's standard library" var intr = createInterpreter("myscript.nim", [std, getAppDir()]) - intr.declareRoutine("*", "exposed", "addFloats", proc (a: VmArgs) = + intr.implementRoutine("*", "exposed", "addFloats", proc (a: VmArgs) = setResult(a, getFloat(a, 0) + getFloat(a, 1) + getFloat(a, 2)) ) @@ -31,6 +32,16 @@ proc main() = echo res.floatVal else: echo "bug!" + + let foreignValue = selectUniqueSymbol(intr, "hostProgramWantsThis") + if foreignValue == nil: + quit "script does not export a global of the name: hostProgramWantsThis" + let val = intr.getGlobalValue(foreignValue) + if val.kind in {nkStrLit..nkTripleStrLit}: + echo val.strVal + else: + echo "bug!" + destroyInterpreter(intr) main() \ No newline at end of file |