Skip to content

Commit

Permalink
build: Upgrades version of pybind11 from v2.5.0 to v2.9.0.
Browse files Browse the repository at this point in the history
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 <philippe.martin@softbankrobotics.com>
Reviewed-by: jmonnon <jmonnon@aldebaran.com>
Tested-by: vincent.palancher <vincent.palancher@softbankrobotics.com>
  • Loading branch information
Vincent Palancher committed Mar 14, 2022
1 parent cf0ce2f commit ea3f422
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmake/set_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ include_guard(GLOBAL)
overridable_variable(BOOST_VERSION 1.77)

# Version of pybind11 to use.
overridable_variable(PYBIND11_VERSION 2.5.0)
overridable_variable(PYBIND11_VERSION 2.9.0)

# URL of the git repository from which to download pybind11. For more details, see CMake
# `ExternalProject` module documentation of the `GIT_REPOSITORY` argument.
Expand Down
9 changes: 5 additions & 4 deletions src/pyobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,11 @@ namespace detail
boost::optional<ObjectUid> readObjectUid(const ::py::object& obj)
{
GILAcquire lock;
const ::py::bytes qiObjectUid = ::py::getattr(obj, qiObjectUidAttributeName, ::py::none());
if (!qiObjectUid.is_none())
return deserializeObjectUid(static_cast<std::string>(qiObjectUid));
return {};
const auto qiObjectUidObj = ::py::getattr(obj, qiObjectUidAttributeName, ::py::none());
if (qiObjectUidObj.is_none())
return {};
const auto qiObjectUid = qiObjectUidObj.cast<std::string>();
return deserializeObjectUid(qiObjectUid);
}

void writeObjectUid(const pybind11::object& obj, const ObjectUid& uid)
Expand Down
9 changes: 6 additions & 3 deletions tests/test_qipython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ qiLogCategory("TestQiPython");

namespace py = pybind11;

PYBIND11_EMBEDDED_MODULE(qi, m) {
qi::py::exportAll(m);
}

int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
Expand All @@ -24,9 +28,8 @@ int main(int argc, char **argv)
boost::optional<qi::Application> app;
app.emplace(argc, argv);

py::module m("qi");
qi::py::exportAll(m);
py::globals()["qi"] = m;
py::globals()["qi"] = py::module::import("qi");


int ret = EXIT_FAILURE;
{
Expand Down

0 comments on commit ea3f422

Please sign in to comment.