mirror of
https://github.com/varun-r-mallya/pylibbpf.git
synced 2026-02-10 23:20:55 +00:00
Use shared_from_this while creating BpfProgram or BpfMap, make get_map_names and get_program_names non-const
This commit is contained in:
@ -74,7 +74,7 @@ void BpfObject::load() {
|
||||
|
||||
// ==================== Program Methods ====================
|
||||
|
||||
py::list BpfObject::get_program_names() const {
|
||||
py::list BpfObject::get_program_names() {
|
||||
if (!loaded_) {
|
||||
throw BpfException("BPF object not loaded");
|
||||
}
|
||||
@ -106,7 +106,7 @@ BpfObject::_get_or_create_program(struct bpf_program *prog) {
|
||||
}
|
||||
|
||||
// Create and cache
|
||||
auto bpf_prog = std::make_shared<BpfProgram>(this, prog, prog_name);
|
||||
auto bpf_prog = std::make_shared<BpfProgram>(shared_from_this(), prog, prog_name);
|
||||
prog_cache_[prog_name] = bpf_prog;
|
||||
|
||||
return bpf_prog;
|
||||
@ -125,7 +125,7 @@ std::shared_ptr<BpfProgram> BpfObject::get_program(const std::string &name) {
|
||||
|
||||
// Create and cache
|
||||
struct bpf_program *raw_prog = find_program_by_name(name);
|
||||
auto prog = std::make_shared<BpfProgram>(this, raw_prog, name);
|
||||
auto prog = std::make_shared<BpfProgram>(shared_from_this(), raw_prog, name);
|
||||
prog_cache_[name] = prog;
|
||||
|
||||
return prog;
|
||||
@ -148,8 +148,8 @@ BpfObject::find_program_by_name(const std::string &name) const {
|
||||
|
||||
py::dict BpfObject::get_cached_programs() const {
|
||||
py::dict programs;
|
||||
for (const auto &[name, prog] : prog_cache_) {
|
||||
programs[name] = prog;
|
||||
for (const auto &entry : prog_cache_) {
|
||||
programs[entry.first.c_str()] = entry.second;
|
||||
}
|
||||
return programs;
|
||||
}
|
||||
@ -178,7 +178,7 @@ py::dict BpfObject::attach_all() {
|
||||
|
||||
// ==================== Map Methods ====================
|
||||
|
||||
py::list BpfObject::get_map_names() const {
|
||||
py::list BpfObject::get_map_names() {
|
||||
if (!loaded_) {
|
||||
throw BpfException("BPF object not loaded");
|
||||
}
|
||||
@ -249,8 +249,8 @@ struct bpf_map *BpfObject::find_map_by_name(const std::string &name) const {
|
||||
|
||||
py::dict BpfObject::get_cached_maps() const {
|
||||
py::dict maps;
|
||||
for (const auto &[name, map] : maps_cache_) {
|
||||
maps[name] = map;
|
||||
for (const auto &entry : maps_cache_) {
|
||||
maps[entry.first.c_str()] = entry.second;
|
||||
}
|
||||
return maps;
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ public:
|
||||
py::dict attach_all();
|
||||
|
||||
// Program access
|
||||
[[nodiscard]] py::list get_program_names() const;
|
||||
[[nodiscard]] py::list get_program_names();
|
||||
[[nodiscard]] std::shared_ptr<BpfProgram>
|
||||
get_program(const std::string &name);
|
||||
[[nodiscard]] struct bpf_program *
|
||||
@ -73,7 +73,7 @@ public:
|
||||
[[nodiscard]] py::dict get_cached_programs() const;
|
||||
|
||||
// Map access
|
||||
[[nodiscard]] py::list get_map_names() const;
|
||||
[[nodiscard]] py::list get_map_names();
|
||||
[[nodiscard]] std::shared_ptr<BpfMap> get_map(const std::string &name);
|
||||
[[nodiscard]] struct bpf_map *find_map_by_name(const std::string &name) const;
|
||||
[[nodiscard]] py::dict get_cached_maps() const;
|
||||
|
||||
Reference in New Issue
Block a user