mirror of
https://github.com/lief-project/LIEF
synced 2026-06-08 15:30:44 +00:00
Update nanobind
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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")) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user