diff options
author | David Winter <david.winter@analog.com> | 2021-08-09 13:24:24 +0200 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2021-09-03 16:12:30 -0400 |
commit | 956f332e410331fde426e1485589d905cdf80fb1 (patch) | |
tree | c1004bbc58e99afe1ed2daf404d11020626e2980 /gr-qtgui/python/qtgui/bindings/edit_box_msg_python.cc | |
parent | 4d0f2900e887b87e547a1af5874b5d502b5fc71e (diff) |
qtgui: Replace pyqwidget() with qwidget()
Previously, two versions of the `qtwidget` functions existed,
`qwidget()` and `pyqwidget()`, with the only difference being that
`qwidget()` returned a pointer to the `QWidget` object managed by the
corresponding block, while `pyqwidget()` returned that same pointer, but as
an integer (Or `PyLong` in this case).
While `qwidget()` is used by C++ code accessing the widgets,
`pyqwidget()` is only used for the python interface. This makes these
two methods redundant, thus this commit entirely removes `pyqwidget()`,
and modifies the `qwidget()` python wrapper to behave like
`pyqwidget()`. Note that we can be fairly confident that this change
will not effect potential users of `qwidget()`, because any invocation
on the objects previously returned by `qwidget()` would cause a
segmentation fault.
This commit also fixes a memory leak:
Internally, the `pyqwidget()` functions were returning a PyLong `PyObject *`,
which was then upwrapped in a pybind trampoline without decrementing
the reference count of that python object.
Signed-off-by: David Winter <david.winter@analog.com>
Diffstat (limited to 'gr-qtgui/python/qtgui/bindings/edit_box_msg_python.cc')
-rw-r--r-- | gr-qtgui/python/qtgui/bindings/edit_box_msg_python.cc | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/gr-qtgui/python/qtgui/bindings/edit_box_msg_python.cc b/gr-qtgui/python/qtgui/bindings/edit_box_msg_python.cc index e65d81721b..b4bc1ee4ca 100644 --- a/gr-qtgui/python/qtgui/bindings/edit_box_msg_python.cc +++ b/gr-qtgui/python/qtgui/bindings/edit_box_msg_python.cc @@ -55,23 +55,11 @@ void bind_edit_box_msg(py::module& m) .def("exec_", &edit_box_msg::exec_, D(edit_box_msg, exec_)) - // .def("pyqwidget",&edit_box_msg::pyqwidget, - // D(edit_box_msg,pyqwidget) - // ) - // For the sip conversion to python to work, the widget object - // needs to be explicitly converted to long long. + .def( - "pyqwidget", - [](std::shared_ptr<edit_box_msg> p) { - return PyLong_AsLongLong(p->pyqwidget()); + "qwidget", + [](edit_box_msg& self) { + return reinterpret_cast<uintptr_t>(self.qwidget()); }, - D(edit_box_msg, pyqwidget)) - - - .def("qwidget", &edit_box_msg::qwidget, D(edit_box_msg, qwidget)) - - - .def("pyqwidget", &edit_box_msg::pyqwidget, D(edit_box_msg, pyqwidget)) - - ; + D(edit_box_msg, qwidget)); } |