1010# # This file implements the FFI part of the evaluator for Nim code.
1111
1212import ast, types, options, tables, dynlib, msgs, lineinfos
13+ from os import getAppFilename
1314import pkg/ libffi
1415
1516when defined (windows):
2728 gDllCache = initTable [string , LibHandle ]()
2829
2930when defined (windows):
30- var gExeHandle = loadLib (os. getAppFilename ())
31+ var gExeHandle = loadLib (getAppFilename ())
3132else :
3233 var gExeHandle = loadLib ()
3334
@@ -52,11 +53,13 @@ proc importcSymbol*(conf: ConfigRef, sym: PSym): PNode =
5253 # that contains the address instead:
5354 result = newNodeIT (nkPtrLit, sym.info, sym.typ)
5455 when true :
56+ var libPathMsg = " "
5557 let lib = sym.annex
5658 if lib != nil and lib.path.kind notin {nkStrLit.. nkTripleStrLit}:
5759 globalError (conf, sym.info, " dynlib needs to be a string lit" )
5860 var theAddr: pointer
5961 if (lib.isNil or lib.kind == libHeader) and not gExeHandle.isNil:
62+ libPathMsg = " current exe: " & getAppFilename () & " nor libc: " & libcDll
6063 # first try this exe itself:
6164 theAddr = gExeHandle.symAddr (name)
6265 # then try libc:
@@ -65,9 +68,11 @@ proc importcSymbol*(conf: ConfigRef, sym: PSym): PNode =
6568 theAddr = dllhandle.symAddr (name)
6669 elif not lib.isNil:
6770 let dll = if lib.kind == libHeader: libcDll else : lib.path.strVal
71+ libPathMsg = dll
6872 let dllhandle = getDll (conf, gDllCache, dll, sym.info)
6973 theAddr = dllhandle.symAddr (name)
70- if theAddr.isNil: globalError (conf, sym.info, " cannot import: " & name)
74+ if theAddr.isNil: globalError (conf, sym.info,
75+ " cannot import symbol: " & name & " from " & libPathMsg)
7176 result .intVal = cast [ByteAddress ](theAddr)
7277
7378proc mapType (conf: ConfigRef , t: ast.PType ): ptr libffi.Type =
@@ -320,7 +325,7 @@ proc unpack(conf: ConfigRef, x: pointer, typ: PType, n: PNode): PNode =
320325 else :
321326 reset n[]
322327 result = n
323- result .kind = nkNilLit
328+ result [] = TNode (kind: nkNilLit)
324329 result .typ = typ
325330
326331 template awi (kind, v: untyped ): untyped = aw (kind, v, intVal)
0 commit comments