grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] add grub_qsort_strcmp to use when sorting array of strings
@ 2013-11-29 17:01 Andrey Borzenkov
  2013-11-30 10:39 ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 1 reply; 4+ messages in thread
From: Andrey Borzenkov @ 2013-11-29 17:01 UTC (permalink / raw)
  To: grub-devel

Compare function used in qsort gets arguments by reference, so strcmp
cannot be used directly - it expects pointer to char, but gets pointer
to pointer to char.

Introduce new helper grub_qsort_strcmp and use it in grub-install.
This helper is going to be used in a couple more places as well so
add it to global file, not in grub-install.c.

---
 include/grub/util/misc.h | 2 ++
 util/grub-install.c      | 2 +-
 util/misc.c              | 8 ++++++++
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/grub/util/misc.h b/include/grub/util/misc.h
index 6aacf23..192874d 100644
--- a/include/grub/util/misc.h
+++ b/include/grub/util/misc.h
@@ -47,4 +47,6 @@ void grub_util_init_nls (void);
 
 void grub_util_host_init (int *argc, char ***argv);
 
+int grub_qsort_strcmp (const void *, const void *);
+
 #endif /* ! GRUB_UTIL_MISC_HEADER */
diff --git a/util/grub-install.c b/util/grub-install.c
index 5354a6d..1870182 100644
--- a/util/grub-install.c
+++ b/util/grub-install.c
@@ -583,7 +583,7 @@ device_map_check_duplicates (const char *dev_map)
 
   fclose (fp);
 
-  qsort (d, filled, sizeof (d[0]), (int (*) (const void *, const void *))strcmp);
+  qsort (d, filled, sizeof (d[0]), grub_qsort_strcmp);
 
   for (i = 0; i + 1 < filled; i++)
     if (strcmp (d[i], d[i+1]) == 0)
diff --git a/util/misc.c b/util/misc.c
index 0de340b..9eb1fc1 100644
--- a/util/misc.c
+++ b/util/misc.c
@@ -256,3 +256,11 @@ void
 grub_register_exported_symbols (void)
 {
 }
+
+/* Used in comparison of arrays of strings with qsort */
+int
+grub_qsort_strcmp (const void *p1, const void *p2)
+{
+  return strcmp(*(char **)p1, *(char **)p2);
+}
+
-- 
tg: (69ca97c..) u/qsort-fix (depends on: master)


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] add grub_qsort_strcmp to use when sorting array of strings
  2013-11-29 17:01 [PATCH] add grub_qsort_strcmp to use when sorting array of strings Andrey Borzenkov
@ 2013-11-30 10:39 ` Vladimir 'φ-coder/phcoder' Serbinenko
  2013-11-30 10:59   ` Andrey Borzenkov
  0 siblings, 1 reply; 4+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-11-30 10:39 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 1993 bytes --]

On 29.11.2013 18:01, Andrey Borzenkov wrote:
> Compare function used in qsort gets arguments by reference, so strcmp
> cannot be used directly - it expects pointer to char, but gets pointer
> to pointer to char.
> 
> Introduce new helper grub_qsort_strcmp and use it in grub-install.
> This helper is going to be used in a couple more places as well so
> add it to global file, not in grub-install.c.
> 
Nice catch. But I don't we have enough use for grub_qsort_strcmp to make
it global. Can you make it static in grub-install.c ?
> ---
>  include/grub/util/misc.h | 2 ++
>  util/grub-install.c      | 2 +-
>  util/misc.c              | 8 ++++++++
>  3 files changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/include/grub/util/misc.h b/include/grub/util/misc.h
> index 6aacf23..192874d 100644
> --- a/include/grub/util/misc.h
> +++ b/include/grub/util/misc.h
> @@ -47,4 +47,6 @@ void grub_util_init_nls (void);
>  
>  void grub_util_host_init (int *argc, char ***argv);
>  
> +int grub_qsort_strcmp (const void *, const void *);
> +
>  #endif /* ! GRUB_UTIL_MISC_HEADER */
> diff --git a/util/grub-install.c b/util/grub-install.c
> index 5354a6d..1870182 100644
> --- a/util/grub-install.c
> +++ b/util/grub-install.c
> @@ -583,7 +583,7 @@ device_map_check_duplicates (const char *dev_map)
>  
>    fclose (fp);
>  
> -  qsort (d, filled, sizeof (d[0]), (int (*) (const void *, const void *))strcmp);
> +  qsort (d, filled, sizeof (d[0]), grub_qsort_strcmp);
>  
>    for (i = 0; i + 1 < filled; i++)
>      if (strcmp (d[i], d[i+1]) == 0)
> diff --git a/util/misc.c b/util/misc.c
> index 0de340b..9eb1fc1 100644
> --- a/util/misc.c
> +++ b/util/misc.c
> @@ -256,3 +256,11 @@ void
>  grub_register_exported_symbols (void)
>  {
>  }
> +
> +/* Used in comparison of arrays of strings with qsort */
> +int
> +grub_qsort_strcmp (const void *p1, const void *p2)
> +{
> +  return strcmp(*(char **)p1, *(char **)p2);
> +}
> +
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 291 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] add grub_qsort_strcmp to use when sorting array of strings
  2013-11-30 10:39 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2013-11-30 10:59   ` Andrey Borzenkov
  2013-12-02  5:34     ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 1 reply; 4+ messages in thread
From: Andrey Borzenkov @ 2013-11-30 10:59 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 836 bytes --]

В Sat, 30 Nov 2013 11:39:12 +0100
Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:

> On 29.11.2013 18:01, Andrey Borzenkov wrote:
> > Compare function used in qsort gets arguments by reference, so strcmp
> > cannot be used directly - it expects pointer to char, but gets pointer
> > to pointer to char.
> > 
> > Introduce new helper grub_qsort_strcmp and use it in grub-install.
> > This helper is going to be used in a couple more places as well so
> > add it to global file, not in grub-install.c.
> > 
> Nice catch. But I don't we have enough use for grub_qsort_strcmp to make
> it global. Can you make it static in grub-install.c ?

I have pending patches to sort long lists in help output of commands
(grub-mkimage and grub-probe target lists). They are long enough to
wish some ordering.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] add grub_qsort_strcmp to use when sorting array of strings
  2013-11-30 10:59   ` Andrey Borzenkov
@ 2013-12-02  5:34     ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 0 replies; 4+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-12-02  5:34 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 1090 bytes --]

On 30.11.2013 11:59, Andrey Borzenkov wrote:
> В Sat, 30 Nov 2013 11:39:12 +0100
> Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:
> 
>> On 29.11.2013 18:01, Andrey Borzenkov wrote:
>>> Compare function used in qsort gets arguments by reference, so strcmp
>>> cannot be used directly - it expects pointer to char, but gets pointer
>>> to pointer to char.
>>>
>>> Introduce new helper grub_qsort_strcmp and use it in grub-install.
>>> This helper is going to be used in a couple more places as well so
>>> add it to global file, not in grub-install.c.
>>>
>> Nice catch. But I don't we have enough use for grub_qsort_strcmp to make
>> it global. Can you make it static in grub-install.c ?
> 
> I have pending patches to sort long lists in help output of commands
> (grub-mkimage and grub-probe target lists). They are long enough to
> wish some ordering.
> 
Ok, then go ahead.
> 
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 291 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-12-02  5:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-29 17:01 [PATCH] add grub_qsort_strcmp to use when sorting array of strings Andrey Borzenkov
2013-11-30 10:39 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-11-30 10:59   ` Andrey Borzenkov
2013-12-02  5:34     ` Vladimir 'φ-coder/phcoder' Serbinenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).