[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 09/10] kern: Make it possible to subtract conditions from deb
From: |
Daniel Kiper |
Subject: |
Re: [PATCH 09/10] kern: Make it possible to subtract conditions from debug= |
Date: |
Fri, 3 Apr 2020 21:23:55 +0200 |
User-agent: |
NeoMutt/20170113 (1.7.2) |
On Fri, Mar 13, 2020 at 08:16:59PM +0100, Javier Martinez Canillas wrote:
> From: Peter Jones <address@hidden>
>
> This makes it so you can do set debug to "all,-scripting,-lexer" and get the
> obvious outcome. Any negation present will take preference over that
> conditional, so "all,-scripting,scripting" is the same thing as
> "all,-scripting".
>
> Signed-off-by: Peter Jones <address@hidden>
> Signed-off-by: Javier Martinez Canillas <address@hidden>
>
> ---
>
> grub-core/kern/misc.c | 14 +++++++++++++-
> 1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
> index ce92ddd076d..e5fd8c1915f 100644
> --- a/grub-core/kern/misc.c
> +++ b/grub-core/kern/misc.c
> @@ -162,12 +162,24 @@ int
> grub_debug_enabled (const char * condition)
> {
> const char *debug;
> + char *negcond;
> + int negated = 0;
>
> debug = grub_env_get ("debug");
> if (!debug)
> return 0;
>
> - if (grub_strword (debug, "all") || grub_strword (debug, condition))
> + negcond = grub_zalloc (grub_strlen (condition) + 2);
I would use grub_malloc() here and zero last char... And in general
I would try to avoid grub_malloc()/grub_free(). Static buffer? This
is part of debug function and calling into memory allocator can have
bad impact on debugging capabilities. So, it has to be simple as much
as possible.
> + if (negcond)
> + {
> + grub_strcpy (negcond, "-");
*negcond = '-';
The function can be called thousand times. So, this change can matter here.
> + grub_strcpy (negcond+1, condition);
negcond + 1
Or we can avoid copying at all by using grub_strword((debug, condition)
and checking backwards for "-". Or maybe /,[ \t]*-/ (perlre)...
> + negated = grub_strword (debug, negcond);
> + grub_free (negcond);
> + }
> +
> + if (!negated &&
> + (grub_strword (debug, "all") || grub_strword (debug, condition)))
> return 1;
>
> return 0;
Daniel
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [PATCH 09/10] kern: Make it possible to subtract conditions from debug=,
Daniel Kiper <=