From 07acd6006c69370c7af4ca50221f1a8166d78e3f Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 2 Apr 2022 19:03:58 +0900 Subject: [PATCH] [ruby/zlib] Use `z_size_t` version functions https://github.com/ruby/zlib/commit/1ce6625fff --- ext/zlib/extconf.rb | 2 ++ ext/zlib/zlib.c | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ext/zlib/extconf.rb b/ext/zlib/extconf.rb index d674544f22..5477f49178 100644 --- a/ext/zlib/extconf.rb +++ b/ext/zlib/extconf.rb @@ -121,10 +121,12 @@ if have_zlib $defs << "-DHAVE_CRC32_COMBINE" $defs << "-DHAVE_ADLER32_COMBINE" $defs << "-DHAVE_TYPE_Z_CRC_T" + $defs << "-DHAVE_TYPE_Z_SIZE_T" else have_func('crc32_combine', 'zlib.h') have_func('adler32_combine', 'zlib.h') have_type('z_crc_t', 'zlib.h') + have_type('z_size_t', 'zlib.h') end create_makefile('zlib') {|conf| diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 70f422a124..20079a5d4c 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -44,6 +44,14 @@ #endif #endif +#if defined(HAVE_TYPE_Z_SIZE_T) +typedef uLong (*checksum_func)(uLong, const Bytef*, z_size_t); +# define crc32 crc32_z +# define adler32 adler32_z +#else +typedef uLong (*checksum_func)(uLong, const Bytef*, uInt); +#endif + #if SIZEOF_LONG > SIZEOF_INT static inline uInt max_uint(long n) @@ -65,7 +73,7 @@ static ID id_dictionaries, id_read, id_buffer; static NORETURN(void raise_zlib_error(int, const char*)); static VALUE rb_zlib_version(VALUE); -static VALUE do_checksum(int, VALUE*, uLong (*)(uLong, const Bytef*, uInt)); +static VALUE do_checksum(int, VALUE*, checksum_func); static VALUE rb_zlib_adler32(int, VALUE*, VALUE); static VALUE rb_zlib_crc32(int, VALUE*, VALUE); static VALUE rb_zlib_crc_table(VALUE); @@ -380,7 +388,7 @@ rb_zlib_version(VALUE klass) # define mask32(x) (x) #endif -#if SIZEOF_LONG > SIZEOF_INT +#if SIZEOF_LONG > SIZEOF_INT && !defined(HAVE_TYPE_Z_SIZE_T) static uLong checksum_long(uLong (*func)(uLong, const Bytef*, uInt), uLong sum, const Bytef *ptr, long len) { @@ -399,7 +407,7 @@ checksum_long(uLong (*func)(uLong, const Bytef*, uInt), uLong sum, const Bytef * #endif static VALUE -do_checksum(int argc, VALUE *argv, uLong (*func)(uLong, const Bytef*, uInt)) +do_checksum(int argc, VALUE *argv, checksum_func func) { VALUE str, vsum; unsigned long sum;