summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-19 23:10:31 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-19 23:10:31 +0000
commitd38975ac74a13fe1561851e1a193b86ea39a5a6d (patch)
treed053dcb158c139860dfc4c331a7f43adcb9fc69c
parent95d902d90d62e10bdd1c73bf70650ba01d026483 (diff)
merge revision(s) 26252:
* io.c (rb_io_s_read): close the IO if an exception is raised on seeking. [ruby-core:27429] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@27410 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--io.c23
-rw-r--r--version.h2
3 files changed, 28 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index e49f0b6fdc..aa3ff2655b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Apr 20 08:04:37 2010 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * io.c (rb_io_s_read): close the IO if an exception is raised on
+ seeking. [ruby-core:27429]
+
Mon Apr 19 22:43:28 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.h (RB_GC_GUARD_PTR): workaround for gcc optimization.
diff --git a/io.c b/io.c
index c3fb3e420d..e815c07c9f 100644
--- a/io.c
+++ b/io.c
@@ -5462,6 +5462,18 @@ io_s_read(arg)
return io_read(arg->argc, &arg->sep, arg->io);
}
+struct seek_arg {
+ VALUE io;
+ VALUE offset;
+ int mode;
+};
+
+static VALUE
+seek_before_read(struct seek_arg *arg)
+{
+ return rb_io_seek(arg->io, arg->offset, arg->mode);
+}
+
/*
* call-seq:
* IO.read(name, [length [, offset]] ) => string
@@ -5491,7 +5503,16 @@ rb_io_s_read(argc, argv, io)
arg.io = rb_io_open(StringValueCStr(fname), "r");
if (NIL_P(arg.io)) return Qnil;
if (!NIL_P(offset)) {
- rb_io_seek(arg.io, offset, SEEK_SET);
+ struct seek_arg sarg;
+ int state = 0;
+ sarg.io = arg.io;
+ sarg.offset = offset;
+ sarg.mode = SEEK_SET;
+ rb_protect((VALUE (*)(VALUE))seek_before_read, (VALUE)&sarg, &state);
+ if (state) {
+ rb_io_close(arg.io);
+ rb_jump_tag(state);
+ }
}
return rb_ensure(io_s_read, (VALUE)&arg, rb_io_close, arg.io);
}
diff --git a/version.h b/version.h
index a33fb38213..57a5368cc2 100644
--- a/version.h
+++ b/version.h
@@ -2,7 +2,7 @@
#define RUBY_RELEASE_DATE "2010-04-20"
#define RUBY_VERSION_CODE 187
#define RUBY_RELEASE_CODE 20100420
-#define RUBY_PATCHLEVEL 253
+#define RUBY_PATCHLEVEL 254
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8