Update nanobind

This commit is contained in:
Romain Thomas
2026-02-15 11:30:29 +01:00
parent d19b32f006
commit d09a8d53cd
6 changed files with 14 additions and 10 deletions
+6 -2
View File
@@ -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
+4 -4
View File
@@ -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<const uint8_t> sp) {
return nanobind::memoryview::from_memory(sp.data(), sp.size());
inline nanobind::extra::memoryview to_memoryview(LIEF::span<const uint8_t> sp) {
return nanobind::extra::memoryview::from_memory(sp.data(), sp.size());
}
inline nanobind::memoryview to_memoryview(const std::vector<uint8_t>& vec) {
return nanobind::memoryview::from_memory(vec.data(), vec.size());
inline nanobind::extra::memoryview to_memoryview(const std::vector<uint8_t>& vec) {
return nanobind::extra::memoryview::from_memory(vec.data(), vec.size());
}
inline std::vector<uint8_t> to_vector(nanobind::bytes bytes) {
+1 -1
View File
@@ -55,7 +55,7 @@ result<PyIOStream> 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")) {
+1 -1
View File
@@ -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);