[#28337] constant look up order in CVS HEAD — Yukihiro Matsumoto <matz@...>

まつもと ゆきひろです

15 messages 2006/02/18
[#28338] Re: constant look up order in CVS HEAD — Tanaka Akira <akr@...17n.org> 2006/02/19

In article <1140229116.805371.31930.nullmailer@x31.priv.netlab.jp>,

[#28341] Re: constant look up order in CVS HEAD — GOTOU Yuuzou <gotoyuzo@...> 2006/02/19

In message <87lkw8xfay.fsf@m17n.org>,

[#28342] Re: constant look up order in CVS HEAD — Yukihiro Matsumoto <matz@...> 2006/02/19

まつもと ゆきひろです

[ruby-dev:28309] Re: SEGV with zlib

From: Yukihiro Matsumoto <matz@...>
Date: 2006-02-07 02:14:57 UTC
List: ruby-dev #28309
まつもと ゆきひろです

In message "Re: [ruby-dev:28308] Re: SEGV with zlib"
    on Mon, 6 Feb 2006 22:46:45 +0900, Yukihiro Matsumoto <matz@ruby-lang.org> writes:

|私はそれでよいと思います。finalizerでフラッシュするのは親切ですが、
|インタプリタを落としたり、GCが遅くなったりする問題を導入するほどでは
|ないと思います。

パッチを作るならこんな感じでしょうか。ついでに大量のwarnigを
消しています。本質は「#if 0」のところだけ。

Index: ext/zlib/zlib.c
===================================================================
RCS file: /var/cvs/src/ruby/ext/zlib/zlib.c,v
retrieving revision 1.29
diff -p -u -1 -r1.29 zlib.c
--- ext/zlib/zlib.c	14 Dec 2005 16:37:24 -0000	1.29
+++ ext/zlib/zlib.c	7 Feb 2006 02:14:27 -0000
@@ -47,3 +47,3 @@ static void zstream_expand_buffer _((str
 static void zstream_expand_buffer_into _((struct zstream*, int));
-static void zstream_append_buffer _((struct zstream*, const char*, int));
+static void zstream_append_buffer _((struct zstream*, const Bytef*, int));
 static VALUE zstream_detach_buffer _((struct zstream*));
@@ -51,3 +51,3 @@ static VALUE zstream_shift_buffer _((str
 static void zstream_buffer_ungetc _((struct zstream*, int));
-static void zstream_append_input _((struct zstream*, const char*, unsigned int));
+static void zstream_append_input _((struct zstream*, const Bytef*, unsigned int));
 static void zstream_discard_input _((struct zstream*, unsigned int));
@@ -286,3 +286,3 @@ do_checksum(argc, argv, func)
 	StringValue(str);
-	sum = func(sum, RSTRING(str)->ptr, RSTRING(str)->len);
+	sum = func(sum, (Bytef*)RSTRING(str)->ptr, RSTRING(str)->len);
     }
@@ -441,3 +441,3 @@ zstream_expand_buffer(z)
 	z->buf_filled = 0;
-	z->stream.next_out = RSTRING(z->buf)->ptr;
+	z->stream.next_out = (Bytef*)RSTRING(z->buf)->ptr;
 	z->stream.avail_out = ZSTREAM_INITIAL_BUFSIZE;
@@ -460,3 +460,3 @@ zstream_expand_buffer(z)
     }
-    z->stream.next_out = RSTRING(z->buf)->ptr + z->buf_filled;
+    z->stream.next_out = (Bytef*)RSTRING(z->buf)->ptr + z->buf_filled;
 }
@@ -473,3 +473,3 @@ zstream_expand_buffer_into(z, size)
 	z->buf_filled = 0;
-	z->stream.next_out = RSTRING(z->buf)->ptr;
+	z->stream.next_out = (Bytef*)RSTRING(z->buf)->ptr;
 	z->stream.avail_out = size;
@@ -479,3 +479,3 @@ zstream_expand_buffer_into(z, size)
 	rb_str_resize(z->buf, z->buf_filled + size);
-	z->stream.next_out = RSTRING(z->buf)->ptr + z->buf_filled;
+	z->stream.next_out = (Bytef*)RSTRING(z->buf)->ptr + z->buf_filled;
 	z->stream.avail_out = size;
@@ -487,3 +487,3 @@ zstream_append_buffer(z, src, len)
     struct zstream *z;
-    const char *src;
+    const Bytef *src;
     int len;
@@ -492,5 +492,5 @@ zstream_append_buffer(z, src, len)
 	z->buf = rb_str_buf_new(len);
-	rb_str_buf_cat(z->buf, src, len);
+	rb_str_buf_cat(z->buf, (char*)src, len);
 	z->buf_filled = len;
-	z->stream.next_out = RSTRING(z->buf)->ptr;
+	z->stream.next_out = (Bytef*)RSTRING(z->buf)->ptr;
 	z->stream.avail_out = 0;
@@ -514,3 +514,3 @@ zstream_append_buffer(z, src, len)
     z->buf_filled += len;
-    z->stream.next_out = RSTRING(z->buf)->ptr + z->buf_filled;
+    z->stream.next_out = (Bytef*)RSTRING(z->buf)->ptr + z->buf_filled;
 }
@@ -518,3 +518,3 @@ zstream_append_buffer(z, src, len)
 #define zstream_append_buffer2(z,v) \
-    zstream_append_buffer((z),RSTRING(v)->ptr,RSTRING(v)->len)
+    zstream_append_buffer((z),(Bytef*)RSTRING(v)->ptr,RSTRING(v)->len)
 
@@ -558,3 +558,3 @@ zstream_shift_buffer(z, len)
 	    z->buf_filled);
-    z->stream.next_out = RSTRING(z->buf)->ptr + z->buf_filled;
+    z->stream.next_out = (Bytef*)RSTRING(z->buf)->ptr + z->buf_filled;
     z->stream.avail_out = RSTRING(z->buf)->len - z->buf_filled;
@@ -588,3 +588,3 @@ zstream_append_input(z, src, len)
     struct zstream *z;
-    const char *src;
+    const Bytef *src;
     unsigned int len;
@@ -595,3 +595,3 @@ zstream_append_input(z, src, len)
 	z->input = rb_str_buf_new(len);
-	rb_str_buf_cat(z->input, src, len);
+	rb_str_buf_cat(z->input, (char*)src, len);
 	RBASIC(z->input)->klass = 0;
@@ -599,3 +599,3 @@ zstream_append_input(z, src, len)
     else {
-	rb_str_buf_cat(z->input, src, len);
+	rb_str_buf_cat(z->input, (char*)src, len);
     }
@@ -604,3 +604,3 @@ zstream_append_input(z, src, len)
 #define zstream_append_input2(z,v)\
-    zstream_append_input((z), RSTRING(v)->ptr, RSTRING(v)->len)
+    zstream_append_input((z), (Bytef*)RSTRING(v)->ptr, RSTRING(v)->len)
 
@@ -714,3 +714,3 @@ zstream_run(z, src, len, flush)
     if (NIL_P(z->input) && len == 0) {
-	z->stream.next_in = "";
+	z->stream.next_in = (Bytef*)"";
 	z->stream.avail_in = 0;
@@ -719,3 +719,3 @@ zstream_run(z, src, len, flush)
 	zstream_append_input(z, src, len);
-	z->stream.next_in = RSTRING(z->input)->ptr;
+	z->stream.next_in = (Bytef*)RSTRING(z->input)->ptr;
 	z->stream.avail_in = RSTRING(z->input)->len;
@@ -778,3 +778,3 @@ zstream_sync(z, src, len)
     if (!NIL_P(z->input)) {
-	z->stream.next_in = RSTRING(z->input)->ptr;
+	z->stream.next_in = (Bytef*)RSTRING(z->input)->ptr;
 	z->stream.avail_in = RSTRING(z->input)->len;
@@ -789,3 +789,3 @@ zstream_sync(z, src, len)
 	if (err != Z_DATA_ERROR) {
-	    rest = rb_str_new(z->stream.next_in, z->stream.avail_in);
+	    rest = rb_str_new((char*)z->stream.next_in, z->stream.avail_in);
 	    raise_zlib_error(err, z->stream.msg);
@@ -804,3 +804,3 @@ zstream_sync(z, src, len)
     if (err != Z_DATA_ERROR) {
-	rest = rb_str_new(z->stream.next_in, z->stream.avail_in);
+	rest = rb_str_new((char*)z->stream.next_in, z->stream.avail_in);
 	raise_zlib_error(err, z->stream.msg);
@@ -956,3 +956,3 @@ rb_zstream_finish(obj)
 
-    zstream_run(z, "", 0, Z_FINISH);
+    zstream_run(z, (Bytef*)"", 0, Z_FINISH);
     dst = zstream_detach_buffer(z);
@@ -1189,3 +1189,3 @@ deflate_run(args)
 
-    zstream_run(z, RSTRING(src)->ptr, RSTRING(src)->len, Z_FINISH);
+    zstream_run(z, (Bytef*)RSTRING(src)->ptr, RSTRING(src)->len, Z_FINISH);
     return zstream_detach_buffer(z);
@@ -1249,3 +1249,3 @@ do_deflate(z, src, flush)
     if (NIL_P(src)) {
-	zstream_run(z, "", 0, Z_FINISH);
+	zstream_run(z, (Bytef*)"", 0, Z_FINISH);
 	return;
@@ -1254,3 +1254,3 @@ do_deflate(z, src, flush)
     if (flush != Z_NO_FLUSH || RSTRING(src)->len > 0) { /* prevent BUF_ERROR */
-	zstream_run(z, RSTRING(src)->ptr, RSTRING(src)->len, flush);
+	zstream_run(z, (Bytef*)RSTRING(src)->ptr, RSTRING(src)->len, flush);
     }
@@ -1328,3 +1328,3 @@ rb_deflate_flush(argc, argv, obj)
     if (flush != Z_NO_FLUSH) {  /* prevent Z_BUF_ERROR */
-	zstream_run(z, "", 0, flush);
+	zstream_run(z, (Bytef*)"", 0, flush);
     }
@@ -1391,3 +1391,3 @@ rb_deflate_set_dictionary(obj, dic)
     err = deflateSetDictionary(&z->stream,
-			       RSTRING(src)->ptr, RSTRING(src)->len);
+			       (Bytef*)RSTRING(src)->ptr, RSTRING(src)->len);
     if (err != Z_OK) {
@@ -1456,4 +1456,4 @@ inflate_run(args)
 
-    zstream_run(z, RSTRING(src)->ptr, RSTRING(src)->len, Z_SYNC_FLUSH);
-    zstream_run(z, "", 0, Z_FINISH);  /* for checking errors */
+    zstream_run(z, (Bytef*)RSTRING(src)->ptr, RSTRING(src)->len, Z_SYNC_FLUSH);
+    zstream_run(z, (Bytef*)"", 0, Z_FINISH);  /* for checking errors */
     return zstream_detach_buffer(z);
@@ -1508,3 +1508,3 @@ do_inflate(z, src)
     if (NIL_P(src)) {
-	zstream_run(z, "", 0, Z_FINISH);
+	zstream_run(z, (Bytef*)"", 0, Z_FINISH);
 	return;
@@ -1513,3 +1513,3 @@ do_inflate(z, src)
     if (RSTRING(src)->len > 0) { /* prevent Z_BUF_ERROR */
-	zstream_run(z, RSTRING(src)->ptr, RSTRING(src)->len, Z_SYNC_FLUSH);
+	zstream_run(z, (Bytef*)RSTRING(src)->ptr, RSTRING(src)->len, Z_SYNC_FLUSH);
     }
@@ -1609,3 +1609,3 @@ rb_inflate_sync(obj, src)
     StringValue(src);
-    return zstream_sync(z, RSTRING(src)->ptr, RSTRING(src)->len);
+    return zstream_sync(z, (Bytef*)RSTRING(src)->ptr, RSTRING(src)->len);
 }
@@ -1653,3 +1653,3 @@ rb_inflate_set_dictionary(obj, dic)
     err = inflateSetDictionary(&z->stream,
-			       RSTRING(src)->ptr, RSTRING(src)->len);
+			       (Bytef*)RSTRING(src)->ptr, RSTRING(src)->len);
     if (err != Z_OK) {
@@ -1939,3 +1939,3 @@ gzfile_make_header(gz)
 {
-    unsigned char buf[10];  /* the size of gzip header */
+    Bytef buf[10];  /* the size of gzip header */
     unsigned char flags = 0, extraflags = 0;
@@ -1970,3 +1970,3 @@ gzfile_make_header(gz)
 	zstream_append_buffer2(&gz->z, gz->orig_name);
-	zstream_append_buffer(&gz->z, "\0", 1);
+	zstream_append_buffer(&gz->z, (Bytef*)"\0", 1);
     }
@@ -1974,3 +1974,3 @@ gzfile_make_header(gz)
 	zstream_append_buffer2(&gz->z, gz->comment);
-	zstream_append_buffer(&gz->z, "\0", 1);
+	zstream_append_buffer(&gz->z, (Bytef*)"\0", 1);
     }
@@ -1984,3 +1984,3 @@ gzfile_make_footer(gz)
 {
-    unsigned char buf[8];  /* 8 is the size of gzip footer */
+    Bytef buf[8];  /* 8 is the size of gzip footer */
 
@@ -2004,3 +2004,3 @@ gzfile_read_header(gz)
 
-    head = RSTRING(gz->z.input)->ptr;
+    head = (unsigned char*)RSTRING(gz->z.input)->ptr;
 
@@ -2042,3 +2042,3 @@ gzfile_read_header(gz)
 	}
-	len = gzfile_get16(RSTRING(gz->z.input)->ptr);
+	len = gzfile_get16((Bytef*)RSTRING(gz->z.input)->ptr);
 	if (!gzfile_read_raw_ensure(gz, 2 + len)) {
@@ -2080,4 +2080,4 @@ gzfile_check_footer(gz)
 
-    crc = gzfile_get32(RSTRING(gz->z.input)->ptr);
-    length = gzfile_get32(RSTRING(gz->z.input)->ptr + 4);
+    crc = gzfile_get32((Bytef*)RSTRING(gz->z.input)->ptr);
+    length = gzfile_get32((Bytef*)RSTRING(gz->z.input)->ptr + 4);
 
@@ -2127,3 +2127,3 @@ gzfile_read_more(gz)
 	if (RSTRING(str)->len > 0) { /* prevent Z_BUF_ERROR */
-	    zstream_run(&gz->z, RSTRING(str)->ptr, RSTRING(str)->len,
+	    zstream_run(&gz->z, (Bytef*)RSTRING(str)->ptr, RSTRING(str)->len,
 			Z_SYNC_FLUSH);
@@ -2144,3 +2144,3 @@ gzfile_calc_crc(gz, str)
     else {
-	gz->crc = crc32(gz->crc, RSTRING(str)->ptr + gz->ungetc,
+	gz->crc = crc32(gz->crc, (Bytef*)RSTRING(str)->ptr + gz->ungetc,
 			RSTRING(str)->len - gz->ungetc);
@@ -2280,3 +2280,3 @@ gzfile_writer_end(gz)
 
-    zstream_run(&gz->z, "", 0, Z_FINISH);
+    zstream_run(&gz->z, (Bytef*)"", 0, Z_FINISH);
     gzfile_make_footer(gz);
@@ -2286,2 +2286,3 @@ gzfile_writer_end(gz)
 	rb_warn("Zlib::GzipWriter object must be closed explicitly.");
+#if 0
 	if (!SPECIAL_CONST_P(gz->io) && OBJ_IS_FREED(gz->io)) {
@@ -2295,2 +2296,4 @@ gzfile_writer_end(gz)
 	}
+#endif
+	rb_warn("gzip footer is not written; broken gzip file");
 	zstream_end(&gz->z);
@@ -2824,3 +2827,3 @@ rb_gzwriter_flush(argc, argv, obj)
     if (flush != Z_NO_FLUSH) {  /* prevent Z_BUF_ERROR */
-	zstream_run(&gz->z, "", 0, flush);
+	zstream_run(&gz->z, (Bytef*)"", 0, flush);
     }
@@ -2846,3 +2849,3 @@ rb_gzwriter_write(obj, str)
     }
-    gzfile_write(gz, RSTRING(str)->ptr, RSTRING(str)->len);
+    gzfile_write(gz, (Bytef*)RSTRING(str)->ptr, RSTRING(str)->len);
     return INT2FIX(RSTRING(str)->len);
@@ -2860,3 +2863,3 @@ rb_gzwriter_putc(obj, ch)
 
-    gzfile_write(gz, &c, 1);
+    gzfile_write(gz, (Bytef*)&c, 1);
     return ch;



In This Thread