git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Justin Tobler <jltobler@gmail.com>
Date
Mar 9, 2026, 15:33 UTC
Message-ID
<aa7nk37z9VkaiEyt@denethor>
In-Reply-To
<20260305-pks-gitlab-ci-macos-16-v1-1-ce8da0ff29c2@pks.im>
On 26/03/05 12:20PM, Patrick Steinhardt wrote:
Show 70 quoted lines
> 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 <ps@pks.im>
> ---
>  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
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 3 of 7 in “gitlab-ci: update to macOS 15 images”
  1. 0/3 gitlab-ci: update to macOS 15 imagesPatrick Steinhardt, Mar 5, 2026
  2. 1/3 meson: simplify iconv-emits-BOM checkPatrick Steinhardt, Mar 5, 2026
  3. Justin ToblerMar 9, 2026
  4. 2/3 meson: detect broken iconv that requires ICONV_RESTART_RESETPatrick Steinhardt, Mar 5, 2026
  5. Justin ToblerMar 9, 2026
  6. 3/3 gitlab-ci: update to macOS 15 imagesPatrick Steinhardt, Mar 5, 2026
  7. Justin ToblerMar 9, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.