diff --git a/api/python/CMakeLists.txt b/api/python/CMakeLists.txt index 9d0ecf1e..f803b715 100644 --- a/api/python/CMakeLists.txt +++ b/api/python/CMakeLists.txt @@ -23,8 +23,8 @@ if (LIEF_EXTERNAL_NANOBIND) find_package(Python REQUIRED COMPONENTS Interpreter Development.Module) find_package(nanobind REQUIRED) else() - set(NANOBIND_VERSION 2.11.0.r10.g5f0a380) - set(NANOBIND_SHA256 SHA256=4494b2b580b400e98e4d847b6a9e2a3aeb99581ac7545f6efaa52605335fa806) + set(NANOBIND_VERSION 2.11.0.r17.g94ad040) + set(NANOBIND_SHA256 SHA256=0018b31936af0d1b6ac0bee3d86b6d0b6b022e3a2d0399893c3b116ed7c404ad) set(NANOBIND_URL "${THIRD_PARTY_DIRECTORY}/nanobind-${NANOBIND_VERSION}.zip" CACHE STRING "URL to the Nanobind") FetchContent_Declare(nanobind diff --git a/api/python/src/nanobind/extra/memoryview.hpp b/api/python/src/nanobind/extra/memoryview.hpp index 9805a88d..b660d757 100644 --- a/api/python/src/nanobind/extra/memoryview.hpp +++ b/api/python/src/nanobind/extra/memoryview.hpp @@ -5,10 +5,12 @@ NAMESPACE_BEGIN(NB_NAMESPACE) -/* The current version of nanobind does not memoryview helper compared to - * pybind11. So here is a minimal API needed by LIEF +namespace extra { +/* the memoryview wrapper class has been introduced in nanobind with the commit + * 7206bc2 but it misses important helpers like data(). * * Tracked by the discussion: https://github.com/wjakob/nanobind/discussions/233 + * PR: https://github.com/wjakob/nanobind/pull/1291 */ class memoryview : public object { using ssize_t = Py_ssize_t; @@ -76,6 +78,8 @@ public: } }; +} // namespace extra + NAMESPACE_END(NB_NAMESPACE) #endif diff --git a/api/python/src/nanobind/utils.hpp b/api/python/src/nanobind/utils.hpp index 3e72fc4c..72f06a03 100644 --- a/api/python/src/nanobind/utils.hpp +++ b/api/python/src/nanobind/utils.hpp @@ -22,12 +22,12 @@ inline nanobind::bytes to_bytes(const std::string& str) { return nanobind::bytes(str.data(), str.size()); } -inline nanobind::memoryview to_memoryview(LIEF::span sp) { - return nanobind::memoryview::from_memory(sp.data(), sp.size()); +inline nanobind::extra::memoryview to_memoryview(LIEF::span sp) { + return nanobind::extra::memoryview::from_memory(sp.data(), sp.size()); } -inline nanobind::memoryview to_memoryview(const std::vector& vec) { - return nanobind::memoryview::from_memory(vec.data(), vec.size()); +inline nanobind::extra::memoryview to_memoryview(const std::vector& vec) { + return nanobind::extra::memoryview::from_memory(vec.data(), vec.size()); } inline std::vector to_vector(nanobind::bytes bytes) { diff --git a/api/python/src/pyIOStream.cpp b/api/python/src/pyIOStream.cpp index 4da418e4..e5bd46d7 100644 --- a/api/python/src/pyIOStream.cpp +++ b/api/python/src/pyIOStream.cpp @@ -55,7 +55,7 @@ result PyIOStream::from_python(nb::object object) { seek(0, PY_SEEK_SET); if (nb::hasattr(object, "readinto")) { - auto view = nb::memoryview::from_memory(data.data(), size); + auto view = nb::extra::memoryview::from_memory(data.data(), size); object.attr("readinto")(view); } else if (nb::hasattr(object, "read")) { diff --git a/api/python/src/pyLIEF.cpp b/api/python/src/pyLIEF.cpp index 2010aeda..9dabd446 100644 --- a/api/python/src/pyLIEF.cpp +++ b/api/python/src/pyLIEF.cpp @@ -280,7 +280,7 @@ void init(nb::module_& m) { "mangled"_a ); - m.def("dump", [] (nb::memoryview view, const std::string& title, + m.def("dump", [] (nb::extra::memoryview view, const std::string& title, const std::string& prefix, size_t limit) { return LIEF::dump(view.data(), view.size(), title, prefix, limit); diff --git a/third-party/nanobind-2.11.0.r10.g5f0a380.zip b/third-party/nanobind-2.11.0.r17.g94ad040.zip similarity index 84% rename from third-party/nanobind-2.11.0.r10.g5f0a380.zip rename to third-party/nanobind-2.11.0.r17.g94ad040.zip index a182bccb..1d824e57 100644 Binary files a/third-party/nanobind-2.11.0.r10.g5f0a380.zip and b/third-party/nanobind-2.11.0.r17.g94ad040.zip differ