From e1d2bef5ff3f98eb7760b29847ce2ced878659cb Mon Sep 17 00:00:00 2001 From: Phil Miller Date: Wed, 8 Nov 2023 13:58:25 -0800 Subject: [PATCH] Convert bmi_model members from shared_ptr to unique_ptr This avoids giving the impression that there should ever actually be shared ownership - a model instance is always exclusively held by the single adapter instance that created it. Leave the C++ adapter alone for now due to the more complicated lifetime logic that it implements. --- include/bmi/Bmi_C_Adapter.hpp | 4 ++-- include/bmi/Bmi_Fortran_Adapter.hpp | 4 ++-- include/bmi/Bmi_Py_Adapter.hpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/bmi/Bmi_C_Adapter.hpp b/include/bmi/Bmi_C_Adapter.hpp index d736cf5329..5dcabbf0ad 100755 --- a/include/bmi/Bmi_C_Adapter.hpp +++ b/include/bmi/Bmi_C_Adapter.hpp @@ -562,7 +562,7 @@ namespace models { inline void construct_and_init_backing_model_for_type() { if (model_initialized) return; - bmi_model = std::make_shared(C_Bmi()); + bmi_model = std::make_unique(C_Bmi()); execModuleRegistration(); int init_result = bmi_model->initialize(bmi_model.get(), bmi_init_config.c_str()); if (init_result != BMI_SUCCESS) { @@ -643,7 +643,7 @@ namespace models { friend class ::Bmi_C_Adapter_Test; /** Pointer to backing BMI model instance. */ - std::shared_ptr bmi_model = nullptr; + std::unique_ptr bmi_model = nullptr; }; diff --git a/include/bmi/Bmi_Fortran_Adapter.hpp b/include/bmi/Bmi_Fortran_Adapter.hpp index 00bef70f7f..c21a77c13d 100644 --- a/include/bmi/Bmi_Fortran_Adapter.hpp +++ b/include/bmi/Bmi_Fortran_Adapter.hpp @@ -498,7 +498,7 @@ namespace models { inline void construct_and_init_backing_model_for_fortran() { if (model_initialized) return; - bmi_model = std::make_shared(Bmi_Fortran_Handle_Wrapper()); + bmi_model = std::make_unique(Bmi_Fortran_Handle_Wrapper()); dynamic_library_load(); execModuleRegistration(); int init_result = initialize(&bmi_model->handle, bmi_init_config.c_str()); @@ -805,7 +805,7 @@ namespace models { private: /** Pointer to backing BMI model instance. */ - std::shared_ptr bmi_model = nullptr; + std::unique_ptr bmi_model = nullptr; }; } diff --git a/include/bmi/Bmi_Py_Adapter.hpp b/include/bmi/Bmi_Py_Adapter.hpp index 377e8a35d2..773013745d 100644 --- a/include/bmi/Bmi_Py_Adapter.hpp +++ b/include/bmi/Bmi_Py_Adapter.hpp @@ -662,7 +662,7 @@ namespace models { // This is a class object for the BMI module Python class py::object bmi_py_class = utils::ngenPy::InterpreterUtil::getPyModule(moduleComponents); // This is the actual backing model object - bmi_model = std::make_shared(bmi_py_class()); + bmi_model = std::make_unique(bmi_py_class()); bmi_model->attr("initialize")(bmi_init_config); } catch (std::runtime_error& e){ //Catch specific exception types so the type/message don't get erased @@ -773,7 +773,7 @@ namespace models { protected: /** Pointer to backing BMI model instance. */ - std::shared_ptr bmi_model = nullptr; + std::unique_ptr bmi_model = nullptr; };