parent
ab72d68ec8
commit
7c90e22ddd
2 changed files with 47 additions and 13 deletions
|
|
@ -1103,9 +1103,8 @@ proc genMainProc(m: BModule) =
|
||||||
"}$N$N" &
|
"}$N$N" &
|
||||||
"void PreMain(void) {$N" &
|
"void PreMain(void) {$N" &
|
||||||
"\tvoid (*volatile inner)(void);$N" &
|
"\tvoid (*volatile inner)(void);$N" &
|
||||||
"$1" &
|
|
||||||
"\tinner = PreMainInner;$N" &
|
"\tinner = PreMainInner;$N" &
|
||||||
"$4$5" &
|
"$1" &
|
||||||
"\t(*inner)();$N" &
|
"\t(*inner)();$N" &
|
||||||
"}$N$N"
|
"}$N$N"
|
||||||
|
|
||||||
|
|
@ -1222,12 +1221,7 @@ proc genMainProc(m: BModule) =
|
||||||
else: ropecg(m, "\t#initStackBottomWith((void *)&inner);$N")
|
else: ropecg(m, "\t#initStackBottomWith((void *)&inner);$N")
|
||||||
inc(m.labels)
|
inc(m.labels)
|
||||||
appcg(m, m.s[cfsProcs], PreMainBody, [
|
appcg(m, m.s[cfsProcs], PreMainBody, [
|
||||||
m.g.mainDatInit, m.g.breakpoints, m.g.otherModsInit,
|
m.g.mainDatInit, m.g.breakpoints, m.g.otherModsInit])
|
||||||
if emulatedThreadVars(m.config) and m.config.target.targetOS != osStandalone:
|
|
||||||
ropecg(m, "\t#initThreadVarsEmulation();$N")
|
|
||||||
else:
|
|
||||||
"".rope,
|
|
||||||
initStackBottomCall])
|
|
||||||
|
|
||||||
appcg(m, m.s[cfsProcs], nimMain,
|
appcg(m, m.s[cfsProcs], nimMain,
|
||||||
[m.g.mainModInit, initStackBottomCall, rope(m.labels)])
|
[m.g.mainModInit, initStackBottomCall, rope(m.labels)])
|
||||||
|
|
@ -1256,21 +1250,32 @@ proc getInitName(m: PSym): Rope =
|
||||||
|
|
||||||
proc getDatInitName(m: PSym): Rope = getSomeInitName(m, "DatInit000")
|
proc getDatInitName(m: PSym): Rope = getSomeInitName(m, "DatInit000")
|
||||||
|
|
||||||
|
|
||||||
proc registerModuleToMain(g: BModuleList; m: BModule) =
|
proc registerModuleToMain(g: BModuleList; m: BModule) =
|
||||||
|
if m.s[cfsDatInitProc].len > 0:
|
||||||
|
let datInit = m.module.getDatInitName
|
||||||
|
addf(g.mainModProcs, "N_LIB_PRIVATE N_NIMCALL(void, $1)(void);$N", [datInit])
|
||||||
|
addf(g.mainDatInit, "\t$1();$N", [datInit])
|
||||||
|
|
||||||
|
# Initialization of TLS and GC should be done in between
|
||||||
|
# systemDatInit and systemInit calls if any
|
||||||
|
if sfSystemModule in m.module.flags:
|
||||||
|
if emulatedThreadVars(m.config) and m.config.target.targetOS != osStandalone:
|
||||||
|
add(g.mainDatInit, ropecg(m, "\t#initThreadVarsEmulation();$N"))
|
||||||
|
if m.config.target.targetOS != osStandalone and m.config.selectedGC != gcNone:
|
||||||
|
add(g.mainDatInit, ropecg(m, "\t#initStackBottomWith((void *)&inner);$N"))
|
||||||
|
|
||||||
if m.s[cfsInitProc].len > 0:
|
if m.s[cfsInitProc].len > 0:
|
||||||
let init = m.module.getInitName
|
let init = m.module.getInitName
|
||||||
addf(g.mainModProcs, "N_LIB_PRIVATE N_NIMCALL(void, $1)(void);$N", [init])
|
addf(g.mainModProcs, "N_LIB_PRIVATE N_NIMCALL(void, $1)(void);$N", [init])
|
||||||
let initCall = "\t$1();$N" % [init]
|
let initCall = "\t$1();$N" % [init]
|
||||||
if sfMainModule in m.module.flags:
|
if sfMainModule in m.module.flags:
|
||||||
add(g.mainModInit, initCall)
|
add(g.mainModInit, initCall)
|
||||||
|
elif sfSystemModule in m.module.flags:
|
||||||
|
add(g.mainDatInit, initCall) # systemInit must called right after systemDatInit if any
|
||||||
else:
|
else:
|
||||||
add(g.otherModsInit, initCall)
|
add(g.otherModsInit, initCall)
|
||||||
|
|
||||||
if m.s[cfsDatInitProc].len > 0:
|
|
||||||
let datInit = m.module.getDatInitName
|
|
||||||
addf(g.mainModProcs, "N_LIB_PRIVATE N_NIMCALL(void, $1)(void);$N", [datInit])
|
|
||||||
addf(g.mainDatInit, "\t$1();$N", [datInit])
|
|
||||||
|
|
||||||
proc genDatInitCode(m: BModule) =
|
proc genDatInitCode(m: BModule) =
|
||||||
## this function is called in cgenWriteModules after all modules are closed,
|
## this function is called in cgenWriteModules after all modules are closed,
|
||||||
## it means raising dependency on the symbols is too late as it will not propogate
|
## it means raising dependency on the symbols is too late as it will not propogate
|
||||||
|
|
|
||||||
29
tests/cpp/t10148.nim
Normal file
29
tests/cpp/t10148.nim
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
discard """
|
||||||
|
output: '''Expected successful exit'''
|
||||||
|
joinable: false
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
proc another_proc: string =
|
||||||
|
## trigger many GC allocations
|
||||||
|
var x = @[""]
|
||||||
|
for i in 0..100:
|
||||||
|
x.add $i
|
||||||
|
result = "not_existent_path"
|
||||||
|
|
||||||
|
proc findlib2: string =
|
||||||
|
let path = getEnv("MYLIB2_DOES_NOT_EXIST_PATH")
|
||||||
|
let another_path = another_proc()
|
||||||
|
GC_fullCollect()
|
||||||
|
|
||||||
|
if path.len > 0 and dirExists(path):
|
||||||
|
path / "alib_does_not_matter.dll"
|
||||||
|
elif fileExists(another_path):
|
||||||
|
another_path
|
||||||
|
else:
|
||||||
|
quit("Expected successful exit", 0)
|
||||||
|
|
||||||
|
proc imported_func*(a: cint): cstring {.importc, dynlib: findlib2().}
|
||||||
|
|
||||||
|
echo imported_func(0)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue