fix(construction): removed std::optional arguments for weakRateInterpolator

Passing weak rate interpolator as an std::optional was resulting in use-after-free bugs due to std::optional making a copy of WeakRateInterpolator. This resulted in segfaults. Since we have the new construction semantics with flags this is no longer needed so the optional argument has been removed in favor of a simple const &
This commit is contained in:
2025-11-03 09:43:36 -05:00
parent 70ebe151ba
commit 0adc340767
3 changed files with 12 additions and 12 deletions

View File

@@ -105,7 +105,7 @@ namespace gridfire {
*/ */
reaction::ReactionSet build_nuclear_network( reaction::ReactionSet build_nuclear_network(
const fourdst::composition::Composition &composition, const fourdst::composition::Composition &composition,
const std::optional<rates::weak::WeakRateInterpolator> &weakInterpolator, const rates::weak::WeakRateInterpolator &weakInterpolator,
BuildDepthType maxLayers = NetworkBuildDepth::Full, BuildDepthType maxLayers = NetworkBuildDepth::Full,
NetworkConstructionFlags ReactionTypes = NetworkConstructionFlags::DEFAULT NetworkConstructionFlags ReactionTypes = NetworkConstructionFlags::DEFAULT
); );

View File

@@ -40,16 +40,15 @@ namespace {
gridfire::reaction::ReactionSet register_weak_reactions( gridfire::reaction::ReactionSet register_weak_reactions(
const std::optional<gridfire::rates::weak::WeakRateInterpolator> &weakInterpolator, const gridfire::rates::weak::WeakRateInterpolator &weakInterpolator,
const gridfire::NetworkConstructionFlags reactionTypes const gridfire::NetworkConstructionFlags reactionTypes
) { ) {
gridfire::reaction::ReactionSet weak_reaction_pool; gridfire::reaction::ReactionSet weak_reaction_pool;
assert(weakInterpolator.has_value());
if (!has_flag(reactionTypes, gridfire::NetworkConstructionFlags::WEAK)) { if (!has_flag(reactionTypes, gridfire::NetworkConstructionFlags::WEAK)) {
return weak_reaction_pool; return weak_reaction_pool;
} }
for (const auto& parent_species: weakInterpolator->available_isotopes()) { for (const auto& parent_species: weakInterpolator.available_isotopes()) {
std::expected<fourdst::atomic::Species, fourdst::atomic::SpeciesErrorType> upProduct = fourdst::atomic::az_to_species( std::expected<fourdst::atomic::Species, fourdst::atomic::SpeciesErrorType> upProduct = fourdst::atomic::az_to_species(
parent_species.a(), parent_species.a(),
parent_species.z() + 1 parent_species.z() + 1
@@ -64,7 +63,7 @@ namespace {
std::make_unique<gridfire::rates::weak::WeakReaction>( std::make_unique<gridfire::rates::weak::WeakReaction>(
parent_species, parent_species,
gridfire::rates::weak::WeakReactionType::BETA_PLUS_DECAY, gridfire::rates::weak::WeakReactionType::BETA_PLUS_DECAY,
*weakInterpolator weakInterpolator
) )
); );
} }
@@ -73,7 +72,7 @@ namespace {
std::make_unique<gridfire::rates::weak::WeakReaction>( std::make_unique<gridfire::rates::weak::WeakReaction>(
parent_species, parent_species,
gridfire::rates::weak::WeakReactionType::ELECTRON_CAPTURE, gridfire::rates::weak::WeakReactionType::ELECTRON_CAPTURE,
*weakInterpolator weakInterpolator
) )
); );
} }
@@ -84,7 +83,7 @@ namespace {
std::make_unique<gridfire::rates::weak::WeakReaction>( std::make_unique<gridfire::rates::weak::WeakReaction>(
parent_species, parent_species,
gridfire::rates::weak::WeakReactionType::BETA_MINUS_DECAY, gridfire::rates::weak::WeakReactionType::BETA_MINUS_DECAY,
*weakInterpolator weakInterpolator
) )
); );
} }
@@ -93,7 +92,7 @@ namespace {
std::make_unique<gridfire::rates::weak::WeakReaction>( std::make_unique<gridfire::rates::weak::WeakReaction>(
parent_species, parent_species,
gridfire::rates::weak::WeakReactionType::POSITRON_CAPTURE, gridfire::rates::weak::WeakReactionType::POSITRON_CAPTURE,
*weakInterpolator weakInterpolator
) )
); );
} }
@@ -127,7 +126,7 @@ namespace gridfire {
ReactionSet build_nuclear_network( ReactionSet build_nuclear_network(
const Composition& composition, const Composition& composition,
const std::optional<rates::weak::WeakRateInterpolator> &weakInterpolator, const rates::weak::WeakRateInterpolator &weakInterpolator,
BuildDepthType maxLayers, BuildDepthType maxLayers,
NetworkConstructionFlags ReactionTypes NetworkConstructionFlags ReactionTypes
) { ) {

View File

@@ -55,9 +55,10 @@ namespace gridfire {
} }
} }
if (primeReactions.empty()) { if (primeReactions.empty()) {
LOG_ERROR(m_logger, "No priming reactions found for species '{}'.", primingSpecies.name()); LOG_INFO(m_logger, "No priming reactions found for species '{}', returning empty peName set.", primingSpecies.name());
m_logger->flush_log(); return std::vector<std::string>{};
throw std::runtime_error("No priming reactions found for species '" + std::string(primingSpecies.name()) + "'."); // m_logger->flush_log();
// throw std::runtime_error("No priming reactions found for species '" + std::string(primingSpecies.name()) + "'.");
} }
std::vector<std::string> primingReactionSet(primeReactions.begin(), primeReactions.end()); std::vector<std::string> primingReactionSet(primeReactions.begin(), primeReactions.end());
// LOG_INFO(m_logger, "Constructed priming reaction set with {} reactions for species '{}'.", primingReactionSet.size(), primingSpecies.name()); // LOG_INFO(m_logger, "Constructed priming reaction set with {} reactions for species '{}'.", primingReactionSet.size(), primingSpecies.name());