diff options
Diffstat (limited to 'ext/zlib/zlib.c')
-rw-r--r-- | ext/zlib/zlib.c | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index be5f148bcd..fe03072576 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -25,7 +25,7 @@ # define VALGRIND_MAKE_MEM_UNDEFINED(p, n) 0 #endif -#define RUBY_ZLIB_VERSION "2.1.1" +#define RUBY_ZLIB_VERSION "3.1.0" #ifndef RB_PASS_CALLED_KEYWORDS # define rb_class_new_instance_kw(argc, argv, klass, kw_splat) rb_class_new_instance(argc, argv, klass) @@ -44,6 +44,14 @@ #endif #endif +#if defined(HAVE_ZLIB_SIZE_T_FUNCS) +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); @@ -374,26 +382,32 @@ rb_zlib_version(VALUE klass) return rb_str_new2(zlibVersion()); } -#if SIZEOF_LONG > SIZEOF_INT +#if SIZEOF_LONG * CHAR_BIT > 32 +# define mask32(x) ((x) & 0xffffffff) +#else +# define mask32(x) (x) +#endif + +#if SIZEOF_LONG > SIZEOF_INT && !defined(HAVE_ZLIB_SIZE_T_FUNCS) static uLong checksum_long(uLong (*func)(uLong, const Bytef*, uInt), uLong sum, const Bytef *ptr, long len) { if (len > UINT_MAX) { do { - sum = func(sum, ptr, UINT_MAX); + sum = func(mask32(sum), ptr, UINT_MAX); ptr += UINT_MAX; len -= UINT_MAX; } while (len >= UINT_MAX); } - if (len > 0) sum = func(sum, ptr, (uInt)len); + if (len > 0) sum = func(mask32(sum), ptr, (uInt)len); return sum; } #else -#define checksum_long(func, sum, ptr, len) (func)((sum), (ptr), (len)) +#define checksum_long(func, sum, ptr, len) (func)(mask32(sum), (ptr), (len)) #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; @@ -411,7 +425,7 @@ do_checksum(int argc, VALUE *argv, uLong (*func)(uLong, const Bytef*, uInt)) } if (NIL_P(str)) { - sum = func(sum, Z_NULL, 0); + sum = func(mask32(sum), Z_NULL, 0); } else if (rb_obj_is_kind_of(str, rb_cIO)) { VALUE buf; @@ -461,7 +475,7 @@ rb_zlib_adler32(int argc, VALUE *argv, VALUE klass) * * call-seq: Zlib.adler32_combine(adler1, adler2, len2) * - * Combine two Adler-32 check values in to one. +alder1+ is the first Adler-32 + * Combine two Adler-32 check values in to one. +adler1+ is the first Adler-32 * value, +adler2+ is the second Adler-32 value. +len2+ is the length of the * string used to generate +adler2+. * @@ -909,7 +923,7 @@ zstream_discard_input(struct zstream *z, long len) z->input = Qnil; } else { - z->input = rb_str_substr(z->input, len, + z->input = rb_str_subseq(z->input, len, RSTRING_LEN(z->input) - len); } } @@ -3486,6 +3500,9 @@ static VALUE rb_gzfile_eof_p(VALUE obj) { struct gzfile *gz = get_gzfile(obj); + while (!ZSTREAM_IS_FINISHED(&gz->z) && ZSTREAM_BUF_FILLED(&gz->z) == 0) { + gzfile_read_more(gz, Qnil); + } return GZFILE_IS_FINISHED(gz) ? Qtrue : Qfalse; } |