diff --git a/pyEXP/BasisWrappers.cc b/pyEXP/BasisWrappers.cc index 7ac47d89a..e4ac73093 100644 --- a/pyEXP/BasisWrappers.cc +++ b/pyEXP/BasisWrappers.cc @@ -1561,7 +1561,29 @@ void BasisFactoryClasses(py::module &m) Returns ------- None - )", py::arg("coefs")); + )", py::arg("coefs")) + .def("get_shared_ptr_capsule", [](const std::shared_ptr &self) -> py::capsule { + return py::capsule( + new std::shared_ptr(self), + "BiorthBasis_shared_ptr", + [](void *v) { delete static_cast *>(v); } + ); + }, + R"( + Get a capsule containing a shared pointer to the BiorthBasis instance. + + Returns + ------- + capsule: PyCapsule + A PyCapsule containing a shared pointer to the BiorthBasis instance with + the name "BiorthBasis_shared_ptr". + + Notes + ----- + This can be used to pass the BiorthBasis instance to non-Pybind11 C extensions + in a lifetime-safe manner. + )" + ); py::class_, PyCylindrical, BasisClasses::BiorthBasis>(m, "Cylindrical") .def(py::init(), diff --git a/pyEXP/CoefWrappers.cc b/pyEXP/CoefWrappers.cc index d4f273d2c..81ccdc266 100644 --- a/pyEXP/CoefWrappers.cc +++ b/pyEXP/CoefWrappers.cc @@ -1347,7 +1347,29 @@ void CoefficientClasses(py::module &m) { -------- addcoef : add coefficient structures to an existing coefficieint container )", - py::arg("coef"), py::arg("name")=""); + py::arg("coef"), py::arg("name")="") + .def("get_shared_ptr_capsule", [](const std::shared_ptr &self) -> py::capsule { + return py::capsule( + new std::shared_ptr(self), + "Coefs_shared_ptr", + [](void *v) { delete static_cast *>(v); } + ); + }, + R"( + Get a capsule containing a shared pointer to the Coefs instance. + + Returns + ------- + capsule: PyCapsule + A PyCapsule containing a shared pointer to the Coefs instance with + the name "Coefs_shared_ptr". + + Notes + ----- + This can be used to pass the Coefs instance to non-Pybind11 C extensions + in a lifetime-safe manner. + )" + ); py::class_, PySphCoefs, CoefClasses::Coefs> (m, "SphCoefs", "Container for spherical coefficients")