Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler doesn't insert call to =destroy when compiled to staticLib #20945

Closed
IgorDeepakM opened this issue Nov 27, 2022 · 0 comments · Fixed by #23357
Closed

Compiler doesn't insert call to =destroy when compiled to staticLib #20945

IgorDeepakM opened this issue Nov 27, 2022 · 0 comments · Fixed by #23357
Assignees

Comments

@IgorDeepakM
Copy link
Contributor

IgorDeepakM commented Nov 27, 2022

Description

When compiling with the paramter --app:staticLib --noMain:off, the compiler doesn't insert calls to =destroy for objects both ref objects and objects at the end of main.

type
    TObj = object
        text: string
        val: int
        
proc `=destroy`*(x: var TObj ) =
    echo("TObj destroyed, x.text ", x.text)

when isMainModule:
    var obj = (ref TObj )(text: "tt1", val: 1)
    var obj2 = TObj (text: "tt2", val: 2)

    echo(obj.text)
    echo(obj2.text)

    # Neither obj or obj2 are destroyed at the end of main when target is staticLib

This can be observed by inspecting the compiled C source in the function

N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void)

When compiling to an executable, then the compiler inserts the destructors but not for static library.

Nim Version

Nim Compiler Version 1.7.3 [Windows: amd64]
Compiled at 2022-11-27
Copyright (c) 2006-2022 by Andreas Rumpf

git hash: 5a848a0
active boot switches: -d:release

Current Output

No response

Expected Output

No response

Possible Solution

No response

Additional Information

No response

@IgorDeepakM IgorDeepakM changed the title Nim doesn't insert call to =destroy when compiled to staticLib Compiler doesn't insert call to =destroy when compiled to staticLib Nov 27, 2022
@ringabout ringabout self-assigned this Feb 27, 2024
ringabout added a commit that referenced this issue Feb 27, 2024
Araq pushed a commit that referenced this issue Mar 4, 2024
…atic/dynlib libraries (#23357)

fixes #20945
fixes #18262

todo
- [ ] perhaps export with lib prefix when the option is enabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants