Skip to content

Commit

Permalink
Add wrapper function to capture pointers
Browse files Browse the repository at this point in the history
This resolves memory leaks in generated examples.

The function is to be deleted once we finish our API
transition.
  • Loading branch information
lisitsyn committed Jun 16, 2016
1 parent 5ea6f14 commit dea533a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions examples/meta/generator/targets/cpp.json
Expand Up @@ -10,9 +10,9 @@
"Comment": "//$comment\n",
"Init": {
"Construct": "auto $name = some<C$type>($arguments)",
"Copy": "auto $name = $expr"
"Copy": "auto $name = wrap($expr)"
},
"Assign": "$name = $expr",
"Assign": "$name = wrap($expr)",
"Type": {
"RealFeatures": "DenseFeatures<float64_t>",
"StringCharFeatures": "CStringFeatures<char>",
Expand Down
18 changes: 18 additions & 0 deletions src/shogun/base/some.h
Expand Up @@ -124,6 +124,24 @@ namespace shogun
return Some<T>::from_raw(ptr);
}

template <class T>
inline T wrap(const T& value)
{
return value;
}

template <class T>
inline Some<T> wrap(T* ptr)
{
return Some<T>::from_raw(ptr);
}

template <class T>
inline Some<T> wrap(const Some<T>& other)
{
return other;
}

};

#endif /* HAVE_CXX11 */
Expand Down

0 comments on commit dea533a

Please sign in to comment.