Switch the bindings to nanobind (and update the CI)

This commit is contained in:
Romain Thomas
2023-07-09 21:33:43 +02:00
parent 7e387675ac
commit e37ffa9ec8
377 changed files with 12540 additions and 15730 deletions
+23 -30
View File
@@ -15,72 +15,65 @@
*/
#include <string>
#include <memory>
#include <nanobind/stl/unique_ptr.h>
#include <nanobind/stl/string.h>
#include <nanobind/stl/vector.h>
#include "PyIOStream.hpp"
#include "pyIOStream.hpp"
#include "LIEF/MachO/Parser.hpp"
#include "LIEF/MachO/FatBinary.hpp"
#include "LIEF/logging.hpp"
#include "pyMachO.hpp"
#include "MachO/pyMachO.hpp"
namespace LIEF {
namespace MachO {
namespace LIEF::MachO::py {
template<>
void create<Parser>(py::module& m) {
void create<Parser>(nb::module_& m) {
using namespace LIEF::py;
// Parser (Parser)
m.def("parse",
static_cast<std::unique_ptr<FatBinary> (*) (const std::string&, const ParserConfig&)>(&LIEF::MachO::Parser::parse),
nb::overload_cast<const std::string&, const ParserConfig&>(&LIEF::MachO::Parser::parse),
R"delim(
Parse the given binary and return a :class:`~lief.MachO.FatBinary` object
One can configure the parsing with the ``config`` parameter. See :class:`~lief.MachO.ParserConfig`,
)delim",
"filename"_a,
"config"_a = ParserConfig::deep(),
py::return_value_policy::take_ownership);
)delim"_doc, "filename"_a, "config"_a = ParserConfig::deep(),
nb::rv_policy::take_ownership);
m.def("parse",
static_cast<std::unique_ptr<FatBinary> (*) (const std::vector<uint8_t>&, const ParserConfig&)>(&LIEF::MachO::Parser::parse),
nb::overload_cast<const std::vector<uint8_t>&, const ParserConfig&>(&LIEF::MachO::Parser::parse),
R"delim(
Parse the given binary (from raw bytes) and return a :class:`~lief.MachO.FatBinary` object
One can configure the parsing with the ``config`` parameter. See :class:`~lief.MachO.ParserConfig`
)delim",
"raw"_a,
"config"_a = ParserConfig::quick(),
py::return_value_policy::take_ownership);
)delim"_doc, "raw"_a, "config"_a = ParserConfig::quick(),
nb::rv_policy::take_ownership);
m.def("parse_from_memory",
static_cast<std::unique_ptr<FatBinary> (*) (uintptr_t, const ParserConfig&)>(&MachO::Parser::parse_from_memory),
nb::overload_cast<uintptr_t, const ParserConfig&>(&MachO::Parser::parse_from_memory),
R"delim(
Parse the Mach-O binary from the address given in the first parameter
)delim",
"address"_a,
"config"_a = ParserConfig::deep(),
py::return_value_policy::take_ownership);
)delim"_doc, "address"_a, "config"_a = ParserConfig::deep(),
nb::rv_policy::take_ownership);
m.def("parse",
[] (py::object byteio, const ParserConfig& config) -> py::object {
if (auto stream = PyIOStream::from_python(byteio)) {
[] (nb::object byteio, const ParserConfig& config) -> nb::object {
if (auto stream = PyIOStream::from_python(std::move(byteio))) {
auto ptr = std::make_unique<PyIOStream>(std::move(*stream));
return py::cast(MachO::Parser::parse(std::move(ptr), config));
return nb::cast(MachO::Parser::parse(std::move(ptr), config));
}
logging::log(logging::LOG_ERR, "Can't create a LIEF stream interface over the provided io");
return py::none();
return nb::none();
},
R"delim(
Parse the given binary from a Python IO interface and return a :class:`~lief.MachO.FatBinary` object
One can configure the parsing with the ``config`` parameter. See :class:`~lief.MachO.ParserConfig`
)delim",
"io"_a,
"config"_a = ParserConfig::quick(),
py::return_value_policy::take_ownership);
)delim"_doc, "io"_a, "config"_a = ParserConfig::quick(),
nb::rv_policy::take_ownership);
}
}
}