mirror of
https://github.com/lief-project/LIEF
synced 2026-06-08 15:30:44 +00:00
Switch the bindings to nanobind (and update the CI)
This commit is contained in:
@@ -13,60 +13,32 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <algorithm>
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <nanobind/stl/string.h>
|
||||
|
||||
#include "LIEF/MachO/hash.hpp"
|
||||
#include "LIEF/MachO/DylinkerCommand.hpp"
|
||||
|
||||
#include "pyMachO.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace MachO {
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (DylinkerCommand::*)(void) const;
|
||||
|
||||
template<class T>
|
||||
using setter_t = void (DylinkerCommand::*)(T);
|
||||
#include "MachO/pyMachO.hpp"
|
||||
|
||||
namespace LIEF::MachO::py {
|
||||
|
||||
template<>
|
||||
void create<DylinkerCommand>(py::module& m) {
|
||||
void create<DylinkerCommand>(nb::module_& m) {
|
||||
|
||||
py::class_<DylinkerCommand, LoadCommand>(m, "DylinkerCommand",
|
||||
nb::class_<DylinkerCommand, LoadCommand>(m, "DylinkerCommand",
|
||||
R"delim(
|
||||
Class that represents the Mach-O linker, also named loader
|
||||
Most of the time, :attr:`~lief.MachO.DylinkerCommand.name` returns ``/usr/lib/dyld``
|
||||
)delim")
|
||||
.def(py::init<const std::string&>())
|
||||
)delim"_doc)
|
||||
.def(nb::init<const std::string&>())
|
||||
|
||||
.def_property("name",
|
||||
static_cast<getter_t<const std::string&>>(&DylinkerCommand::name),
|
||||
static_cast<setter_t<const std::string&>>(&DylinkerCommand::name),
|
||||
"Path to the loader/linker",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
.def("__eq__", &DylinkerCommand::operator==)
|
||||
.def("__ne__", &DylinkerCommand::operator!=)
|
||||
.def("__hash__",
|
||||
[] (const DylinkerCommand& dylinker) {
|
||||
return Hash::hash(dylinker);
|
||||
})
|
||||
|
||||
|
||||
.def("__str__",
|
||||
[] (const DylinkerCommand& dylinker)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << dylinker;
|
||||
std::string str = stream.str();
|
||||
return str;
|
||||
});
|
||||
|
||||
}
|
||||
.def_prop_rw("name",
|
||||
nb::overload_cast<>(&DylinkerCommand::name, nb::const_),
|
||||
nb::overload_cast<const std::string&>(&DylinkerCommand::name),
|
||||
"Path to the loader/linker"_doc,
|
||||
nb::rv_policy::reference_internal)
|
||||
|
||||
LIEF_DEFAULT_STR(DylinkerCommand);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user