]> Savannah Git Hosting - gnulib.git/commitdiff
mbchar: Reduce size of 'struct mbchar'.
authorBruno Haible <bruno@clisp.org>
Mon, 17 Jul 2023 17:11:38 +0000 (19:11 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 17 Jul 2023 17:11:38 +0000 (19:11 +0200)
* 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.

ChangeLog
lib/mbchar.h
modules/mbfile

index 5ec78e6bd484e60fc856de3ccdc3d6dabcb0a52e..b6a3321d7a0f6509818218ed3975f9b6aaf9539d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-07-17  Bruno Haible  <bruno@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.
+
 2023-07-17  Bruno Haible  <bruno@clisp.org>
 
        mbszero: Fix for Minix.
index 82c373f47ed1cc62342316867c289d9abcf23fd9..d1900b5a5173d00d27b11d58659ef2fc5735cf5d 100644 (file)
@@ -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
index af3674ea7907711cf5662247a50ce2848d7fd353..09593fcc3f9b65cc16c9e05aafa73d3845f6fb18 100644 (file)
@@ -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