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;