From 5488f0b2caf7d080682a65001ae8c5d1732ab554 Mon Sep 17 00:00:00 2001 From: Gautham <41098605+ahgamut@users.noreply.github.com> Date: Fri, 3 May 2024 10:07:25 -0500 Subject: [PATCH] Remove zlib namespacing (#1142) We have an optimized version of zlib from the Chromium project. We need it for a lot of our libc services. It would be nice to export this to user applications if we can, since projects like llamafile are already depending on it under the private namespace, to avoid needing to link zlib twice. --- test/libc/runtime/zipos_test.c | 6 +++--- third_party/musl/pwd.c | 6 +++--- third_party/zip/crc32.h | 2 +- third_party/zip/zipfile.c | 10 +++++----- third_party/zlib/zconf.h | 4 ++++ 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/test/libc/runtime/zipos_test.c b/test/libc/runtime/zipos_test.c index 621c3bbea..a8bae2c23 100644 --- a/test/libc/runtime/zipos_test.c +++ b/test/libc/runtime/zipos_test.c @@ -33,9 +33,9 @@ __static_yoink("zipos"); __static_yoink("libc/testlib/hyperion.txt"); -__static_yoink("_Cz_inflate"); -__static_yoink("_Cz_inflateInit2"); -__static_yoink("_Cz_inflateEnd"); +__static_yoink("inflate"); +__static_yoink("inflateInit2"); +__static_yoink("inflateEnd"); void *Worker(void *arg) { int i, fd; diff --git a/third_party/musl/pwd.c b/third_party/musl/pwd.c index fc54b77cf..b43267e26 100644 --- a/third_party/musl/pwd.c +++ b/third_party/musl/pwd.c @@ -45,9 +45,9 @@ __static_yoink("musl_libc_notice"); // something as substantive as this library, then we shall assume the // application is meaty enough to benefit from the performance of the // chromium zlib library (costs ~40kb binary) versus just having puff -__static_yoink("_Cz_inflateInit2"); -__static_yoink("_Cz_inflate"); -__static_yoink("_Cz_inflateEnd"); +__static_yoink("inflateInit2"); +__static_yoink("inflate"); +__static_yoink("inflateEnd"); #endif static char * diff --git a/third_party/zip/crc32.h b/third_party/zip/crc32.h index 83af2404c..dbf31c19b 100644 --- a/third_party/zip/crc32.h +++ b/third_party/zip/crc32.h @@ -31,7 +31,7 @@ #ifndef USE_ZLIB ZCONST ulg near *get_crc_table OF((void)); #endif -#if (defined(USE_ZLIB) || defined(CRC_TABLE_ONLY)) +#if (1 || defined(USE_ZLIB) || defined(CRC_TABLE_ONLY)) # ifdef IZ_CRC_BE_OPTIMIZ # undef IZ_CRC_BE_OPTIMIZ # endif diff --git a/third_party/zip/zipfile.c b/third_party/zip/zipfile.c index 7b923b80e..1c2987971 100644 --- a/third_party/zip/zipfile.c +++ b/third_party/zip/zipfile.c @@ -72,7 +72,7 @@ #include "libc/nt/winsock.h" #endif -unsigned _Cz_crc32(unsigned crc, const unsigned char *buf, unsigned len); +unsigned crc32(unsigned crc, const unsigned char *buf, unsigned len); /* * XXX start of zipfile.h @@ -867,7 +867,7 @@ local void read_Unicode_Path_entry(pZipListEntry) } strcpy(iname, pZipListEntry->iname); - chksum = _Cz_crc32(chksum, (uch *)(iname), strlen(iname)); + chksum = crc32(chksum, (uch *)(iname), strlen(iname)); free(iname); @@ -972,7 +972,7 @@ local void read_Unicode_Path_local_entry(pZipListEntry) } strcpy(iname, pZipListEntry->iname); - chksum = _Cz_crc32(chksum, (uch *)(iname), strlen(iname)); + chksum = crc32(chksum, (uch *)(iname), strlen(iname)); free(iname); @@ -1558,7 +1558,7 @@ local int add_Unicode_Path_local_extra_field(pZEntry) # define inameLocal (pZEntry->iname) #endif - chksum = _Cz_crc32(chksum, (uch *)(inameLocal), strlen(inameLocal)); + chksum = crc32(chksum, (uch *)(inameLocal), strlen(inameLocal)); #ifdef WIN32_OEM free(inameLocal); @@ -1685,7 +1685,7 @@ local int add_Unicode_Path_cen_extra_field(pZEntry) # define inameLocal (pZEntry->iname) #endif - chksum = _Cz_crc32(chksum, (uch *)(inameLocal), strlen(inameLocal)); + chksum = crc32(chksum, (uch *)(inameLocal), strlen(inameLocal)); #ifdef WIN32_OEM free(inameLocal); diff --git a/third_party/zlib/zconf.h b/third_party/zlib/zconf.h index 3351fe91a..d8e097b2f 100644 --- a/third_party/zlib/zconf.h +++ b/third_party/zlib/zconf.h @@ -13,6 +13,7 @@ #define z_const const +#if 0 #define Z_COSMO_PREFIX_SET #define Bytef _Cz_Bytef @@ -162,6 +163,9 @@ #define zlibCompileFlags _Cz_zlibCompileFlags #define zlibVersion _Cz_zlibVersion +#pragma message "zconf is included, so zlibVersion should be renamed" + +#endif typedef unsigned char Byte; typedef unsigned int uInt; /* 16 bits or more */