Subject: Re: [PATCH 1/3] meson: simplify iconv-emits-BOM check

From: Justin Tobler <[email-masked]>
Date: Mon, 9 Mar 2026 10:33:42 -0500

On 26/03/05 12:20PM, Patrick Steinhardt wrote:
> Simplify the iconv-emits-BOM check that we have in Meson a bit by:
> 
>   - Dropping useless variables.
> 
>   - Casting the `inpos` pointer to `void *` instead of using a typedef
>     that depends on whether or not we use an old iconv library.
> 
> This overall condenses the code signficantly and makes it easier to
> follow.
> 
> Signed-off-by: Patrick Steinhardt <[email-masked]>
> ---
>  meson.build | 56 ++++++++++++++++++++------------------------------------
>  1 file changed, 20 insertions(+), 36 deletions(-)
> 
> diff --git a/meson.build b/meson.build
> index 4b536e0124..ee3d9ced92 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -1040,42 +1040,26 @@ if iconv.found()
>      have_old_iconv = true
>    endif
>  
> -  iconv_omits_bom_source = '''#
> -    #include <iconv.h>
> -
> -    int main(int argc, const char **argv)
> -    {
> -  '''
> -  if have_old_iconv
> -    iconv_omits_bom_source += '''
> -      typedef const char *iconv_ibp;
> -    '''
> -  else
> -    iconv_omits_bom_source += '''
> -      typedef char *iconv_ibp;
> -    '''
> -  endif
> -  iconv_omits_bom_source += '''
> -      int v;
> -      iconv_t conv;
> -      char in[] = "a"; iconv_ibp pin = in;
> -      char out[20] = ""; char *pout = out;
> -      size_t isz = sizeof in;
> -      size_t osz = sizeof out;
> -
> -      conv = iconv_open("UTF-16", "UTF-8");
> -      iconv(conv, &pin, &isz, &pout, &osz);
> -      iconv_close(conv);
> -      v = (unsigned char)(out[0]) + (unsigned char)(out[1]);
> -      return v != 0xfe + 0xff;
> -    }
> -  '''
> -
> -  if meson.can_run_host_binaries() and compiler.run(iconv_omits_bom_source,
> -    dependencies: iconv,
> -    name: 'iconv omits BOM',
> -  ).returncode() != 0
> -    libgit_c_args += '-DICONV_OMITS_BOM'
> +  if meson.can_run_host_binaries()
> +    if compiler.run('''
> +      #include <iconv.h>
> +
> +      int main(int argc, const char **argv)
> +      {
> +        char in[] = "a", *inpos = in;
> +        char out[20] = "", *outpos = out;
> +        size_t insz = sizeof(in), outsz = sizeof(out);
> +        iconv_t conv = iconv_open("UTF-16", "UTF-8");
> +        iconv(conv, (void *) &inpos, &insz, &outpos, &outsz);

Ok, we are able to avoid the typedefs used for pin/inpos by simply
casting to void *. This does indeed simplify how the program is
constructed while remaining functionally the same. Looks good.

-Justin