Skip to content

Commit

Permalink
[SOfaPython/Binding] Add py::keep_alive in Binding_Node.cpp
Browse files Browse the repository at this point in the history
The object created from python needs special care to avoid being deleted by
the python garbage collection mecanisme.
In sofa-framework#74 and sofa-framework#75 the smart pointer mecanism was refactored. The refactoring
added a py::keep_alive, in addObject but didn't in other functions.

The PR fix this.
  • Loading branch information
damienmarchal committed Apr 11, 2022
1 parent 603d457 commit 5913407
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,12 @@ void moduleAddNode(py::module &m) {
p.def("add", &addKwargs, sofapython3::doc::sofa::core::Node::addKwargs);
p.def("addObject", &addObjectKwargs, sofapython3::doc::sofa::core::Node::addObjectKwargs);
p.def("addObject", &addObject, sofapython3::doc::sofa::core::Node::addObject, py::keep_alive<0, 2>());
p.def("createObject", &createObject, sofapython3::doc::sofa::core::Node::createObject);
p.def("createObject", &createObject, sofapython3::doc::sofa::core::Node::createObject, py::keep_alive<0, 2>());
p.def("hasObject", &hasObject, sofapython3::doc::sofa::core::Node::hasObject);
p.def("getObject", &getObject, sofapython3::doc::sofa::core::Node::getObject);
p.def("addChild", &addChildKwargs, sofapython3::doc::sofa::core::Node::addChildKwargs);
p.def("addChild", &addChild, sofapython3::doc::sofa::core::Node::addChild);
p.def("createChild", &createChild, sofapython3::doc::sofa::core::Node::createChild);
p.def("addChild", &addChild, sofapython3::doc::sofa::core::Node::addChild, py::keep_alive<0, 2>());
p.def("createChild", &createChild, sofapython3::doc::sofa::core::Node::createChild, py::keep_alive<0, 2>());
p.def("getChild", &getChild, sofapython3::doc::sofa::core::Node::getChild);
p.def("removeChild", &removeChild, sofapython3::doc::sofa::core::Node::removeChild);
p.def("removeChild", &removeChildByName, sofapython3::doc::sofa::core::Node::removeChildWithName);
Expand Down

0 comments on commit 5913407

Please sign in to comment.