Skip to content

Commit ea3f422

Browse files
author
Vincent Palancher
committed
build: Upgrades version of pybind11 from v2.5.0 to v2.9.0.
The public constructor of `pybind11::module` is now deprecated. This patch replaces its only use by a call to `PYBIND11_EMBEDDED_MODULE` followed by a `pybind11::import(...)`. The constructor of a `pybind11::object` subclass from a `pybind11::object` from the wrong type now throws an exception. See pybind/pybind11#2349. We had one case of this happening where we tried constructing a `bytes` from a `None`. We now first construct an `object`, then test if it's `None` before trying to convert it to `bytes`. Change-Id: I4aa2a1b4a49d3024f203bdd5c6f9c4ee86bfc9c4 Reviewed-on: http://gerrit2.aldebaran.lan/1760 Reviewed-by: philippe.martin <[email protected]> Reviewed-by: jmonnon <[email protected]> Tested-by: vincent.palancher <[email protected]>
1 parent cf0ce2f commit ea3f422

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

cmake/set_dependencies.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ include_guard(GLOBAL)
4848
overridable_variable(BOOST_VERSION 1.77)
4949

5050
# Version of pybind11 to use.
51-
overridable_variable(PYBIND11_VERSION 2.5.0)
51+
overridable_variable(PYBIND11_VERSION 2.9.0)
5252

5353
# URL of the git repository from which to download pybind11. For more details, see CMake
5454
# `ExternalProject` module documentation of the `GIT_REPOSITORY` argument.

src/pyobject.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,11 @@ namespace detail
270270
boost::optional<ObjectUid> readObjectUid(const ::py::object& obj)
271271
{
272272
GILAcquire lock;
273-
const ::py::bytes qiObjectUid = ::py::getattr(obj, qiObjectUidAttributeName, ::py::none());
274-
if (!qiObjectUid.is_none())
275-
return deserializeObjectUid(static_cast<std::string>(qiObjectUid));
276-
return {};
273+
const auto qiObjectUidObj = ::py::getattr(obj, qiObjectUidAttributeName, ::py::none());
274+
if (qiObjectUidObj.is_none())
275+
return {};
276+
const auto qiObjectUid = qiObjectUidObj.cast<std::string>();
277+
return deserializeObjectUid(qiObjectUid);
277278
}
278279

279280
void writeObjectUid(const pybind11::object& obj, const ObjectUid& uid)

tests/test_qipython.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ qiLogCategory("TestQiPython");
1515

1616
namespace py = pybind11;
1717

18+
PYBIND11_EMBEDDED_MODULE(qi, m) {
19+
qi::py::exportAll(m);
20+
}
21+
1822
int main(int argc, char **argv)
1923
{
2024
::testing::InitGoogleTest(&argc, argv);
@@ -24,9 +28,8 @@ int main(int argc, char **argv)
2428
boost::optional<qi::Application> app;
2529
app.emplace(argc, argv);
2630

27-
py::module m("qi");
28-
qi::py::exportAll(m);
29-
py::globals()["qi"] = m;
31+
py::globals()["qi"] = py::module::import("qi");
32+
3033

3134
int ret = EXIT_FAILURE;
3235
{

0 commit comments

Comments
 (0)