]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Native API changes: Remove adler32_z and crc32_z. api-cleanup 2295/head
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Tue, 12 May 2026 20:43:57 +0000 (22:43 +0200)
committerHans Kristian Rosbach <hk-git@circlestorm.org>
Sat, 16 May 2026 23:41:59 +0000 (01:41 +0200)
Promote adler32 and crc32 to use size_t len.
Add Symver to provide old functions to temporarily remain ABI compatible with older zlib-ng versions.
Implement proper Configure/CMake tests for new-style symver support.

CMakeLists.txt
adler32.c
configure
crc32.c
zbuild.h
zlib-ng.h.in
zlib-ng.map.in
zlib_name_mangling-ng.h.in

index 307159db9783d233496cb31b815d6e3a3f717caf..6b7a21252957f58b497d0c7c6f92dd93dcd2f192 100644 (file)
@@ -632,6 +632,25 @@ if(HAVE_ATTRIBUTE_ALIGNED)
     add_definitions(-DHAVE_ATTRIBUTE_ALIGNED)
 endif()
 
+#
+# Check for __attribute__((__symver__(x))) support in the compiler
+#
+if (UNIX AND NOT ZLIB_COMPAT AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME STREQUAL AIX)
+    check_c_source_compiles(
+        "
+        void foo(void);
+        __attribute__((__symver__(\"foo@VERS_1.0\"))) void foo(void) {}
+        int main(void) {
+            return 0;
+        }"
+        HAVE_ATTRIBUTE_SYMVER FAIL_REGEX "symver")
+    if(HAVE_ATTRIBUTE_SYMVER)
+        add_definitions(-DHAVE_SYMVER)
+    else()
+        message(WARNING "Unable to provide support for deprecated functions without '__attribute__((__symver__(x)))'")
+    endif()
+endif()
+
 #
 # Check for __builtin_assume_aligned(x,n) support in the compiler
 #
@@ -1432,9 +1451,6 @@ if(NOT DEFINED BUILD_SHARED_LIBS OR BUILD_SHARED_LIBS)
             set_target_properties(zlib-ng PROPERTIES COMPILE_FLAGS "-fno-semantic-interposition")
         endif()
         if(NOT APPLE AND NOT CMAKE_SYSTEM_NAME STREQUAL AIX)
-            if(NOT ZLIB_COMPAT)
-                add_definitions(-DHAVE_SYMVER)
-            endif()
             configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zlib${SUFFIX}.map.in
                 ${CMAKE_CURRENT_BINARY_DIR}/zlib${SUFFIX}.map @ONLY)
             set_target_properties(zlib-ng PROPERTIES LINK_FLAGS
index 054521df26a971a0de771436dd441a744c7019e5..b5922605b2b828b4721f435cdbfe14c1158265a7 100644 (file)
--- a/adler32.c
+++ b/adler32.c
@@ -8,28 +8,49 @@
 #include "adler32_p.h"
 
 #ifdef ZLIB_COMPAT
-unsigned long Z_EXPORT PREFIX(adler32_z)(unsigned long adler, const unsigned char *buf, size_t len) {
+unsigned long Z_EXPORT adler32_z(unsigned long adler, const unsigned char *buf, size_t len) {
     if (buf == NULL)
         return ADLER32_INITIAL_VALUE;
     return (unsigned long)FUNCTABLE_CALL(adler32)((uint32_t)adler, buf, len);
 }
-#else
-uint32_t Z_EXPORT PREFIX(adler32_z)(uint32_t adler, const unsigned char *buf, size_t len) {
+unsigned long Z_EXPORT adler32(unsigned long adler, const unsigned char *buf, unsigned int len) {
     if (buf == NULL)
         return ADLER32_INITIAL_VALUE;
-    return FUNCTABLE_CALL(adler32)(adler, buf, len);
+    return (unsigned long)FUNCTABLE_CALL(adler32)((uint32_t)adler, buf, len);
 }
 #endif
 
-/* ========================================================================= */
-#ifdef ZLIB_COMPAT
-unsigned long Z_EXPORT PREFIX(adler32)(unsigned long adler, const unsigned char *buf, unsigned int len) {
+#ifndef ZLIB_COMPAT
+#  if defined(HAVE_SYMVER)
+// Preferred function
+ZSYMVER_DEF("zng_adler32", "ZLIB_NG_2.4.0")
+uint32_t Z_EXPORT zng_adler32_sizet(uint32_t adler, const unsigned char *buf, size_t len) {
     if (buf == NULL)
         return ADLER32_INITIAL_VALUE;
-    return (unsigned long)FUNCTABLE_CALL(adler32)((uint32_t)adler, buf, len);
+    return FUNCTABLE_CALL(adler32)(adler, buf, len);
 }
-#else
-uint32_t Z_EXPORT PREFIX(adler32)(uint32_t adler, const unsigned char *buf, uint32_t len) {
+// Deprecated function
+ZSYMVER("zng_adler32", "ZLIB_NG_2.0.0")
+uint32_t Z_EXPORT zng_adler32_uint32(uint32_t adler, const unsigned char *buf, uint32_t len) {
+    if (buf == NULL)
+        return ADLER32_INITIAL_VALUE;
+    return FUNCTABLE_CALL(adler32)(adler, buf, len);
+}
+
+#  else
+//Fallback to preferred function
+uint32_t Z_EXPORT zng_adler32(uint32_t adler, const unsigned char *buf, size_t len) {
+    if (buf == NULL)
+        return ADLER32_INITIAL_VALUE;
+    return FUNCTABLE_CALL(adler32)(adler, buf, len);
+}
+#  endif
+
+#    ifdef zng_adler32_z
+#      undef zng_adler32_z
+#    endif
+// Deprecated function
+uint32_t Z_EXPORT zng_adler32_z(uint32_t adler, const unsigned char *buf, size_t len) {
     if (buf == NULL)
         return ADLER32_INITIAL_VALUE;
     return FUNCTABLE_CALL(adler32)(adler, buf, len);
index bb7156e545ee95544841f5f1e0b89e804fb20974..d4ccf13946a42840e71f97d36199504e3f6082f3 100755 (executable)
--- a/configure
+++ b/configure
@@ -617,22 +617,6 @@ else
   esac
 fi
 
-# Symbol versioning
-case "$uname" in
-  CYGWIN* | Cygwin* | cygwin* | MINGW* | mingw* | MSYS* | msys* | Darwin* | darwin*)
-    echo "Checking for Symbol versioning... No."
-  ;;
-  *)
-    if test $shared -eq 1; then
-      echo "Checking for Symbol versioning... Yes."
-      CFLAGS="${CFLAGS} -DHAVE_SYMVER"
-      SFLAGS="${SFLAGS} -DHAVE_SYMVER"
-    else
-      echo "Checking for Symbol versioning... No."
-    fi
-  ;;
-esac
-
 # Simplify some later conditionals
 LINUX=0
 FREEBSD=0
@@ -1164,6 +1148,24 @@ else
     echo "Checking for attribute(aligned) ... No." | tee -a configure.log
 fi
 
+# Check for attribute(symver) support in compiler
+cat > $test.c << EOF
+void foo(void);
+__attribute__((__symver__("foo@VERS_1.0"))) void foo(void) {}
+int main(void) {
+    return 0;
+}
+EOF
+if try ${CC} ${CFLAGS} $test.c $LDSHAREDLIBC; then
+    echo "Checking for attribute(symver) ... Yes." | tee -a configure.log
+    CFLAGS="$CFLAGS -DHAVE_SYMVER"
+    SFLAGS="$SFLAGS -DHAVE_SYMVER"
+else
+    echo "Checking for attribute(symver) ... No." | tee -a configure.log
+    echo "Warning: Unable to provide support for deprecated functions without '__attribute__((__symver__(x)))'" | tee -a configure.log
+
+fi
+
 # Check for __builtin_assume_aligned(x,n) support in compiler
 cat > $test.c << EOF
 char *test(char *buffer) {
diff --git a/crc32.c b/crc32.c
index cbc9ef0226f95f527917926300c28a43f7b1daae..bb7786906955ccbd79311a31040bde2a143aad3f 100644 (file)
--- a/crc32.c
+++ b/crc32.c
@@ -13,7 +13,7 @@
 
 /* ========================================================================= */
 
-const uint32_t * Z_EXPORT PREFIX(get_crc_table)(void) {
+Z_EXPORT const uint32_t * PREFIX(get_crc_table)(void) {
     return (const uint32_t *)crc_table;
 }
 
@@ -26,28 +26,51 @@ Z_INTERNAL uint32_t crc32_small(uint32_t crc, const uint8_t *buf, size_t len) {
     return ~crc32_copy_small(~crc, NULL, buf, len, 32, 0);
 }
 
+
 #ifdef ZLIB_COMPAT
-unsigned long Z_EXPORT PREFIX(crc32_z)(unsigned long crc, const unsigned char *buf, size_t len) {
+Z_EXPORT unsigned long crc32_z(unsigned long crc, const unsigned char *buf, size_t len) {
     if (buf == NULL)
         return CRC32_INITIAL_VALUE;
     return (unsigned long)FUNCTABLE_CALL(crc32)((uint32_t)crc, buf, len);
 }
-#else
-uint32_t Z_EXPORT PREFIX(crc32_z)(uint32_t crc, const unsigned char *buf, size_t len) {
+Z_EXPORT unsigned long crc32(unsigned long crc, const unsigned char *buf, unsigned int len) {
     if (buf == NULL)
         return CRC32_INITIAL_VALUE;
-    return FUNCTABLE_CALL(crc32)(crc, buf, len);
+    return (unsigned long)FUNCTABLE_CALL(crc32)((uint32_t)crc, buf, len);
 }
 #endif
 
-#ifdef ZLIB_COMPAT
-unsigned long Z_EXPORT PREFIX(crc32)(unsigned long crc, const unsigned char *buf, unsigned int len) {
+#ifndef ZLIB_COMPAT
+#  if defined(HAVE_SYMVER)
+// Preferred function
+ZSYMVER_DEF("zng_crc32", "ZLIB_NG_2.4.0")
+Z_EXPORT uint32_t zng_crc32_sizet(uint32_t crc, const unsigned char *buf, size_t len) {
     if (buf == NULL)
         return CRC32_INITIAL_VALUE;
-    return (unsigned long)FUNCTABLE_CALL(crc32)((uint32_t)crc, buf, len);
+    return FUNCTABLE_CALL(crc32)(crc, buf, len);
+}
+// Deprecated function
+ZSYMVER("zng_crc32", "ZLIB_NG_2.0.0")
+Z_EXPORT uint32_t zng_crc32_uint32(uint32_t crc, const unsigned char *buf, uint32_t len) {
+    if (buf == NULL)
+        return CRC32_INITIAL_VALUE;
+    return FUNCTABLE_CALL(crc32)(crc, buf, len);
+}
+
+#  else
+// Fallback to preferred function
+Z_EXPORT uint32_t zng_crc32(uint32_t crc, const unsigned char *buf, size_t len) {
+    if (buf == NULL)
+        return CRC32_INITIAL_VALUE;
+    return FUNCTABLE_CALL(crc32)(crc, buf, len);
 }
-#else
-uint32_t Z_EXPORT PREFIX(crc32)(uint32_t crc, const unsigned char *buf, uint32_t len) {
+#  endif
+
+#    ifdef zng_crc32_z
+#      undef zng_crc32_z
+#    endif
+// Deprecated function
+Z_EXPORT uint32_t zng_crc32_z(uint32_t crc, const unsigned char *buf, size_t len) {
     if (buf == NULL)
         return CRC32_INITIAL_VALUE;
     return FUNCTABLE_CALL(crc32)(crc, buf, len);
index 16a9d0d7741c07a1dce2227a4bad53e8c8305606..9f2e10dc37c7081163444df03c13edf67e69a234 100644 (file)
--- a/zbuild.h
+++ b/zbuild.h
  * This is only used for Zlib-ng native API, and only on platforms supporting this.
  */
 #if defined(HAVE_SYMVER)
-#  define ZSYMVER(func,alias,ver) __asm__(".symver " func ", " alias "@ZLIB_NG_" ver);
-#  define ZSYMVER_DEF(func,alias,ver) __asm__(".symver " func ", " alias "@@ZLIB_NG_" ver);
+#  define ZSYMVER(alias,ver) __attribute__((__symver__(alias "@" ver)))
+#  define ZSYMVER_DEF(alias,ver) __attribute__((__symver__(alias "@@" ver)))
 #else
-#  define ZSYMVER(func,alias,ver)
-#  define ZSYMVER_DEF(func,alias,ver)
+#  define ZSYMVER(alias,ver)
+#  define ZSYMVER_DEF(alias,ver)
 #endif
 
 #ifndef __cplusplus
index 79dc3c4f08b79fbad144b8be1e8e7bd068d1c270..6250f66b388a9b5cd80f0f6ef73ccda8b01b5bcf 100644 (file)
@@ -1689,7 +1689,7 @@ void zng_gzclearerr(gzFile file);
 */
 
 Z_EXTERN Z_EXPORT
-uint32_t zng_adler32(uint32_t adler, const uint8_t *buf, uint32_t len);
+uint32_t zng_adler32(uint32_t adler, const uint8_t *buf, size_t len);
 /*
      Update a running Adler-32 checksum with the bytes buf[0..len-1] and
    return the updated checksum. An Adler-32 value is in the range of a 32-bit
@@ -1709,12 +1709,6 @@ uint32_t zng_adler32(uint32_t adler, const uint8_t *buf, uint32_t len);
      if (adler != original_adler) error();
 */
 
-Z_EXTERN Z_EXPORT
-uint32_t zng_adler32_z(uint32_t adler, const uint8_t *buf, size_t len);
-/*
-     Same as adler32(), but with a size_t length.
-*/
-
 Z_EXTERN Z_EXPORT
 uint32_t zng_adler32_combine(uint32_t adler1, uint32_t adler2, z_off64_t len2);
 /*
@@ -1727,7 +1721,7 @@ uint32_t zng_adler32_combine(uint32_t adler1, uint32_t adler2, z_off64_t len2);
 */
 
 Z_EXTERN Z_EXPORT
-uint32_t zng_crc32(uint32_t crc, const uint8_t *buf, uint32_t len);
+uint32_t zng_crc32(uint32_t crc, const uint8_t *buf, size_t len);
 /*
      Update a running CRC-32 with the bytes buf[0..len-1] and return the
    updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer.
@@ -1745,12 +1739,6 @@ uint32_t zng_crc32(uint32_t crc, const uint8_t *buf, uint32_t len);
      if (crc != original_crc) error();
 */
 
-Z_EXTERN Z_EXPORT
-uint32_t zng_crc32_z(uint32_t crc, const uint8_t *buf, size_t len);
-/*
-     Same as crc32(), but with a size_t length.
-*/
-
 Z_EXTERN Z_EXPORT
 uint32_t zng_crc32_combine(uint32_t crc1, uint32_t crc2, z_off64_t len2);
 
@@ -1864,6 +1852,10 @@ Z_EXTERN Z_EXPORT int32_t          zng_deflateResetKeep (zng_stream *);
 Z_EXTERN Z_EXPORTVA int32_t zng_gzvprintf(gzFile file, const char *format, va_list va);
 #endif
 
+/* Aliases for backwards compatibility */
+#define zng_crc32_z @ZLIB_SYMBOL_PREFIX@zng_crc32
+#define zng_adler32_z @ZLIB_SYMBOL_PREFIX@zng_adler32
+
 #ifdef __cplusplus
 }
 #endif
index eed2aa66737ee178fdf803ed2cdf295b3e61bf06..f9e61a2820ec8fa196fcc89ab5772b4431563c00 100644 (file)
@@ -1,3 +1,8 @@
+ZLIB_NG_2.4.0 {
+    @ZLIB_SYMBOL_PREFIX@zng_adler32;
+    @ZLIB_SYMBOL_PREFIX@zng_crc32;
+};
+
 ZLIB_NG_2.1.0 {
   global:
     @ZLIB_SYMBOL_PREFIX@zng_deflateInit;
index e90904a7375dd5074226323c17727fdbbb07e6e5..241af3087a7f8c89b73caddb37440bbff0b10812 100644 (file)
@@ -17,7 +17,6 @@
 #define zng_adler32               @ZLIB_SYMBOL_PREFIX@zng_adler32
 #define zng_adler32_combine       @ZLIB_SYMBOL_PREFIX@zng_adler32_combine
 #define zng_adler32_combine64     @ZLIB_SYMBOL_PREFIX@zng_adler32_combine64
-#define zng_adler32_z             @ZLIB_SYMBOL_PREFIX@zng_adler32_z
 #define zng_compress              @ZLIB_SYMBOL_PREFIX@zng_compress
 #define zng_compress2             @ZLIB_SYMBOL_PREFIX@zng_compress2
 #define zng_compressBound         @ZLIB_SYMBOL_PREFIX@zng_compressBound
@@ -27,7 +26,6 @@
 #define zng_crc32_combine_gen     @ZLIB_SYMBOL_PREFIX@zng_crc32_combine_gen
 #define zng_crc32_combine_gen64   @ZLIB_SYMBOL_PREFIX@zng_crc32_combine_gen64
 #define zng_crc32_combine_op      @ZLIB_SYMBOL_PREFIX@zng_crc32_combine_op
-#define zng_crc32_z               @ZLIB_SYMBOL_PREFIX@zng_crc32_z
 #define zng_deflate               @ZLIB_SYMBOL_PREFIX@zng_deflate
 #define zng_deflateBound          @ZLIB_SYMBOL_PREFIX@zng_deflateBound
 #define zng_deflateCopy           @ZLIB_SYMBOL_PREFIX@zng_deflateCopy