Message ID | 20220404083816.1560501-2-nborisov@suse.com (mailing list archive) |
---|---|
State | RFC |
Delegated to: | BPF |
Headers | show |
Series | Add btf__field_exists | expand |
Context | Check | Description |
---|---|---|
bpf/vmtest-bpf-PR | fail | merge-conflict |
netdev/tree_selection | success | Not a local patch |
On Mon, Apr 4, 2022 at 1:38 AM Nikolay Borisov <nborisov@suse.com> wrote: > > There are multiple places in libbpf where iteration of struct/union > members is required. Instead of open-coding it let's introduce a > convenience macro. > > Signed-off-by: Nikolay Borisov <nborisov@suse.com> > --- > tools/lib/bpf/btf.h | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h > index 061839f04525..74039f8afc63 100644 > --- a/tools/lib/bpf/btf.h > +++ b/tools/lib/bpf/btf.h > @@ -578,6 +578,12 @@ static inline struct btf_decl_tag *btf_decl_tag(const struct btf_type *t) > return (struct btf_decl_tag *)(t + 1); > } > > +#define for_each_member(i, struct_type, member) \ > + for (i = 0, member = btf_members(struct_type); \ > + i < btf_vlen(struct_type); \ > + i++, member++) > + > + this now becomes part of libbpf's API, do we really need it to be part of an API? And even if we did add it, we'll need to do this for params and enums for completeness. > #ifdef __cplusplus > } /* extern "C" */ > #endif > -- > 2.25.1 >
diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h index 061839f04525..74039f8afc63 100644 --- a/tools/lib/bpf/btf.h +++ b/tools/lib/bpf/btf.h @@ -578,6 +578,12 @@ static inline struct btf_decl_tag *btf_decl_tag(const struct btf_type *t) return (struct btf_decl_tag *)(t + 1); } +#define for_each_member(i, struct_type, member) \ + for (i = 0, member = btf_members(struct_type); \ + i < btf_vlen(struct_type); \ + i++, member++) + + #ifdef __cplusplus } /* extern "C" */ #endif
There are multiple places in libbpf where iteration of struct/union members is required. Instead of open-coding it let's introduce a convenience macro. Signed-off-by: Nikolay Borisov <nborisov@suse.com> --- tools/lib/bpf/btf.h | 6 ++++++ 1 file changed, 6 insertions(+)