[前][次][番号順一覧][スレッド一覧]

ruby-changes:14422

From: usa <ko1@a...>
Date: Fri, 8 Jan 2010 17:08:35 +0900 (JST)
Subject: [ruby-changes:14422] Ruby:r26252 (ruby_1_8): * io.c (rb_io_s_read): close the IO if an exception is raised on

usa	2010-01-08 17:08:21 +0900 (Fri, 08 Jan 2010)

  New Revision: 26252

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26252

  Log:
    * io.c (rb_io_s_read): close the IO if an exception is raised on
      seeking. [ruby-core:27429]

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/io.c

Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 26251)
+++ ruby_1_8/ChangeLog	(revision 26252)
@@ -1,3 +1,8 @@
+Fri Jan  8 17:07:15 2010  NAKAMURA Usaku  <usa@r...>
+
+	* io.c (rb_io_s_read): close the IO if an exception is raised on
+	  seeking. [ruby-core:27429]
+
 Fri Jan  8 17:02:45 2010  Nobuyoshi Nakada  <nobu@r...>
 
 	 * ruby.h (RB_GC_GUARD_PTR): workaround for gcc optimization.
Index: ruby_1_8/io.c
===================================================================
--- ruby_1_8/io.c	(revision 26251)
+++ ruby_1_8/io.c	(revision 26252)
@@ -5502,6 +5502,18 @@
     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
@@ -5531,7 +5543,16 @@
     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);
 }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]