Skip to content

Commit 4a5ff0c

Browse files
committed
Janitorial: clang-format
1 parent c5a485b commit 4a5ff0c

File tree

8 files changed

+628
-642
lines changed

8 files changed

+628
-642
lines changed

src/core/bpf_map.cpp

Lines changed: 181 additions & 204 deletions
Large diffs are not rendered by default.

src/core/bpf_map.h

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,72 @@
11
#ifndef PYLIBBPF_BPF_MAP_H
22
#define PYLIBBPF_BPF_MAP_H
33

4+
#include <algorithm>
5+
#include <array>
6+
#include <cerrno>
7+
#include <cstring>
48
#include <libbpf.h>
59
#include <pybind11/pybind11.h>
6-
#include <vector>
7-
#include <string>
810
#include <span>
9-
#include <array>
10-
#include <algorithm>
11-
#include <cstring>
12-
#include <cerrno>
11+
#include <string>
12+
#include <vector>
1313

1414
class BpfObject;
1515

1616
namespace py = pybind11;
1717

1818
class BpfMap {
1919
private:
20-
std::weak_ptr<BpfObject> parent_obj_;
21-
struct bpf_map *map_;
22-
int map_fd_;
23-
std::string map_name_;
24-
__u32 key_size_, value_size_;
20+
std::weak_ptr<BpfObject> parent_obj_;
21+
struct bpf_map *map_;
22+
int map_fd_;
23+
std::string map_name_;
24+
__u32 key_size_, value_size_;
25+
26+
template <size_t StackSize = 64> struct BufferManager {
27+
std::array<uint8_t, StackSize> stack_buf;
28+
std::vector<uint8_t> heap_buf;
2529

26-
template<size_t StackSize = 64>
27-
struct BufferManager {
28-
std::array<uint8_t, StackSize> stack_buf;
29-
std::vector<uint8_t> heap_buf;
30-
31-
std::span<uint8_t> get_span(size_t size) {
32-
if (size <= StackSize) {
33-
return std::span<uint8_t>(stack_buf.data(), size);
34-
} else {
35-
heap_buf.resize(size);
36-
return std::span<uint8_t>(heap_buf);
37-
}
38-
}
39-
};
30+
std::span<uint8_t> get_span(size_t size) {
31+
if (size <= StackSize) {
32+
return std::span<uint8_t>(stack_buf.data(), size);
33+
} else {
34+
heap_buf.resize(size);
35+
return std::span<uint8_t>(heap_buf);
36+
}
37+
}
38+
};
4039

4140
public:
42-
BpfMap(std::shared_ptr<BpfObject> parent, struct bpf_map *raw_map, const std::string &map_name);
41+
BpfMap(std::shared_ptr<BpfObject> parent, struct bpf_map *raw_map,
42+
const std::string &map_name);
4343

44-
~BpfMap() = default;
44+
~BpfMap() = default;
4545

46-
BpfMap(const BpfMap&) = delete;
47-
BpfMap& operator=(const BpfMap&) = delete;
48-
BpfMap(BpfMap&&) noexcept = default;
49-
BpfMap& operator=(BpfMap&&) noexcept = default;
46+
BpfMap(const BpfMap &) = delete;
47+
BpfMap &operator=(const BpfMap &) = delete;
48+
BpfMap(BpfMap &&) noexcept = default;
49+
BpfMap &operator=(BpfMap &&) noexcept = default;
5050

51-
[[nodiscard]] py::object lookup(const py::object &key) const;
52-
void update(const py::object &key, const py::object &value) const;
53-
void delete_elem(const py::object &key) const;
54-
py::object get_next_key(const py::object &key = py::none()) const;
55-
py::dict items() const;
56-
py::list keys() const;
57-
py::list values() const;
51+
[[nodiscard]] py::object lookup(const py::object &key) const;
52+
void update(const py::object &key, const py::object &value) const;
53+
void delete_elem(const py::object &key) const;
54+
py::object get_next_key(const py::object &key = py::none()) const;
55+
py::dict items() const;
56+
py::list keys() const;
57+
py::list values() const;
5858

59-
[[nodiscard]] std::string get_name() const { return map_name_; }
60-
[[nodiscard]] int get_fd() const { return map_fd_; }
61-
[[nodiscard]] int get_type() const;
62-
[[nodiscard]] int get_key_size() const { return key_size_; };
63-
[[nodiscard]] int get_value_size() const { return value_size_; };
64-
[[nodiscard]] int get_max_entries() const;
59+
[[nodiscard]] std::string get_name() const { return map_name_; }
60+
[[nodiscard]] int get_fd() const { return map_fd_; }
61+
[[nodiscard]] int get_type() const;
62+
[[nodiscard]] int get_key_size() const { return key_size_; };
63+
[[nodiscard]] int get_value_size() const { return value_size_; };
64+
[[nodiscard]] int get_max_entries() const;
6565

6666
private:
67-
static void python_to_bytes_inplace(const py::object &obj, std::span<uint8_t> buffer);
68-
static py::object bytes_to_python(std::span<const uint8_t> data);
67+
static void python_to_bytes_inplace(const py::object &obj,
68+
std::span<uint8_t> buffer);
69+
static py::object bytes_to_python(std::span<const uint8_t> data);
6970
};
7071

71-
#endif //PYLIBBPF_MAPS_H
72+
#endif // PYLIBBPF_MAPS_H

0 commit comments

Comments
 (0)