Skip to content

Commit c96e8b9

Browse files
author
KJ Tsanaktsidis
committed
Fix misdetection of {crc32,alder32}_z in cloudflare zlib fork
We use the Cloudflare fork of zlib (https://github.com/cloudflare/zlib), which we find gives improved performance on AWS Graviton ARM instances. That fork does not define crc32_z and alder32_z functions. Until two days ago, Ruby's zlib gem worked fine, because cloudflare zlib _also_ did not define z_size_t, which meant Ruby did not try and use these functions. Since cloudflare/zlib@a3ba995 however, cloudflare zlib _does_ define z_size_t (but NOT crc32_z or alder32_z). The zlib gem would try and use these nonexistant functions and not compile. This patch fixes it by actually specifically detecting the functions that the gem wants to call, rather than just the presence of the z_size_t type.
1 parent 280a1b5 commit c96e8b9

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

ext/zlib/extconf.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,16 @@
120120
$defs << "-DHAVE_CRC32_COMBINE"
121121
$defs << "-DHAVE_ADLER32_COMBINE"
122122
$defs << "-DHAVE_TYPE_Z_CRC_T"
123-
$defs << "-DHAVE_TYPE_Z_SIZE_T"
123+
$defs << "-DHAVE_CRC32_Z"
124+
$defs << "-DHAVE_ADLER32_Z"
125+
$defs << "-DHAVE_ZLIB_SIZE_T_FUNCS"
124126
else
125127
have_func('crc32_combine', 'zlib.h')
126128
have_func('adler32_combine', 'zlib.h')
127129
have_type('z_crc_t', 'zlib.h')
128-
have_type('z_size_t', 'zlib.h')
130+
if have_func('crc32_z', 'zlib.h') && have_func('adler32_z', 'zlib.h')
131+
$defs << "-DHAVE_ZLIB_SIZE_T_FUNCS"
132+
end
129133
end
130134

131135
create_makefile('zlib') {|conf|

ext/zlib/zlib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#endif
4545
#endif
4646

47-
#if defined(HAVE_TYPE_Z_SIZE_T)
47+
#if defined(HAVE_ZLIB_SIZE_T_FUNCS)
4848
typedef uLong (*checksum_func)(uLong, const Bytef*, z_size_t);
4949
# define crc32 crc32_z
5050
# define adler32 adler32_z
@@ -388,7 +388,7 @@ rb_zlib_version(VALUE klass)
388388
# define mask32(x) (x)
389389
#endif
390390

391-
#if SIZEOF_LONG > SIZEOF_INT && !defined(HAVE_TYPE_Z_SIZE_T)
391+
#if SIZEOF_LONG > SIZEOF_INT && !defined(HAVE_ZLIB_SIZE_T_FUNCS)
392392
static uLong
393393
checksum_long(uLong (*func)(uLong, const Bytef*, uInt), uLong sum, const Bytef *ptr, long len)
394394
{

0 commit comments

Comments
 (0)