なかだです。

ついでに、1.7対応のパッチです。あと、host_osじゃなくてtarget_os
じゃないとまずいと思います。
即席なのであんまりテストしてありませんが、参考までに。


diff -u2p ruby-zlib-0.4.0.orig/extconf.rb ruby-zlib-0.4.0/extconf.rb --- ruby-zlib-0.4.0.orig/extconf.rb Sat Jul 15 18:24:46 2000 +++ ruby-zlib-0.4.0/extconf.rb Tue Dec 25 00:53:12 2001 @@ -9,5 +9,5 @@ if have_library('z', 'deflateReset') and # I don't know whether or not this code works correctly on your platform... - case CONFIG['host_os'] + case CONFIG['target_os'] when 'os2_emx' print "OS/2\n" @@ -22,4 +22,6 @@ if have_library('z', 'deflateReset') and print "Unix\n" end + + $CPPFLAGS += " -DHAVE_OBJECT_ALLOCATE" if Object.respond_to? :allocate puts("** Attention:", diff -u2p ruby-zlib-0.4.0.orig/zlib.c ruby-zlib-0.4.0/zlib.c --- ruby-zlib-0.4.0.orig/zlib.c Tue Sep 26 14:47:02 2000 +++ ruby-zlib-0.4.0/zlib.c Tue Dec 25 01:28:47 2001 @@ -30,4 +30,9 @@ #endif +#ifdef StringValuePtr +#define StringPtrLen(str, p, l) ((p) = StringValuePtr(str), (l) = RSTRING(str)->len) +#else +#define StringPtrLen(str, p, l) (p) = str2cstr(str, &(l)) +#endif @@ -37,5 +42,9 @@ static VALUE cStreamError, cDataError, c +#if RUBY_VERSION_CODE < 170 static void raise_zlib_error(int err, const char *msg) NORETURN; +#else +NORETURN(static void raise_zlib_error(int err, const char *msg)); +#endif static void raise_zlib_error(int err, const char *msg) @@ -86,5 +95,5 @@ static VALUE do_checksum(int argc, VALUE if (!NIL_P(str)) { - buf = str2cstr(str, &len); + StringPtrLen(str, buf, len); } else { buf = Z_NULL; @@ -275,6 +284,6 @@ static VALUE zstream_shift_buffer(struct z->buf_filled); z->stream.next_out = RSTRING(z->buf)->ptr + z->buf_filled; - z->stream.avail_out = (z->buf_filled < ZSTREAM_AVAIL_OUT_STEP) ? - z->buf_filled : ZSTREAM_AVAIL_OUT_STEP; + if ((z->stream.avail_out = RSTRING(z->buf)->len - z->buf_filled) > ZSTREAM_AVAIL_OUT_STEP) + z->stream.avail_out = ZSTREAM_AVAIL_OUT_STEP; return dst; @@ -418,5 +427,5 @@ static void zstream_run(struct zstream * z->stream.avail_in = 0; } else { - z->stream.next_in = str2cstr(src, &n); + StringPtrLen(src, z->stream.next_in, n); /* the type of z->stream.avail_in may not be int. */ z->stream.avail_in = n; @@ -584,4 +593,14 @@ static int value_to_flush(VALUE val) +#ifdef HAVE_OBJECT_ALLOCATE +static VALUE rb_zstream_s_allocate(VALUE klass) +{ + struct zstream *z; + return DATA_MAKE_ZSTREAM(klass, z); +} +#endif + + + static void deflate_init(struct zstream *z, int level) { @@ -620,7 +639,14 @@ VALUE rb_deflate_s_deflate(int argc, VAL +#ifdef HAVE_OBJECT_ALLOCATE +VALUE rb_deflate_initialize(int argc, VALUE *argv, VALUE dst) +#else VALUE rb_deflate_s_new(int argc, VALUE *argv, VALUE klass) +#endif { - VALUE v_level, v_wbits, v_memlevel, v_strategy, dst; + VALUE v_level, v_wbits, v_memlevel, v_strategy; +#ifndef HAVE_OBJECT_ALLOCATE + VALUE dst; +#endif int level, wbits, memlevel, strategy; int err; @@ -631,5 +657,9 @@ VALUE rb_deflate_s_new(int argc, VALUE * level = value_to_compression_level(v_level); +#ifdef HAVE_OBJECT_ALLOCATE + Data_Get_Struct(dst, struct zstream, z); +#else dst = DATA_MAKE_ZSTREAM(klass, z); +#endif if (argc <= 1) { @@ -757,5 +787,5 @@ VALUE rb_deflate_set_dictionary(VALUE ob int err; - dic = str2cstr(v_dic, &diclen); + StringPtrLen(v_dic, dic, diclen); err = deflateSetDictionary(&z->stream, dic, diclen); if (err != Z_OK) @@ -809,7 +839,14 @@ VALUE rb_inflate_s_inflate(VALUE obj, VA +#ifdef HAVE_OBJECT_ALLOCATE +VALUE rb_inflate_initialize(int argc, VALUE *argv, VALUE dst) +#else VALUE rb_inflate_s_new(int argc, VALUE *argv, VALUE klass) +#endif { - VALUE v_wbits, dst; + VALUE v_wbits; +#ifndef HAVE_OBJECT_ALLOCATE + VALUE dst; +#endif int wbits; int err; @@ -818,5 +855,9 @@ VALUE rb_inflate_s_new(int argc, VALUE * rb_scan_args(argc, argv, "01", &v_wbits); +#ifdef HAVE_OBJECT_ALLOCATE + Data_Get_Struct(dst, struct zstream, z); +#else dst = DATA_MAKE_ZSTREAM(klass, z); +#endif if (argc == 0) { @@ -849,5 +890,5 @@ VALUE rb_inflate_inflate(VALUE obj, VALU dst = zstream_detach_buffer(z); else { - p = str2cstr(src, &len); + StringPtrLen(src, p, len); zstream_append_buffer(z, p, len); dst = rb_str_new(0, 0); @@ -879,5 +920,5 @@ VALUE rb_inflate_addstr(VALUE obj, VALUE if (z->flag & ZSTREAM_FLAG_FINISHED) { if (!NIL_P(src)) { - p = str2cstr(src, &len); + StringPtrLen(src, p, len); zstream_append_buffer(z, p, len); } @@ -933,5 +974,5 @@ VALUE rb_inflate_set_dictionary(VALUE ob int err; - dic = str2cstr(v_dic, &diclen); + StringPtrLen(v_dic, dic, diclen); err = inflateSetDictionary(&z->stream, dic, diclen); if (err != Z_OK) @@ -1083,4 +1124,12 @@ void gzip_free(struct gzfile *gz) Data_Make_Struct((klass), struct gzfile, gzip_mark, gzip_free, (gz)) +#ifdef HAVE_OBJECT_ALLOCATE +static VALUE +gzfile_s_allocate(VALUE klass) +{ + struct gzfile *gz; + return DATA_MAKE_GZFILE(klass, gz); +} +#endif @@ -1546,8 +1595,15 @@ static void gzipwriter_close(struct gzfi +#ifdef HAVE_OBJECT_ALLOCATE +static VALUE gzipwriter_new(VALUE dst, VALUE io, + VALUE v_level, VALUE v_strategy) +#else static VALUE gzipwriter_new(VALUE klass, VALUE io, VALUE v_level, VALUE v_strategy) +#endif { +#ifndef HAVE_OBJECT_ALLOCATE VALUE dst; +#endif int level, strategy; int err; @@ -1557,5 +1613,9 @@ static VALUE gzipwriter_new(VALUE klass, strategy = value_to_strategy(v_strategy); +#ifdef HAVE_OBJECT_ALLOCATE + Data_Get_Struct(dst, struct gzfile, gz); +#else dst = DATA_MAKE_GZFILE(klass, gz); +#endif GZIPWRITER_INIT(gz, io); gz->level = level; @@ -1594,11 +1654,21 @@ VALUE rb_gzipwriter_s_open(int argc, VAL +#ifdef HAVE_OBJECT_ALLOCATE +VALUE rb_gzipreader_s_new(VALUE dst, VALUE io) +#else VALUE rb_gzipreader_s_new(VALUE klass, VALUE io) +#endif { +#ifndef HAVE_OBJECT_ALLOCATE VALUE dst; +#endif int err; struct gzfile *gz; +#ifdef HAVE_OBJECT_ALLOCATE + Data_Get_Struct(dst, struct gzfile, gz); +#else dst = DATA_MAKE_GZFILE(klass, gz); +#endif GZIPREADER_INIT(gz, io); @@ -2177,7 +2247,11 @@ void Init_zlib() rb_define_module_function(mZlib, "crc_table", rb_zlib_crc_table, 0); - cZStream = rb_define_class_under(mZlib, "ZStream", rb_cObject); + cZStream = rb_define_class_under(mZlib, "ZStream", rb_cData); +#ifdef HAVE_OBJECT_ALLOCATE + rb_define_singleton_method(cZStream, "allocate", rb_zstream_s_allocate, 0); +#else rb_undef_method(CLASS_OF(cZStream), "new"); +#endif rb_define_method(cZStream, "total_in", rb_zstream_total_in, 0); rb_define_method(cZStream, "total_out", rb_zstream_total_out, 0); @@ -2202,5 +2276,9 @@ void Init_zlib() rb_deflate_s_deflate, -1); +#ifdef HAVE_OBJECT_ALLOCATE + rb_define_method(cDeflate, "initialize", rb_deflate_initialize, -1); +#else rb_define_singleton_method(cDeflate, "new", rb_deflate_s_new, -1); +#endif rb_define_method(cDeflate, "clone", rb_deflate_clone, 0); rb_define_method(cDeflate, "deflate", rb_deflate_deflate, -1); @@ -2237,5 +2315,9 @@ void Init_zlib() rb_inflate_s_inflate, 1); +#ifdef HAVE_OBJECT_ALLOCATE + rb_define_method(cInflate, "initialize", rb_inflate_initialize, -1); +#else rb_define_singleton_method(cInflate, "new", rb_inflate_s_new, -1); +#endif rb_define_method(cInflate, "inflate", rb_inflate_inflate, 1); rb_define_method(cInflate, "<<", rb_inflate_addstr, 1); @@ -2256,5 +2338,8 @@ void Init_zlib() id_close = rb_intern("close"); - cGzip = rb_define_class_under(mZlib, "Gzip", rb_cObject); + cGzip = rb_define_class_under(mZlib, "Gzip", rb_cData); +#ifdef HAVE_OBJECT_ALLOCATE + rb_define_singleton_method(cGzip, "allocate", gzfile_s_allocate, 0); +#endif cGzError = rb_define_class_under(cGzip, "Error", cZError); @@ -2280,10 +2365,18 @@ void Init_zlib() rb_define_method(cGzipReader, "eof?", rb_gzip_eof_p, 0); +#ifdef HAVE_OBJECT_ALLOCATE + rb_define_method(cGzipWriter, "initialize", rb_gzipwriter_s_new, -1); +#else rb_define_singleton_method(cGzipWriter, "new", rb_gzipwriter_s_new, -1); +#endif rb_define_singleton_method(cGzipWriter, "open", rb_gzipwriter_s_open, -1); +#ifdef HAVE_OBJECT_ALLOCATE + rb_define_method(cGzipReader, "initialize", rb_gzipreader_s_new, 1); +#else rb_define_singleton_method(cGzipReader, "new", rb_gzipreader_s_new, 1); +#endif rb_define_singleton_method(cGzipReader, "open", rb_gzipreader_s_open, 1);
-- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦