diff mbox series

[FFmpeg-devel,4/4] lavu/log: do not assume AVClass.item_name is always set

Message ID 20231107125835.25827-4-anton@khirnov.net
State Accepted
Commit acf63d5350adeae551d412db699f8ca03f7e76b9
Headers show
Series [FFmpeg-devel,1/4] fftools/cmdutils: only set array size after allocation succeeded | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Nov. 7, 2023, 12:58 p.m. UTC
---
 libavutil/log.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

James Almer Nov. 7, 2023, 8:52 p.m. UTC | #1
On 11/7/2023 9:58 AM, Anton Khirnov wrote:
> ---
>   libavutil/log.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/libavutil/log.c b/libavutil/log.c
> index 2d358b7ab9..46662f3db0 100644
> --- a/libavutil/log.c
> +++ b/libavutil/log.c
> @@ -291,6 +291,11 @@ static const char *get_level_str(int level)
>       }
>   }
>   
> +static const char *item_name(void *obj, const AVClass *cls)
> +{
> +    return (cls->item_name ? cls->item_name : av_default_item_name)(obj);
> +}
> +
>   static void format_line(void *avcl, int level, const char *fmt, va_list vl,
>                           AVBPrint part[4], int *print_prefix, int type[2])
>   {
> @@ -307,12 +312,12 @@ static void format_line(void *avcl, int level, const char *fmt, va_list vl,
>                                      avc->parent_log_context_offset);
>               if (parent && *parent) {
>                   av_bprintf(part+0, "[%s @ %p] ",
> -                         (*parent)->item_name(parent), parent);
> +                           item_name(parent, *parent), parent);
>                   if(type) type[0] = get_category(parent);
>               }
>           }
>           av_bprintf(part+1, "[%s @ %p] ",
> -                 avc->item_name(avcl), avcl);
> +                   item_name(avcl, avc), avcl);
>           if(type) type[1] = get_category(avcl);
>       }

If this lets us define an AVClass without having to add the item_name = 
av_default_item_name line, then +1.

Btw, there's also .version that's always set to LIBAVUTIL_VERSION_INT, 
but that can't be changed as they are compile time constants. What can 
probably be dropped however are the checks in log.c for runtime major 
version 50 and 51.
Anton Khirnov Nov. 9, 2023, 10:25 a.m. UTC | #2
Quoting James Almer (2023-11-07 21:52:11)
> What can probably be dropped however are the checks in log.c for
> runtime major version 50 and 51.

Right. Patches welcome?
diff mbox series

Patch

diff --git a/libavutil/log.c b/libavutil/log.c
index 2d358b7ab9..46662f3db0 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -291,6 +291,11 @@  static const char *get_level_str(int level)
     }
 }
 
+static const char *item_name(void *obj, const AVClass *cls)
+{
+    return (cls->item_name ? cls->item_name : av_default_item_name)(obj);
+}
+
 static void format_line(void *avcl, int level, const char *fmt, va_list vl,
                         AVBPrint part[4], int *print_prefix, int type[2])
 {
@@ -307,12 +312,12 @@  static void format_line(void *avcl, int level, const char *fmt, va_list vl,
                                    avc->parent_log_context_offset);
             if (parent && *parent) {
                 av_bprintf(part+0, "[%s @ %p] ",
-                         (*parent)->item_name(parent), parent);
+                           item_name(parent, *parent), parent);
                 if(type) type[0] = get_category(parent);
             }
         }
         av_bprintf(part+1, "[%s @ %p] ",
-                 avc->item_name(avcl), avcl);
+                   item_name(avcl, avc), avcl);
         if(type) type[1] = get_category(avcl);
     }