| 215 | |
| 216 | |
| 217 | void init(nb::module_& m) { |
| 218 | lief_mod = &m; |
| 219 | m.attr("__version__") = nb::str(LIEF_VERSION); |
| 220 | m.attr("__tag__") = nb::str(LIEF_TAG); |
| 221 | m.attr("__commit__") = nb::str(LIEF_COMMIT); |
| 222 | m.attr("__is_tagged__") = bool(LIEF_TAGGED); |
| 223 | m.doc() = "LIEF Python API"; |
| 224 | |
| 225 | nb::class_<LIEF::lief_version_t>(m, "lief_version_t") |
| 226 | .def_rw("major", &LIEF::lief_version_t::major) |
| 227 | .def_rw("minor", &LIEF::lief_version_t::minor) |
| 228 | .def_rw("patch", &LIEF::lief_version_t::patch) |
| 229 | .def_rw("id", &LIEF::lief_version_t::id) |
| 230 | .def("__repr__", |
| 231 | [] (const LIEF::lief_version_t& version) { |
| 232 | return fmt::format("<lief_version_t: {}>", version.to_string()); |
| 233 | } |
| 234 | ) |
| 235 | .def("__str__", |
| 236 | [] (const LIEF::lief_version_t& version) { |
| 237 | return version.to_string(); |
| 238 | } |
| 239 | ) |
| 240 | ; |
| 241 | |
| 242 | |
| 243 | m.def("disable_leak_warning", [] { |
| 244 | nb::set_leak_warnings(false); |
| 245 | }, R"doc( |
| 246 | Disable nanobind warnings about leaked objects. |
| 247 | For instance: |
| 248 | |
| 249 | .. code-block:: text |
| 250 | |
| 251 | nanobind: leaked 45 instances! |
| 252 | nanobind: leaked 25 types! |
| 253 | - leaked type "lief._lief.FORMATS" |
| 254 | - ... skipped remainder |
| 255 | nanobind: leaked 201 functions! |
| 256 | - leaked function "" |
| 257 | - leaked function "export_symbol" |
| 258 | - ... skipped remainder |
| 259 | nanobind: this is likely caused by a reference counting issue in the binding code. |
| 260 | )doc"_doc); |
| 261 | |
| 262 | m.def("demangle", |
| 263 | [] (const std::string& mangled) { |
| 264 | return LIEF::py::value_or_none(&LIEF::demangle, mangled); |
| 265 | }, |
| 266 | R"doc( |
| 267 | Demangle the given input. |
| 268 | |
| 269 | .. warning:: |
| 270 | |
| 271 | This function only works with the extended version of LIEF |
| 272 | )doc"_doc, |
| 273 | "mangled"_a |
| 274 | ); |
no test coverage detected