Skip to content

Commit

Permalink
prefix NimDestroyGlobals with nimMainPrefix (#24493)
Browse files Browse the repository at this point in the history
ref #24471

---------

Co-authored-by: metagn <metagngn@gmail.com>
  • Loading branch information
ringabout and metagn authored Dec 3, 2024
1 parent 33dc236 commit 3bee04d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions compiler/cgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2497,12 +2497,13 @@ proc updateCachedModule(m: BModule) =
addFileToCompile(m.config, cf)

proc generateLibraryDestroyGlobals(graph: ModuleGraph; m: BModule; body: PNode; isDynlib: bool): PSym =
let procname = getIdent(graph.cache, "NimDestroyGlobals")
let prefixedName = m.config.nimMainPrefix & "NimDestroyGlobals"
let procname = getIdent(graph.cache, prefixedName)
result = newSym(skProc, procname, m.idgen, m.module.owner, m.module.info)
result.typ = newProcType(m.module.info, m.idgen, m.module.owner)
result.typ.callConv = ccCDecl
incl result.flags, sfExportc
result.loc.snippet = "NimDestroyGlobals"
result.loc.snippet = prefixedName
if isDynlib:
incl(result.loc.flags, lfExportLib)

Expand Down
2 changes: 1 addition & 1 deletion doc/backends.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ which will likely make your program crash at runtime.
The name `NimMain` can be influenced via the `--nimMainPrefix:prefix` switch.
Use `--nimMainPrefix:MyLib` and the function to call is named `MyLibNimMain`.

When compiling to static or dynamic libraries, they don't call destructors of global variables as normal Nim programs would do. A C API `NimDestroyGlobals` is provided to call these global destructors.
When compiling to static or dynamic libraries, they don't call destructors of global variables as normal Nim programs would do. A C API `NimDestroyGlobals` is provided to call these global destructors. It is influenced by the `--nimMainPrefix:prefix` switch, too.


### Nim invocation example from C
Expand Down

0 comments on commit 3bee04d

Please sign in to comment.