Commit def6ba0 for zlib

commit def6ba00c494eacb7ca77a06e9af4b895773c7d8
Author: Mark Adler <git@madler.net>
Date:   Wed Nov 11 11:30:26 2026 -0800

    Support the Z_U4 and Z_U8 types for Z_SOLO compiles.

    Before, Z_U4 and Z_U8 were determined using limits.h. However
    Z_SOLO is constrained to not use header files, so those compiles
    could not benefit from the speedups permitted by those types.

    Now they are determined first by looking for gcc and clang
    compiler-defined macros, and then the MSVC fixed sizes. Only if
    those bear no fruit does the determination fall back to limits.h.
    Z_SOLO then can benefit from faster code on the most commonly used
    compilers.

diff --git a/zconf.h b/zconf.h
index 3d308f6..352ec3b 100644
--- a/zconf.h
+++ b/zconf.h
@@ -426,6 +426,26 @@ typedef uLong FAR uLongf;
    typedef Byte       *voidp;
 #endif

+/* Find a four-byte unsigned integer type, Z_U4, for z_crc_t. Start with the
+   sizes that gcc, clang, and compatible compilers predefine. Then try MSVC's
+   fixed sizes. Lastly, use limits.h. The first two need no header, so they
+   work with Z_SOLO. */
+#if !defined(Z_U4) && defined(__CHAR_BIT__) && defined(__SIZEOF_SHORT__) && \
+    defined(__SIZEOF_INT__) && defined(__SIZEOF_LONG__)
+#  if __CHAR_BIT__ != 8
+#  elif __SIZEOF_INT__ == 4
+#    define Z_U4 unsigned
+#  elif __SIZEOF_LONG__ == 4
+#    define Z_U4 unsigned long
+#  elif __SIZEOF_SHORT__ == 4
+#    define Z_U4 unsigned short
+#  endif
+#endif
+#if !defined(Z_U4) && defined(_MSC_VER)
+#  if _MSC_VER >= 1400
+#    define Z_U4 unsigned
+#  endif
+#endif
 #if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
 #  include <limits.h>
 #  if (UINT_MAX == 0xffffffffUL)
diff --git a/zconf.h.in b/zconf.h.in
index 3d308f6..352ec3b 100644
--- a/zconf.h.in
+++ b/zconf.h.in
@@ -426,6 +426,26 @@ typedef uLong FAR uLongf;
    typedef Byte       *voidp;
 #endif

+/* Find a four-byte unsigned integer type, Z_U4, for z_crc_t. Start with the
+   sizes that gcc, clang, and compatible compilers predefine. Then try MSVC's
+   fixed sizes. Lastly, use limits.h. The first two need no header, so they
+   work with Z_SOLO. */
+#if !defined(Z_U4) && defined(__CHAR_BIT__) && defined(__SIZEOF_SHORT__) && \
+    defined(__SIZEOF_INT__) && defined(__SIZEOF_LONG__)
+#  if __CHAR_BIT__ != 8
+#  elif __SIZEOF_INT__ == 4
+#    define Z_U4 unsigned
+#  elif __SIZEOF_LONG__ == 4
+#    define Z_U4 unsigned long
+#  elif __SIZEOF_SHORT__ == 4
+#    define Z_U4 unsigned short
+#  endif
+#endif
+#if !defined(Z_U4) && defined(_MSC_VER)
+#  if _MSC_VER >= 1400
+#    define Z_U4 unsigned
+#  endif
+#endif
 #if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
 #  include <limits.h>
 #  if (UINT_MAX == 0xffffffffUL)
diff --git a/zutil.c b/zutil.c
index 6c01021..1c1ef95 100644
--- a/zutil.c
+++ b/zutil.c
@@ -10,6 +10,27 @@
 #  include "gzguts.h"
 #endif

+/* Check, when building zlib, that the sizes the compiler predefines, from
+   which Z_U4 and Z_U8 are found, agree with limits.h. */
+#if defined(STDC) && !defined(Z_SOLO) && defined(__CHAR_BIT__) && \
+    defined(__SIZEOF_SHORT__) && defined(__SIZEOF_INT__) && \
+    defined(__SIZEOF_LONG__)
+#  include <limits.h>
+#  if __CHAR_BIT__ != CHAR_BIT || \
+      (__SIZEOF_SHORT__ == 4) != (USHRT_MAX == 0xffffffffUL) || \
+      (__SIZEOF_INT__ == 4) != (UINT_MAX == 0xffffffffUL) || \
+      (__SIZEOF_LONG__ == 4) != (ULONG_MAX == 0xffffffffUL) || \
+      (__SIZEOF_INT__ == 8) != (UINT_MAX == 0xffffffffffffffff) || \
+      (__SIZEOF_LONG__ == 8) != (ULONG_MAX == 0xffffffffffffffff)
+#    error predefined integer sizes disagree with limits.h
+#  endif
+#  if defined(__SIZEOF_LONG_LONG__) && defined(ULLONG_MAX)
+#    if (__SIZEOF_LONG_LONG__ == 8) != (ULLONG_MAX == 0xffffffffffffffff)
+#      error predefined integer sizes disagree with limits.h
+#    endif
+#  endif
+#endif
+
 z_const char * const z_errmsg[10] = {
     (z_const char *)"need dictionary",     /* Z_NEED_DICT       2  */
     (z_const char *)"stream end",          /* Z_STREAM_END      1  */
diff --git a/zutil.h b/zutil.h
index 69ba8b4..9dc0007 100644
--- a/zutil.h
+++ b/zutil.h
@@ -46,6 +46,25 @@ typedef unsigned short ush;
 typedef ush FAR ushf;
 typedef unsigned long  ulg;

+/* Find an eight-byte unsigned integer type, Z_U8, the same way as Z_U4 in
+   zconf.h: first from the predefined sizes, then for MSVC, lastly from
+   limits.h. */
+#if !defined(Z_U8) && defined(__CHAR_BIT__) && defined(__SIZEOF_INT__) && \
+    defined(__SIZEOF_LONG__) && defined(__SIZEOF_LONG_LONG__)
+#  if __CHAR_BIT__ != 8
+#  elif __SIZEOF_LONG__ == 8
+#    define Z_U8 unsigned long
+#  elif __SIZEOF_LONG_LONG__ == 8
+#    define Z_U8 unsigned long long
+#  elif __SIZEOF_INT__ == 8
+#    define Z_U8 unsigned
+#  endif
+#endif
+#if !defined(Z_U8) && defined(_MSC_VER)
+#  if _MSC_VER >= 1400
+#    define Z_U8 unsigned long long
+#  endif
+#endif
 #if !defined(Z_U8) && !defined(Z_SOLO) && defined(STDC)
 #  include <limits.h>
 #  if (ULONG_MAX == 0xffffffffffffffff)