Actions
Bug #923
closed`initialize_copy': wrong argument type #<Class:0x825d23c> (expected Data) (TypeError)
Bug #923:
`initialize_copy': wrong argument type #<Class:0x825d23c> (expected Data) (TypeError)
Description
=begin
まつもと ゆきひろです
In message "Re: [ruby-dev:37572] [Bug:1.9] `initialize_copy': wrong argument type #Class:0x825d23c (expected Data) (TypeError)"
on Wed, 24 Dec 2008 01:44:13 +0900, Tanaka Akira akr@fsij.org writes:
|
|以下のプログラムで、
| wrong argument type #Class:0x825d23c (expected Data) (TypeError)
|という奇妙なエラーが出ます。
|
|% ./ruby -ve 'f = open("/tmp/x", "w")
|1000.times { f.dup.print "a" }
|GC.start
|'
IOのファイナライザを実行する時点ではwrite_lockがすでに解放さ
れちゃってるからのようです。とりあえず、
- ファイナライザ実行前にwrite_lockをクリア
- io_fflushでwrite_lockを問答無用で参照していたのをやめる
という対応で上記のプログラムは動いているように見えます。が、
わざわざwrite_lockをかけていたのをはずしちゃって良いのかとい
う判断は私にはつきかねます。
パッチを添付します。
--- a/io.c
+++ b/io.c
@@ -558,7 +558,13 @@ io_fflush(rb_io_t *fptr)
retry:
if (fptr->wbuf_len == 0)
return 0;
- r = rb_mutex_synchronize(fptr->write_lock, io_flush_buffer, (VALUE)fptr);
- if (fptr->write_lock) {
- r = rb_mutex_synchronize(fptr->write_lock, io_flush_buffer, (VALUE)fptr);
- }
- else {
- long l = io_writable_length(fptr, fptr->wbuf_len);
- r = rb_write_internal(fptr->fd, fptr->wbuf+fptr->wbuf_off, l);
- }
/* xxx: Other threads may modify wbuf.- A lock is required, definitely. */
rb_io_check_closed(fptr);
@@ -3194,6 +3200,7 @@ rb_io_fptr_finalize(rb_io_t *fptr)
{
if (!fptr) return 0;
fptr->pathv = Qnil;
- A lock is required, definitely. */
- fptr->write_lock = 0;
if (0 <= fptr->fd)
rb_io_fptr_cleanup(fptr, Qtrue);
if (fptr->rbuf) {
=end
Actions