This is a preparation for the modules 'mbitern' and 'mbuitern':
2023-07-17 Bruno Haible <br...@clisp.org> mbchar: Reduce size of 'struct mbchar'. * modules/mbfile (configure.ac): Define GNULIB_MBFILE as an indicator. * lib/mbchar.h (MBCHAR_BUF_SIZE): Set to 4. (struct mbchar): Disable member 'buf' if the module 'mbfile' is not in use. diff --git a/lib/mbchar.h b/lib/mbchar.h index 82c373f47e..d1900b5a51 100644 --- a/lib/mbchar.h +++ b/lib/mbchar.h @@ -156,7 +156,9 @@ _GL_INLINE_HEADER_BEGIN # define MBCHAR_INLINE _GL_INLINE #endif -#define MBCHAR_BUF_SIZE 24 +/* The longest multibyte characters, nowadays, are 4 bytes long. + Regardless of the values of MB_CUR_MAX and MB_LEN_MAX. */ +#define MBCHAR_BUF_SIZE 4 struct mbchar { @@ -164,7 +166,9 @@ struct mbchar size_t bytes; /* number of bytes of current character, > 0 */ bool wc_valid; /* true if wc is a valid 32-bit wide character */ char32_t wc; /* if wc_valid: the current character */ +#if defined GNULIB_MBFILE char buf[MBCHAR_BUF_SIZE]; /* room for the bytes, used for file input only */ +#endif }; /* EOF (not a real character) is represented with bytes = 0 and diff --git a/modules/mbfile b/modules/mbfile index af3674ea79..09593fcc3f 100644 --- a/modules/mbfile +++ b/modules/mbfile @@ -18,6 +18,10 @@ stdbool configure.ac: gl_MBFILE +dnl Do not use gl_MODULE_INDICATOR([mbfile]) here: we don't want 'struct mbchar' +dnl to have a different size in lib/ than in tests/. +AC_DEFINE([GNULIB_MBFILE], [1], + [Define to 1 if the gnulib module 'mbfile' is in use.]) Makefile.am: lib_SOURCES += mbfile.h mbfile.c