summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-10-23 09:36:52 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-10-23 09:36:52 +0000
commit03144f6df01df8b115436e5d916d3e5c3ed30212 (patch)
tree11a6ca2f161f5c0175ecde42403706a0a5a6edf8 /io.c
parentcfdaa4dddc55c20d9a2970e32dbef2f683e26129 (diff)
merges r29415 from trunk into ruby_1_9_2. fixes #3910 #3951 and #3959.
-- * io.c (fptr_finalize): write_mutex might have been destroyed already in finalization phase, as the order of finalizers is not guaranteed. rb_mutex_t should be used in place of Mutex object in the future. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@29564 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/io.c b/io.c
index 6eff580a88..ed23a618ad 100644
--- a/io.c
+++ b/io.c
@@ -3423,7 +3423,7 @@ fptr_finalize(rb_io_t *fptr, int noraise)
{
VALUE err = Qnil;
if (fptr->writeconv) {
- if (fptr->write_lock) {
+ if (fptr->write_lock && !noraise) {
struct finish_writeconv_arg arg;
arg.fptr = fptr;
arg.noalloc = noraise;
@@ -3434,8 +3434,14 @@ fptr_finalize(rb_io_t *fptr, int noraise)
}
}
if (fptr->wbuf_len) {
- if (io_fflush(fptr) < 0 && NIL_P(err))
- err = noraise ? Qtrue : INT2NUM(errno);
+ if (noraise) {
+ if ((int)io_flush_buffer_sync(fptr) < 0 && NIL_P(err))
+ err = Qtrue;
+ }
+ else {
+ if (io_fflush(fptr) < 0 && NIL_P(err))
+ err = INT2NUM(errno);
+ }
}
if (IS_PREP_STDIO(fptr) || fptr->fd <= 2) {
goto skip_fd_close;