Skip to content

Commit

Permalink
Added function to free stack only if variable is stack allocated
Browse files Browse the repository at this point in the history
  • Loading branch information
anutosh491 committed Mar 27, 2024
1 parent 450a027 commit f100b44
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions symengine/cwrapper.cpp
Expand Up @@ -131,6 +131,13 @@ void basic_free_stack(basic s)
s->m.~RCP();
}

void basic_free_stack_if_not_null(basic s)
{
if (s != nullptr) {
s->m.~RCP();
}
}

basic_struct *basic_new_heap()
{
return new CRCPBasic();
Expand Down
2 changes: 2 additions & 0 deletions symengine/cwrapper.h
Expand Up @@ -100,6 +100,8 @@ typedef basic_struct basic[1];
void basic_new_stack(basic s);
//! Free the C++ class wrapped by s.
void basic_free_stack(basic s);
//! Free the C++ class wrapped by s only if s is stack allocated.
void basic_free_stack_if_not_null(basic s);

// Use these two functions to allocate and free 'basic' on a heap. The pointer
// can then be used in all the other methods below (i.e. the methods that
Expand Down

0 comments on commit f100b44

Please sign in to comment.