Skip to content

Commit

Permalink
fixes #9222 (#9224)
Browse files Browse the repository at this point in the history
  • Loading branch information
cooldome authored and Araq committed Oct 9, 2018
1 parent 73e6b22 commit 036c52f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compiler/cgen.nim
Expand Up @@ -567,7 +567,12 @@ proc loadDynamicLib(m: BModule, lib: PLib) =
var p = newProc(nil, m)
p.options = p.options - {optStackTrace, optEndb}
var dest: TLoc
initLocExpr(p, lib.path, dest)
initLoc(dest, locTemp, lib.path, OnStack)
dest.r = getTempName(m)
appcg(m, m.s[cfsDynLibInit],"$1 $2;$n",
[getTypeDesc(m, lib.path.typ), rdLoc(dest)])
expr(p, lib.path, dest)

add(m.s[cfsVars], p.s(cpsLocals))
add(m.s[cfsDynLibInit], p.s(cpsInit))
add(m.s[cfsDynLibInit], p.s(cpsStmts))
Expand Down
10 changes: 10 additions & 0 deletions tests/cpp/amodule.nim
@@ -0,0 +1,10 @@
import os

proc findlib: string =
let path = getEnv("MYLIB_DOES_NOT_EXIST_PATH")
if path.len > 0 and dirExists(path):
path / "alib_does_not_matter.dll"
else:
"alib_does_not_matter.dll"

proc imported_func*(a: cint): cstring {.importc, dynlib: findlib().}
16 changes: 16 additions & 0 deletions tests/cpp/t8241.nim
Expand Up @@ -5,3 +5,19 @@ discard """

proc foo(): cstring {.importcpp: "", dynlib: "".}
echo foo()


## bug #9222
import os
import amodule
proc findlib2: string =
let path = getEnv("MYLIB2_DOES_NOT_EXIST_PATH")
if path.len > 0 and dirExists(path):
path / "alib_does_not_matter.dll"
else:
"alib_does_not_matter.dll"

proc imported_func2*(a: cint): cstring {.importc, dynlib: findlib2().}

echo imported_func(1)
echo imported_func2(1)

0 comments on commit 036c52f

Please sign in to comment.