From 4da7d5a946df34ae3461c524600e80ea8ab15f41 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Thu, 19 Nov 2020 17:52:52 +0100 Subject: python: multi_usrp: Let get_tree() return a raw pointer This changes the Python version of MultiUSRP.get_tree() such that it returns a raw pointer to the tree instead of returning the sptr. This fixes an issue where calling get_tree() will reliably cause a segfault during garbage collection, at least on some USRPs. The downside of this approach is that storing the return value from get_tree() can produce a dangling pointer when the underlying object is destroyed. It's still better than segfaults, and the recommended way to use get_tree() anyway is not to store the return value (unless it's in a local scope), but tack on property tree methods to get_tree() itself. Examples: >>> usrp = uhd.usrp.MultiUSRP('...') >>> usrp.get_tree().exists('/path/to/prop') # This is fine This change has no noticable API changes. --- host/lib/usrp/multi_usrp_python.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'host/lib') diff --git a/host/lib/usrp/multi_usrp_python.cpp b/host/lib/usrp/multi_usrp_python.cpp index 34bb96338..b26671760 100644 --- a/host/lib/usrp/multi_usrp_python.cpp +++ b/host/lib/usrp/multi_usrp_python.cpp @@ -29,7 +29,7 @@ void export_multi_usrp(py::module& m) .def(py::init(&multi_usrp::make)) // clang-format off - .def("get_tree" , &multi_usrp::get_tree) + .def("get_tree" , [](multi_usrp& self){ return self.get_tree().get(); }, py::return_value_policy::reference_internal) // General USRP methods .def("get_rx_freq" , &multi_usrp::get_rx_freq, py::arg("chan") = 0) -- cgit v1.2.3