From 6992e533988e2d49b010aeb3f2156c3f87ac821e Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 29 Jul 2020 15:48:14 -0500 Subject: [PATCH] Change declaration order of maps used for vectors If the destructor of an object tries to remove an entry from the map, there's no guarantee it exists if the map has already been destroyed (because it was declared after the vector of objects), resulting in a segfault. By declaring the map first, we avoid this. Currently an issue for Nuclide, but potentially other classes in the future. --- include/openmc/cell.h | 4 ++-- include/openmc/cross_sections.h | 6 +++--- include/openmc/lattice.h | 2 +- include/openmc/mesh.h | 2 +- include/openmc/nuclide.h | 2 +- include/openmc/plot.h | 2 +- include/openmc/surface.h | 2 +- include/openmc/tallies/derivative.h | 2 +- include/openmc/thermal.h | 2 +- src/cell.cpp | 4 ++-- src/cross_sections.cpp | 2 +- src/lattice.cpp | 2 +- src/mesh.cpp | 2 +- src/nuclide.cpp | 2 +- src/plot.cpp | 2 +- src/surface.cpp | 2 +- src/tallies/derivative.cpp | 2 +- src/thermal.cpp | 2 +- 18 files changed, 22 insertions(+), 22 deletions(-) diff --git a/include/openmc/cell.h b/include/openmc/cell.h index 5efbdd99ef..5cd819c26c 100644 --- a/include/openmc/cell.h +++ b/include/openmc/cell.h @@ -49,11 +49,11 @@ class Universe; class UniversePartitioner; namespace model { - extern std::vector> cells; extern std::unordered_map cell_map; + extern std::vector> cells; - extern std::vector> universes; extern std::unordered_map universe_map; + extern std::vector> universes; } // namespace model //============================================================================== diff --git a/include/openmc/cross_sections.h b/include/openmc/cross_sections.h index 3700bc217a..3afcf6b177 100644 --- a/include/openmc/cross_sections.h +++ b/include/openmc/cross_sections.h @@ -43,12 +43,12 @@ using LibraryKey = std::pair; namespace data { -//!< Data libraries -extern std::vector libraries; - //! Maps (type, name) to index in libraries extern std::map library_map; +//!< Data libraries +extern std::vector libraries; + } // namespace data //============================================================================== diff --git a/include/openmc/lattice.h b/include/openmc/lattice.h index bf18d92e4b..618859c80a 100644 --- a/include/openmc/lattice.h +++ b/include/openmc/lattice.h @@ -35,8 +35,8 @@ enum class LatticeType { class Lattice; namespace model { - extern std::vector> lattices; extern std::unordered_map lattice_map; + extern std::vector> lattices; } // namespace model //============================================================================== diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index a7160b0c89..eed36c7f84 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -32,8 +32,8 @@ class Mesh; namespace model { -extern std::vector> meshes; extern std::unordered_map mesh_map; +extern std::vector> meshes; } // namespace model diff --git a/include/openmc/nuclide.h b/include/openmc/nuclide.h index 3ea3a05a73..e3f7c3d749 100644 --- a/include/openmc/nuclide.h +++ b/include/openmc/nuclide.h @@ -138,8 +138,8 @@ extern double temperature_min; //! Maximum temperature in [K] that nuclide data is available at extern double temperature_max; -extern std::vector> nuclides; extern std::unordered_map nuclide_map; +extern std::vector> nuclides; } // namespace data diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 2468af1bfc..76fc462c35 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -27,8 +27,8 @@ class Plot; namespace model { -extern std::vector plots; //!< Plot instance container extern std::unordered_map plot_map; //!< map of plot ids to index +extern std::vector plots; //!< Plot instance container extern uint64_t plotter_prn_seeds[N_STREAMS]; // Random number seeds used for plotter extern int plotter_stream; // Stream index used by the plotter diff --git a/include/openmc/surface.h b/include/openmc/surface.h index 784ecbcece..cef5f4f880 100644 --- a/include/openmc/surface.h +++ b/include/openmc/surface.h @@ -24,8 +24,8 @@ namespace openmc { class Surface; namespace model { - extern std::vector> surfaces; extern std::unordered_map surface_map; + extern std::vector> surfaces; } // namespace model //============================================================================== diff --git a/include/openmc/tallies/derivative.h b/include/openmc/tallies/derivative.h index 421094c995..53e6925bac 100644 --- a/include/openmc/tallies/derivative.h +++ b/include/openmc/tallies/derivative.h @@ -70,8 +70,8 @@ void score_track_derivative(Particle& p, double distance); namespace openmc { namespace model { -extern std::vector tally_derivs; extern std::unordered_map tally_deriv_map; +extern std::vector tally_derivs; } // namespace model } // namespace openmc diff --git a/include/openmc/thermal.h b/include/openmc/thermal.h index ca2f785625..a18658fe3d 100644 --- a/include/openmc/thermal.h +++ b/include/openmc/thermal.h @@ -23,8 +23,8 @@ namespace openmc { class ThermalScattering; namespace data { -extern std::vector> thermal_scatt; extern std::unordered_map thermal_scatt_map; +extern std::vector> thermal_scatt; } //============================================================================== diff --git a/src/cell.cpp b/src/cell.cpp index fd488f3604..6c2bbf6bd7 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -32,11 +32,11 @@ namespace openmc { //============================================================================== namespace model { - std::vector> cells; std::unordered_map cell_map; + std::vector> cells; - std::vector> universes; std::unordered_map universe_map; + std::vector> universes; } // namespace model //============================================================================== diff --git a/src/cross_sections.cpp b/src/cross_sections.cpp index 6267dc5f9b..c06a11924a 100644 --- a/src/cross_sections.cpp +++ b/src/cross_sections.cpp @@ -34,8 +34,8 @@ namespace openmc { namespace data { -std::vector libraries; std::map library_map; +std::vector libraries; } diff --git a/src/lattice.cpp b/src/lattice.cpp index f0c3dc979f..18b40dff43 100644 --- a/src/lattice.cpp +++ b/src/lattice.cpp @@ -22,8 +22,8 @@ namespace openmc { //============================================================================== namespace model { - std::vector> lattices; std::unordered_map lattice_map; + std::vector> lattices; } //============================================================================== diff --git a/src/mesh.cpp b/src/mesh.cpp index b76be1ee8e..4954ca373e 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -35,8 +35,8 @@ namespace openmc { namespace model { -std::vector> meshes; std::unordered_map mesh_map; +std::vector> meshes; } // namespace model diff --git a/src/nuclide.cpp b/src/nuclide.cpp index 9b4500e634..59e5f6e8c0 100644 --- a/src/nuclide.cpp +++ b/src/nuclide.cpp @@ -32,8 +32,8 @@ std::array energy_min {0.0, 0.0}; std::array energy_max {INFTY, INFTY}; double temperature_min {0.0}; double temperature_max {INFTY}; -std::vector> nuclides; std::unordered_map nuclide_map; +std::vector> nuclides; } // namespace data //============================================================================== diff --git a/src/plot.cpp b/src/plot.cpp index bc94b3ad66..e2fe5abde4 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -80,8 +80,8 @@ void PropertyData::set_overlap(size_t y, size_t x) { namespace model { -std::vector plots; std::unordered_map plot_map; +std::vector plots; uint64_t plotter_seed = 1; } // namespace model diff --git a/src/surface.cpp b/src/surface.cpp index 8133a6a7e0..f5a7f9f5f3 100644 --- a/src/surface.cpp +++ b/src/surface.cpp @@ -23,8 +23,8 @@ namespace openmc { //============================================================================== namespace model { - std::vector> surfaces; std::unordered_map surface_map; + std::vector> surfaces; } // namespace model //============================================================================== diff --git a/src/tallies/derivative.cpp b/src/tallies/derivative.cpp index 6c802d8565..fecfa3f1c3 100644 --- a/src/tallies/derivative.cpp +++ b/src/tallies/derivative.cpp @@ -18,8 +18,8 @@ namespace openmc { //============================================================================== namespace model { - std::vector tally_derivs; std::unordered_map tally_deriv_map; + std::vector tally_derivs; } //============================================================================== diff --git a/src/thermal.cpp b/src/thermal.cpp index 352ca8dd30..f8e9b280be 100644 --- a/src/thermal.cpp +++ b/src/thermal.cpp @@ -27,8 +27,8 @@ namespace openmc { //============================================================================== namespace data { -std::vector> thermal_scatt; std::unordered_map thermal_scatt_map; +std::vector> thermal_scatt; } //==============================================================================