Skip to content

Commit 098e390

Browse files
committed
proper fix for windows
1 parent 44e3920 commit 098e390

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

compiler/ast.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,8 @@ type
856856
loc*: TLoc
857857
annex*: PLib # additional fields (seldom used, so we use a
858858
# reference to another object to save space)
859+
cname*: string # resolved C declaration name in importc decl, eg:
860+
# {.importc: "foo".} => cname = foo
859861
constraint*: PNode # additional constraints like 'lit|result'; also
860862
# misused for the codegenDecl pragma in the hope
861863
# it won't cause problems

compiler/cgen.nim

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -697,14 +697,10 @@ proc loadDynamicLib(m: BModule, lib: PLib) =
697697
proc mangleDynLibProc(sym: PSym): Rope =
698698
# we have to build this as a single rope in order not to trip the
699699
# optimization in genInfixCall, see test tests/cpp/t8241.nim
700-
when not defined(windows):
701-
# mysterious bug that only affects windows, causing SIGSEGV in
700+
if sym.loc.r != nil:
701+
# `return rope($sym.loc.r)` would cause on windows a SIGSEGV in
702702
# stdlib_winleanDatInit000 () at generated_not_to_break_here
703-
if sym.loc.r != nil:
704-
if sym.loc.r.data.len > 0:
705-
return sym.loc.r
706-
else:
707-
return rope($sym.loc.r)
703+
if sym.cname.len == 0: sym.cname = $sym.loc.r
708704
if sfCompilerProc in sym.flags:
709705
# NOTE: sym.loc.r is the external name!
710706
result = rope(sym.name.s)

compiler/evalffi.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ const
4747
nkPtrLit = nkIntLit # hopefully we can get rid of this hack soon
4848
4949
proc importcSymbol*(conf: ConfigRef, sym: PSym): PNode =
50-
let name = $sym.loc.r
50+
var name = $sym.cname
51+
if name.len == 0: name = $sym.loc.r
5152
# the AST does not support untyped pointers directly, so we use an nkIntLit
5253
# that contains the address instead:
5354
result = newNodeIT(nkPtrLit, sym.info, sym.typ)

compiler/vm.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ proc putIntoReg(dest: var TFullReg; n: PNode) =
281281
if dest.kind == rkNode:
282282
dest.node = n
283283
return
284-
elif n.typ.kind == tyPtr:
284+
elif n.typ != nil and n.typ.kind == tyPtr:
285285
dest = TFullReg(kind: rkNode, node: n)
286286
return
287287

0 commit comments

Comments
 (0)