[FFmpeg-devel] [PATCH v5 06/14] fftools/textformat: AVTextWriter change writer_printf signature

Stefano Sabatini stefasab at gmail.com
Thu Apr 24 02:07:43 EEST 2025


On date Tuesday 2025-04-22 21:55:35 +0000, softworkz wrote:
> From: softworkz <softworkz at hotmail.com>
> 

> Using va_list provides greater flebility

flebility typo

Also this looks more about factorization than flexibility (for an API
used directly by users the ... format is better).

> 
> Signed-off-by: softworkz <softworkz at hotmail.com>
> ---
>  fftools/textformat/avtextwriters.h | 2 +-
>  fftools/textformat/tw_avio.c       | 7 ++-----
>  fftools/textformat/tw_buffer.c     | 7 ++-----
>  fftools/textformat/tw_stdout.c     | 8 ++------
>  4 files changed, 7 insertions(+), 17 deletions(-)
> 
> diff --git a/fftools/textformat/avtextwriters.h b/fftools/textformat/avtextwriters.h
> index 34db3f1832..fd6da747eb 100644
> --- a/fftools/textformat/avtextwriters.h
> +++ b/fftools/textformat/avtextwriters.h
> @@ -41,7 +41,7 @@ typedef struct AVTextWriter {
>      void (*uninit)(AVTextWriterContext *wctx);
>      void (*writer_w8)(AVTextWriterContext *wctx, int b);
>      void (*writer_put_str)(AVTextWriterContext *wctx, const char *str);

> -    void (*writer_printf)(AVTextWriterContext *wctx, const char *fmt, ...);
> +    void (*writer_printf)(AVTextWriterContext *wctx, const char *fmt, va_list vl);

If you change the signature, change also the name (writer_vprintf) of
the callback to make it clear it takes a va_list.

>  } AVTextWriter;
>  
>  typedef struct AVTextWriterContext {
> diff --git a/fftools/textformat/tw_avio.c b/fftools/textformat/tw_avio.c
> index 29889598bb..7d52dc4cf5 100644
> --- a/fftools/textformat/tw_avio.c
> +++ b/fftools/textformat/tw_avio.c
> @@ -57,14 +57,11 @@ static void io_put_str(AVTextWriterContext *wctx, const char *str)
>      avio_write(ctx->avio_context, (const unsigned char *)str, (int)strlen(str));
>  }
>  
> -static void io_printf(AVTextWriterContext *wctx, const char *fmt, ...)
> +static void io_printf(AVTextWriterContext *wctx, const char *fmt, va_list vl)
>  {
>      IOWriterContext *ctx = wctx->priv;
> -    va_list ap;
>  
> -    va_start(ap, fmt);
> -    avio_vprintf(ctx->avio_context, fmt, ap);
> -    va_end(ap);
> +    avio_vprintf(ctx->avio_context, fmt, vl);
>  }
>  
>  
> diff --git a/fftools/textformat/tw_buffer.c b/fftools/textformat/tw_buffer.c
> index f8b38414a6..f861722247 100644
> --- a/fftools/textformat/tw_buffer.c
> +++ b/fftools/textformat/tw_buffer.c
> @@ -56,14 +56,11 @@ static void buffer_put_str(AVTextWriterContext *wctx, const char *str)
>      av_bprintf(ctx->buffer, "%s", str);
>  }
>  
> -static void buffer_printf(AVTextWriterContext *wctx, const char *fmt, ...)
> +static void buffer_printf(AVTextWriterContext *wctx, const char *fmt, va_list vl)
>  {
>      BufferWriterContext *ctx = wctx->priv;
>  
> -    va_list vargs;
> -    va_start(vargs, fmt);
> -    av_vbprintf(ctx->buffer, fmt, vargs);
> -    va_end(vargs);
> +    av_vbprintf(ctx->buffer, fmt, vl);
>  }
>  
>  
> diff --git a/fftools/textformat/tw_stdout.c b/fftools/textformat/tw_stdout.c
> index 23de6f671f..dace55f38a 100644
> --- a/fftools/textformat/tw_stdout.c
> +++ b/fftools/textformat/tw_stdout.c
> @@ -53,13 +53,9 @@ static inline void stdout_put_str(AVTextWriterContext *wctx, const char *str)
>      printf("%s", str);
>  }
>  
> -static inline void stdout_printf(AVTextWriterContext *wctx, const char *fmt, ...)
> +static inline void stdout_printf(AVTextWriterContext *wctx, const char *fmt, va_list vl)
>  {
> -    va_list ap;
> -
> -    va_start(ap, fmt);
> -    vprintf(fmt, ap);
> -    va_end(ap);
> +    vprintf(fmt, vl);
>  }
>  
>  
> -- 
> ffmpeg-codebot
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".


More information about the ffmpeg-devel mailing list