diff mbox series

[dwarves,v6,1/3] gobuffer: Add gobuffer__sort() helper

Message ID ba9ff49e099583ab854d3d3c8c215c3ca1b6f930.1711389163.git.dxu@dxuuu.xyz (mailing list archive)
State Not Applicable
Headers show
Series pahole: Inject kfunc decl tags into BTF | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Daniel Xu March 25, 2024, 5:53 p.m. UTC
Add a helper to sort the gobuffer. Trivial wrapper around qsort().

Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
---
 gobuffer.c | 5 +++++
 gobuffer.h | 2 ++
 2 files changed, 7 insertions(+)

Comments

Alan Maguire April 17, 2024, 9:20 a.m. UTC | #1
On 25/03/2024 17:53, Daniel Xu wrote:
> Add a helper to sort the gobuffer. Trivial wrapper around qsort().
> 
> Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
> ---
>  gobuffer.c | 5 +++++
>  gobuffer.h | 2 ++
>  2 files changed, 7 insertions(+)
> 
> diff --git a/gobuffer.c b/gobuffer.c
> index 02b2084..4655339 100644
> --- a/gobuffer.c
> +++ b/gobuffer.c
> @@ -102,6 +102,11 @@ void gobuffer__copy(const struct gobuffer *gb, void *dest)
>  	}
>  }
>  
> +void gobuffer__sort(struct gobuffer *gb, unsigned int size, int (*compar)(const void *, const void *))
> +{
> +	qsort((void *)gb->entries, gb->nr_entries, size, compar);

nit shouldn't need to cast char * gb->entries to void * ; not worth
respinning the series for though unless there are other issues

> +}
> +
>  const void *gobuffer__compress(struct gobuffer *gb, unsigned int *size)
>  {
>  	z_stream z = {
> diff --git a/gobuffer.h b/gobuffer.h
> index a12c5c8..cd218b6 100644
> --- a/gobuffer.h
> +++ b/gobuffer.h
> @@ -21,6 +21,8 @@ void __gobuffer__delete(struct gobuffer *gb);
>  
>  void gobuffer__copy(const struct gobuffer *gb, void *dest);
>  
> +void gobuffer__sort(struct gobuffer *gb, unsigned int size, int (*compar)(const void *, const void *));
> +
>  int gobuffer__add(struct gobuffer *gb, const void *s, unsigned int len);
>  int gobuffer__allocate(struct gobuffer *gb, unsigned int len);
>
Arnaldo Carvalho de Melo April 17, 2024, 1:40 p.m. UTC | #2
On Wed, Apr 17, 2024 at 10:20:41AM +0100, Alan Maguire wrote:
> On 25/03/2024 17:53, Daniel Xu wrote:
> > Add a helper to sort the gobuffer. Trivial wrapper around qsort().
> > 
> > Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
> Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
> > ---
> >  gobuffer.c | 5 +++++
> >  gobuffer.h | 2 ++
> >  2 files changed, 7 insertions(+)
> > 
> > diff --git a/gobuffer.c b/gobuffer.c
> > index 02b2084..4655339 100644
> > --- a/gobuffer.c
> > +++ b/gobuffer.c
> > @@ -102,6 +102,11 @@ void gobuffer__copy(const struct gobuffer *gb, void *dest)
> >  	}
> >  }
> >  
> > +void gobuffer__sort(struct gobuffer *gb, unsigned int size, int (*compar)(const void *, const void *))
> > +{
> > +	qsort((void *)gb->entries, gb->nr_entries, size, compar);
> 
> nit shouldn't need to cast char * gb->entries to void * ; not worth
> respinning the series for though unless there are other issues

I can remove that while applying the series, which I'm doing now.

- Arnaldo
 
> > +}
> > +
> >  const void *gobuffer__compress(struct gobuffer *gb, unsigned int *size)
> >  {
> >  	z_stream z = {
> > diff --git a/gobuffer.h b/gobuffer.h
> > index a12c5c8..cd218b6 100644
> > --- a/gobuffer.h
> > +++ b/gobuffer.h
> > @@ -21,6 +21,8 @@ void __gobuffer__delete(struct gobuffer *gb);
> >  
> >  void gobuffer__copy(const struct gobuffer *gb, void *dest);
> >  
> > +void gobuffer__sort(struct gobuffer *gb, unsigned int size, int (*compar)(const void *, const void *));
> > +
> >  int gobuffer__add(struct gobuffer *gb, const void *s, unsigned int len);
> >  int gobuffer__allocate(struct gobuffer *gb, unsigned int len);
> >
Alan Maguire April 18, 2024, 9:31 a.m. UTC | #3
On 17/04/2024 14:40, Arnaldo Carvalho de Melo wrote:
> On Wed, Apr 17, 2024 at 10:20:41AM +0100, Alan Maguire wrote:
>> On 25/03/2024 17:53, Daniel Xu wrote:
>>> Add a helper to sort the gobuffer. Trivial wrapper around qsort().
>>>
>>> Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
>> Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
>>> ---
>>>  gobuffer.c | 5 +++++
>>>  gobuffer.h | 2 ++
>>>  2 files changed, 7 insertions(+)
>>>
>>> diff --git a/gobuffer.c b/gobuffer.c
>>> index 02b2084..4655339 100644
>>> --- a/gobuffer.c
>>> +++ b/gobuffer.c
>>> @@ -102,6 +102,11 @@ void gobuffer__copy(const struct gobuffer *gb, void *dest)
>>>  	}
>>>  }
>>>  
>>> +void gobuffer__sort(struct gobuffer *gb, unsigned int size, int (*compar)(const void *, const void *))
>>> +{
>>> +	qsort((void *)gb->entries, gb->nr_entries, size, compar);
>>
>> nit shouldn't need to cast char * gb->entries to void * ; not worth
>> respinning the series for though unless there are other issues
> 
> I can remove that while applying the series, which I'm doing now.
>

great, thanks! BTW patch 2 will probably require a small tweak for
merging into next:

-	BTF_FEATURE(decl_tag_kfuncs, btf_decl_tag_kfuncs, false),
+	BTF_FEATURE(decl_tag_kfuncs, btf_decl_tag_kfuncs, false, true),

this will ensure it is considered a standard feature and is enabled for
"all"; for readability it might make sense to position it wth the other
features prior to

        BTF_FEATURE(reproducible_build, reproducible_build, false, false),

...since then we'd have the standard features grouped before the
non-standard ones, making it a bit more readable; not a big deal tho.
thanks!

> - Arnaldo
>  
>>> +}
>>> +
>>>  const void *gobuffer__compress(struct gobuffer *gb, unsigned int *size)
>>>  {
>>>  	z_stream z = {
>>> diff --git a/gobuffer.h b/gobuffer.h
>>> index a12c5c8..cd218b6 100644
>>> --- a/gobuffer.h
>>> +++ b/gobuffer.h
>>> @@ -21,6 +21,8 @@ void __gobuffer__delete(struct gobuffer *gb);
>>>  
>>>  void gobuffer__copy(const struct gobuffer *gb, void *dest);
>>>  
>>> +void gobuffer__sort(struct gobuffer *gb, unsigned int size, int (*compar)(const void *, const void *));
>>> +
>>>  int gobuffer__add(struct gobuffer *gb, const void *s, unsigned int len);
>>>  int gobuffer__allocate(struct gobuffer *gb, unsigned int len);
>>>
diff mbox series

Patch

diff --git a/gobuffer.c b/gobuffer.c
index 02b2084..4655339 100644
--- a/gobuffer.c
+++ b/gobuffer.c
@@ -102,6 +102,11 @@  void gobuffer__copy(const struct gobuffer *gb, void *dest)
 	}
 }
 
+void gobuffer__sort(struct gobuffer *gb, unsigned int size, int (*compar)(const void *, const void *))
+{
+	qsort((void *)gb->entries, gb->nr_entries, size, compar);
+}
+
 const void *gobuffer__compress(struct gobuffer *gb, unsigned int *size)
 {
 	z_stream z = {
diff --git a/gobuffer.h b/gobuffer.h
index a12c5c8..cd218b6 100644
--- a/gobuffer.h
+++ b/gobuffer.h
@@ -21,6 +21,8 @@  void __gobuffer__delete(struct gobuffer *gb);
 
 void gobuffer__copy(const struct gobuffer *gb, void *dest);
 
+void gobuffer__sort(struct gobuffer *gb, unsigned int size, int (*compar)(const void *, const void *));
+
 int gobuffer__add(struct gobuffer *gb, const void *s, unsigned int len);
 int gobuffer__allocate(struct gobuffer *gb, unsigned int len);