Skip to content

Commit

Permalink
C++ API: (Equation) made create_equation_deep_copy() to call clec_dee…
Browse files Browse the repository at this point in the history
…p_copy() instead of using memcpy for the clec attribute of the struct EQ
  • Loading branch information
alixdamman committed Oct 25, 2023
1 parent 3621f65 commit 86311c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cpp_api/objects/equation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
EQ* create_equation_deep_copy(EQ* original_equation)
{
EQ* copy_eq = (EQ*) SW_nalloc(sizeof(EQ));
// NOTE : we do not use memcpy() because memcpy() actually makes
// a shallow copy of a struct instead of a deep copy
copy_eq->clec = clec_deep_copy(original_equation->clec);
copy_eq->lec = copy_char_array(original_equation->lec);
copy_eq->clec = (CLEC*) SW_nalloc(sizeof(CLEC));
memcpy(copy_eq->clec, original_equation->clec, sizeof(CLEC));
copy_eq->solved = original_equation->solved;
copy_eq->method = original_equation->method;
// NOTE : we can use memcpy() on SAMPLE because SAMPLE does
// not contain attributes which are pointers
memcpy(&copy_eq->smpl, &original_equation->smpl, sizeof(SAMPLE));
copy_eq->cmt = copy_char_array(original_equation->cmt);
copy_eq->blk = copy_char_array(original_equation->blk);
Expand Down
2 changes: 2 additions & 0 deletions cpp_api/objects/equation.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "utils/utils.h"
#include "time/period.h"
#include "time/sample.h"
#include "lec/lec.h"

#include <boost/functional/hash.hpp>
#include <boost/algorithm/string.hpp>

Expand Down

0 comments on commit 86311c3

Please sign in to comment.