Skip to content

Fix static initialization order for UserFormatRegister map#202

Merged
mhochsteger merged 1 commit intoNGSolve:masterfrom
StefanBruens:fix_static_initialization
Mar 27, 2026
Merged

Fix static initialization order for UserFormatRegister map#202
mhochsteger merged 1 commit intoNGSolve:masterfrom
StefanBruens:fix_static_initialization

Conversation

@StefanBruens
Copy link
Copy Markdown
Contributor

A std::map is in an invalid state when just zero-initialized, and needs to be initialized by its constructor. As this initilization may be done after the first call to Register, a crash will typically happen.

To fix this wrap all accesses to the map with a Meyers Singleton. Also remove the extra Array - most accesses are using the key, and the few format list iterations all sort the result afterwards anyway.

Fixes #201.

A std::map is in an invalid state when just zero-initialized, and needs
to be initialized by its constructor. As this initilization may be done
after the first call to Register, a crash will typically happen.

To fix this wrap all accesses to the map with a Meyers Singleton. Also
remove the extra Array - most accesses are using the key, and the few
format list iterations all sort the result afterwards anyway.

Fixes NGSolve#201.
@StefanBruens
Copy link
Copy Markdown
Contributor Author

There is also PR #125, which addresses the same problem elsewhere. Unfortunately, that has not been updated.

@mhochsteger
Copy link
Copy Markdown
Member

Merged, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using dlopen on libnglib.so crashes in std::map

2 participants