Skip to content

Commit

Permalink
More span
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed Nov 10, 2023
1 parent 3ec79f9 commit 879c4c5
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion api/c/MachO/LoadCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void init_c_commands(Macho_Binary_t* c_binary, Binary* binary) {
LoadCommand& cmd = commands[i];

c_binary->commands[i] = static_cast<Macho_Command_t*>(malloc(sizeof(Macho_Command_t)));
const std::vector<uint8_t>& cmd_content = cmd.data();
const span<const uint8_t> cmd_content = cmd.data();
auto* content = static_cast<uint8_t*>(malloc(cmd_content.size() * sizeof(uint8_t)));
std::copy(
std::begin(cmd_content),
Expand Down
5 changes: 3 additions & 2 deletions api/python/src/MachO/objects/pyLoadCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
#include <sstream>
#include <nanobind/stl/string.h>
#include "nanobind/extra/memoryview.hpp"
#include "nanobind/utils.hpp"

#include "LIEF/MachO/LoadCommand.hpp"

#include "MachO/pyMachO.hpp"


namespace LIEF::MachO::py {

template<>
Expand All @@ -43,8 +45,7 @@ void create<LoadCommand>(nb::module_& m) {

.def_prop_rw("data",
[] (const LoadCommand& cmd) {
const LoadCommand::raw_t& content = cmd.data();
return nb::memoryview::from_memory(content.data(), content.size());
return nb::to_memoryview(cmd.data());
},
nb::overload_cast<const LoadCommand::raw_t&>(&LoadCommand::data),
"Command's data"_doc)
Expand Down
1 change: 0 additions & 1 deletion include/LIEF/MachO/CodeSignature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ class LIEF_API CodeSignature : public LoadCommand {

~CodeSignature() override;


void accept(Visitor& visitor) const override;

std::ostream& print(std::ostream& os) const override;
Expand Down
1 change: 0 additions & 1 deletion include/LIEF/MachO/DylibCommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ class LIEF_API DylibCommand : public LoadCommand {

std::ostream& print(std::ostream& os) const override;


void accept(Visitor& visitor) const override;

static bool classof(const LoadCommand* cmd);
Expand Down
1 change: 0 additions & 1 deletion include/LIEF/MachO/ExportInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class LIEF_API ExportInfo : public Object {

~ExportInfo() override;


void accept(Visitor& visitor) const override;

LIEF_API friend std::ostream& operator<<(std::ostream& os, const ExportInfo& export_info);
Expand Down
5 changes: 4 additions & 1 deletion include/LIEF/MachO/LoadCommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "LIEF/types.hpp"
#include "LIEF/Object.hpp"
#include "LIEF/visibility.h"
#include "LIEF/span.hpp"

#include "LIEF/MachO/enums.hpp"

Expand Down Expand Up @@ -61,7 +62,9 @@ class LIEF_API LoadCommand : public Object {
uint32_t size() const;

//! Raw command
const raw_t& data() const;
span<const uint8_t> data() const {
return original_data_;
}

//! Offset of the command within the *Load Command Table*
uint64_t command_offset() const;
Expand Down
5 changes: 0 additions & 5 deletions src/MachO/LoadCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ uint32_t LoadCommand::size() const {
return size_;
}

const LoadCommand::raw_t& LoadCommand::data() const {
return original_data_;
}


uint64_t LoadCommand::command_offset() const {
return command_offset_;
}
Expand Down

0 comments on commit 879c4c5

Please sign in to comment.