Skip to content

Commit

Permalink
Convert bmi_model members from shared_ptr to unique_ptr
Browse files Browse the repository at this point in the history
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.

Leave the Python adapted alone because the unit tests do silly things
with reaching in and grabbing the underlying object.
  • Loading branch information
PhilMiller committed Nov 13, 2023
1 parent f2c3074 commit 7687cfc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions include/bmi/Bmi_C_Adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>(C_Bmi());
bmi_model = std::make_unique<C_Bmi>(C_Bmi());
execModuleRegistration();
int init_result = bmi_model->initialize(bmi_model.get(), bmi_init_config.c_str());
if (init_result != BMI_SUCCESS) {
Expand Down Expand Up @@ -643,7 +643,7 @@ namespace models {
friend class ::Bmi_C_Adapter_Test;

/** Pointer to backing BMI model instance. */
std::shared_ptr<C_Bmi> bmi_model = nullptr;
std::unique_ptr<C_Bmi> bmi_model = nullptr;

};

Expand Down
4 changes: 2 additions & 2 deletions include/bmi/Bmi_Fortran_Adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_Fortran_Handle_Wrapper());
bmi_model = std::make_unique<Bmi_Fortran_Handle_Wrapper>(Bmi_Fortran_Handle_Wrapper());
dynamic_library_load();
execModuleRegistration();
int init_result = initialize(&bmi_model->handle, bmi_init_config.c_str());
Expand Down Expand Up @@ -805,7 +805,7 @@ namespace models {

private:
/** Pointer to backing BMI model instance. */
std::shared_ptr<Bmi_Fortran_Handle_Wrapper> bmi_model = nullptr;
std::unique_ptr<Bmi_Fortran_Handle_Wrapper> bmi_model = nullptr;

};
}
Expand Down

0 comments on commit 7687cfc

Please sign in to comment.