Re: [RFC PATCH 1/2] libbpf: Add userspace version of for_each_member macro

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Apr 4, 2022 at 1:38 AM Nikolay Borisov <nborisov@xxxxxxxx> 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@xxxxxxxx>
> ---
>  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
>



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux