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

ruby-changes:7878

From: matz <ko1@a...>
Date: Thu, 18 Sep 2008 01:40:01 +0900 (JST)
Subject: [ruby-changes:7878] Ruby:r19399 (trunk): * io.c (rb_io_extract_modeenc): process option mode: and perm: as

matz	2008-09-18 01:39:47 +0900 (Thu, 18 Sep 2008)

  New Revision: 19399

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

  Log:
    * io.c (rb_io_extract_modeenc): process option mode: and perm: as
      well.
    
    * io.c (open_key_args): move mode: and perm: related code to
      rb_io_extract_modeenc().

  Modified files:
    trunk/ChangeLog
    trunk/io.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19398)
+++ ChangeLog	(revision 19399)
@@ -15,6 +15,14 @@
 	* test/ruby/test_io.rb (TestIO#test_dup): remove needless open.
 	  [ruby-dev:35957]
 
+Wed Sep 17 17:44:59 2008  Yukihiro Matsumoto  <matz@r...>
+
+	* io.c (rb_io_extract_modeenc): process option mode: and perm: as
+	  well.
+
+	* io.c (open_key_args): move mode: and perm: related code to
+	  rb_io_extract_modeenc().
+
 Wed Sep 17 13:42:59 2008  Takeyuki Fujioka  <xibbar@r...>
 
 	* lib/cgi/html.rb (checkbox_group,radio_group): bug fix
Index: io.c
===================================================================
--- io.c	(revision 19398)
+++ io.c	(revision 19399)
@@ -3864,7 +3864,7 @@
 }
 
 static void
-rb_io_extract_modeenc(VALUE *vmode_p, VALUE opthash,
+rb_io_extract_modeenc(VALUE *vmode_p, VALUE *vperm_p, VALUE opthash,
         int *oflags_p, int *fmode_p, convconfig_t *convconfig_p)
 {
     VALUE vmode;
@@ -3872,7 +3872,7 @@
     rb_encoding *enc, *enc2;
     int ecflags;
     VALUE ecopts;
-    int has_enc = 0;
+    int has_enc = 0, has_vmode = 0;
     VALUE intmode;
 
     vmode = *vmode_p;
@@ -3891,6 +3891,8 @@
     }
     else {
         const char *p;
+
+      vmode_handle:
         SafeStringValue(vmode);
         p = StringValueCStr(vmode);
         fmode = rb_io_modestr_fmode(p);
@@ -3909,15 +3911,38 @@
     else {
 	VALUE v;
 	v = rb_hash_aref(opthash, sym_textmode);
-	if (RTEST(v))
+	if (!NIL_P(v))
             fmode |= FMODE_TEXTMODE;
 	v = rb_hash_aref(opthash, sym_binmode);
-	if (RTEST(v)) {
+	if (!NIL_P(v)) {
             fmode |= FMODE_BINMODE;
 #ifdef O_BINARY
             oflags |= O_BINARY;
 #endif
         }
+	if (!has_vmode) {
+	    v = rb_hash_aref(opthash, sym_mode);
+	    if (!NIL_P(v)) {
+		if (!NIL_P(vmode)) {
+		    rb_raise(rb_eArgError, "mode specified twice");
+		}
+		has_vmode = 1;
+		vmode = v;
+		goto vmode_handle;
+	    }
+	}
+	v = rb_hash_aref(opthash, sym_perm);
+	if (!NIL_P(v)) {
+	    if (vperm_p) {
+		if (!NIL_P(*vperm_p)) {
+		    rb_raise(rb_eArgError, "perm specified twice");
+		}
+		*vperm_p = v;
+	    }
+	    else {
+		/* perm no use, just ignore */
+	    }
+	}
         ecflags = rb_econv_prepare_opts(opthash, &ecopts);
 
         if (io_extract_encoding_option(opthash, &enc, &enc2)) {
@@ -4588,7 +4613,7 @@
     opt = pop_last_hash(&argc, &argv);
     rb_scan_args(argc, argv, "11", &pname, &pmode);
 
-    rb_io_extract_modeenc(&pmode, opt, &oflags, &fmode, &convconfig);
+    rb_io_extract_modeenc(&pmode, 0, opt, &oflags, &fmode, &convconfig);
     modestr = rb_io_oflags_modestr(oflags);
 
     tmp = rb_check_array_type(pname);
@@ -4652,7 +4677,7 @@
     }
 #endif
  
-    rb_io_extract_modeenc(&vmode, opt, &oflags, &fmode, convconfig_p);
+    rb_io_extract_modeenc(&vmode, &vperm, opt, &oflags, &fmode, convconfig_p);
 
     perm = NIL_P(vperm) ? 0666 :  NUM2UINT(vperm);
 
@@ -4909,7 +4934,7 @@
     convconfig_t convconfig;
     mode_t perm;
 
-    rb_io_extract_modeenc(&vmode, opt, &oflags, &fmode, &convconfig);
+    rb_io_extract_modeenc(&vmode, &vperm, opt, &oflags, &fmode, &convconfig);
     perm = NIL_P(vperm) ? 0666 :  NUM2UINT(vperm);
 
     if (!NIL_P(cmd = check_pipe_command(filename))) {
@@ -5596,7 +5621,7 @@
 
     opt = pop_last_hash(&argc, &argv);
     rb_scan_args(argc, argv, "11", &fnum, &vmode);
-    rb_io_extract_modeenc(&vmode, opt, &oflags, &fmode, &convconfig);
+    rb_io_extract_modeenc(&vmode, 0, opt, &oflags, &fmode, &convconfig);
 
     fd = NUM2INT(fnum);
     UPDATE_MAXFD(fd);
@@ -6774,7 +6799,6 @@
 open_key_args(int argc, VALUE *argv, struct foreach_arg *arg)
 {
     VALUE opt, v;
-    VALUE vmode, vperm;
 
     FilePathValue(argv[0]);
     arg->io = 0;
@@ -6801,15 +6825,7 @@
 	arg->io = rb_io_open_with_args(RARRAY_LEN(args), RARRAY_PTR(args));
 	return;
     }
-    vmode = Qnil;
-    vperm = INT2NUM(O_RDONLY);
-    v = rb_hash_aref(opt, sym_mode);
-    if (!NIL_P(v))
-        vmode = v;
-    v = rb_hash_aref(opt, sym_perm);
-    if (!NIL_P(v))
-        vperm = v;
-    arg->io = rb_io_open(argv[0], vmode, vperm, opt);
+    arg->io = rb_io_open(argv[0], Qnil, INT2NUM(O_RDONLY), opt);
 }
 
 static VALUE

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

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