Skip to content

Commit

Permalink
Switched to new from malloc
Browse files Browse the repository at this point in the history
  • Loading branch information
jrenaud90 committed Nov 30, 2024
1 parent ca03905 commit 21939ec
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push_tests_ubun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Manual Test
run: |
cd Tests/E_CySolver_Tests/
python -c "from test_a_cysolve_ivp import test_cysolve_ivp; test_cysolve_ivp(True, False, False, False, False, 1, 0.0, 10_000, True)"
python -c "from test_a_cysolve_ivp import test_cysolve_ivp; print('Import Success!'); test_cysolve_ivp(True, False, False, False, False, 1, 0.0, 10_000, True); print('DONE!')"
cd ../..
- name: Run pytest
Expand Down
32 changes: 24 additions & 8 deletions CyRK/cy/cysolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,22 @@ CySolverBase::CySolverBase(
// Allocate memory for the size of args.
// Store void pointer to it.
printf("Pre Malloc\n");
this->args_ptr = malloc(size_of_args);
this->args_char_ptr = new char[size_of_args];

// Copy over contents of arg
printf("Pre Copy Over\n");
std::memcpy(this->args_ptr, args_ptr, size_of_args);
printf("Post\n");
if (this->args_char_ptr)
{
this->args_built = true;
this->args_ptr = (void*)this->args_char_ptr;
// Copy over contents of arg
printf("Pre Copy Over\n");
std::memcpy(this->args_ptr, args_ptr, size_of_args);
printf("Post\n");
}
else
{
// TODO: Memory error?
this->storage_sptr->error_code = -870;
}
}

// Check for errors
Expand Down Expand Up @@ -163,6 +173,7 @@ CySolverBase::CySolverBase(
// Destructors
CySolverBase::~CySolverBase()
{
printf("CySolver Deconstructor called.\n");
if (this->deconstruct_python)
{
// Decrease reference count on the cython extension class instance
Expand All @@ -176,11 +187,16 @@ CySolverBase::~CySolverBase()
}

// Release args data
if (args_built)
if (this->args_built)
{
if (this->args_ptr)
printf("Deconstructor:: args built.\n");
if (this->args_char_ptr)
{
free(this->args_ptr);
printf("Deconstructor:: args array not null.\n");
delete[] this->args_char_ptr;
printf("Deconstructor:: args deleted.\n");
this->args_char_ptr = nullptr;
this->args_ptr = nullptr;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions CyRK/cy/cysolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class CySolverBase {

// Differential equation information
void* args_ptr = nullptr;
char* args_char_ptr = nullptr;
bool args_built = false;
DiffeqFuncType diffeq_ptr = nullptr;

Expand Down

0 comments on commit 21939ec

Please sign in to comment.