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

ruby-changes:7297

From: akr <ko1@a...>
Date: Sun, 24 Aug 2008 18:14:15 +0900 (JST)
Subject: [ruby-changes:7297] Ruby:r18816 (trunk): * include/ruby/io.h (rb_io_enc_t): add opts field.

akr	2008-08-24 18:13:55 +0900 (Sun, 24 Aug 2008)

  New Revision: 18816

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

  Log:
    * include/ruby/io.h (rb_io_enc_t): add opts field.
      (FMODE_INVALID_MASK): removed.
      (FMODE_INVALID_IGNORE): ditto.
      (FMODE_INVALID_REPLACE): ditto.
      (FMODE_UNDEF_MASK): ditto.
      (FMODE_UNDEF_IGNORE): ditto.
      (FMODE_UNDEF_REPLACE): ditto.
      (MakeOpenFile): initialize the opts field.
    
    * io.c (make_writeconv): use the opts field.
      (io_fwrite): ditto.
      (make_readconv): ditto.
      (argf_ecopts): new macro.
      (rb_io_extract_modeenc): fill the opts field.
      (argf_next_argv): ditto.
      (rb_file_open_generic): initialize the opts field.
      (rb_file_open_internal): ditto.
      (io_encoding_set): ditto.
      (argf_set_encoding): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/io.h
    trunk/io.c

Index: include/ruby/io.h
===================================================================
--- include/ruby/io.h	(revision 18815)
+++ include/ruby/io.h	(revision 18816)
@@ -58,6 +58,7 @@
     struct rb_io_enc_t {
         rb_encoding *enc;
         rb_encoding *enc2;
+        rb_econv_option_t opts;
     } encs;
 
     rb_econv_t *readconv;
@@ -89,12 +90,6 @@
 #define FMODE_TRUNC                 0x00000800
 #define FMODE_TEXTMODE              0x00001000
 /* #define FMODE_PREP               0x00010000 */
-#define FMODE_INVALID_MASK          0x00f00000
-#define FMODE_INVALID_IGNORE        0x00100000
-#define FMODE_INVALID_REPLACE       0x00200000
-#define FMODE_UNDEF_MASK            0x0f000000
-#define FMODE_UNDEF_IGNORE          0x01000000
-#define FMODE_UNDEF_REPLACE         0x02000000
 
 #define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)
 
@@ -133,6 +128,7 @@
     fp->tied_io_for_writing = 0;\
     fp->encs.enc = NULL;\
     fp->encs.enc2 = NULL;\
+    fp->encs.opts.flags = 0;\
 } while (0)
 
 FILE *rb_io_stdio_file(rb_io_t *fptr);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 18815)
+++ ChangeLog	(revision 18816)
@@ -1,3 +1,25 @@
+Sun Aug 24 18:10:08 2008  Tanaka Akira  <akr@f...>
+
+	* include/ruby/io.h (rb_io_enc_t): add opts field.
+	  (FMODE_INVALID_MASK): removed.
+	  (FMODE_INVALID_IGNORE): ditto.
+	  (FMODE_INVALID_REPLACE): ditto.
+	  (FMODE_UNDEF_MASK): ditto.
+	  (FMODE_UNDEF_IGNORE): ditto.
+	  (FMODE_UNDEF_REPLACE): ditto.
+	  (MakeOpenFile): initialize the opts field.
+
+	* io.c (make_writeconv): use the opts field.
+	  (io_fwrite): ditto.
+	  (make_readconv): ditto.
+	  (argf_ecopts): new macro.
+	  (rb_io_extract_modeenc): fill the opts field.
+	  (argf_next_argv): ditto.
+	  (rb_file_open_generic): initialize the opts field.
+	  (rb_file_open_internal): ditto.
+	  (io_encoding_set): ditto.
+	  (argf_set_encoding): ditto.
+
 Sun Aug 24 18:02:14 2008  Tanaka Akira  <akr@f...>
 
 	* io.c (struct argf): use struct rb_io_enc_t.
Index: io.c
===================================================================
--- io.c	(revision 18815)
+++ io.c	(revision 18816)
@@ -698,13 +698,8 @@
 
         fptr->writeconv_initialized = 1;
 
-        ecopts.flags = 0;
+        ecopts = fptr->encs.opts;
 
-        if (fptr->mode & FMODE_INVALID_MASK)
-            ecopts.flags |= (fptr->mode / (FMODE_INVALID_MASK/ECONV_INVALID_MASK)) & ECONV_INVALID_MASK;
-        if (fptr->mode & FMODE_UNDEF_MASK)
-            ecopts.flags |= (fptr->mode / (FMODE_UNDEF_MASK/ECONV_UNDEF_MASK)) & ECONV_UNDEF_MASK;
-
 #ifdef TEXTMODE_NEWLINE_ENCODER
         if (NEED_NEWLINE_ENCODER(fptr))
             ecopts.flags |= TEXTMODE_NEWLINE_ENCODER;
@@ -761,13 +756,7 @@
         }
 
         if (!NIL_P(common_encoding)) {
-            rb_econv_option_t ecopts;
-            ecopts.flags = 0;
-            if (fptr->mode & FMODE_INVALID_MASK)
-                ecopts.flags |= (fptr->mode / (FMODE_INVALID_MASK/ECONV_INVALID_MASK)) & ECONV_INVALID_MASK;
-            if (fptr->mode & FMODE_UNDEF_MASK)
-                ecopts.flags |= (fptr->mode / (FMODE_UNDEF_MASK/ECONV_UNDEF_MASK)) & ECONV_UNDEF_MASK;
-            str = rb_str_transcode(str, common_encoding, &ecopts);
+            str = rb_str_transcode(str, common_encoding, &fptr->encs.opts);
         }
 
         if (fptr->writeconv) {
@@ -1454,13 +1443,9 @@
     if (!fptr->readconv) {
         rb_econv_option_t ecopts;
         const char *sname, *dname;
-        ecopts.flags = 0;
+        ecopts = fptr->encs.opts;
         if (NEED_NEWLINE_DECODER(fptr))
             ecopts.flags |= ECONV_UNIVERSAL_NEWLINE_DECODER;
-        if (fptr->mode & FMODE_INVALID_MASK)
-            ecopts.flags |= (fptr->mode / (FMODE_INVALID_MASK/ECONV_INVALID_MASK)) & ECONV_INVALID_MASK;
-        if (fptr->mode & FMODE_UNDEF_MASK)
-            ecopts.flags |= (fptr->mode / (FMODE_UNDEF_MASK/ECONV_UNDEF_MASK)) & ECONV_UNDEF_MASK;
         if (fptr->encs.enc2) {
             sname = fptr->encs.enc2->name;
             dname = fptr->encs.enc->name;
@@ -3859,6 +3844,7 @@
     VALUE mode;
     int modenum, flags;
     rb_encoding *enc, *enc2;
+    rb_econv_option_t ecopts;
     int has_enc = 0;
     VALUE intmode;
 
@@ -3889,9 +3875,11 @@
         }
     }
 
-    if (!NIL_P(opthash)) {
+    if (NIL_P(opthash)) {
+        ecopts.flags = 0;
+    }
+    else {
 	VALUE v;
-        rb_econv_option_t ecopts;
 	v = rb_hash_aref(opthash, sym_textmode);
 	if (RTEST(v))
             flags |= FMODE_TEXTMODE;
@@ -3903,10 +3891,6 @@
 #endif
         }
         rb_econv_opts(opthash, &ecopts);
-        if (ecopts.flags & ECONV_INVALID_REPLACE) flags |= FMODE_INVALID_REPLACE;
-        if (ecopts.flags & ECONV_INVALID_IGNORE) flags |= FMODE_INVALID_IGNORE;
-        if (ecopts.flags & ECONV_UNDEF_REPLACE) flags |= FMODE_UNDEF_REPLACE;
-        if (ecopts.flags & ECONV_UNDEF_IGNORE) flags |= FMODE_UNDEF_IGNORE;
 
         if (io_extract_encoding_option(opthash, &enc, &enc2)) {
             if (has_enc) {
@@ -3924,6 +3908,7 @@
     *flags_p = flags;
     convconfig_p->enc = enc;
     convconfig_p->enc2 = enc2;
+    convconfig_p->opts = ecopts;
 }
 
 struct sysopen_struct {
@@ -4031,6 +4016,7 @@
     else {
         fptr->encs.enc = NULL;
         fptr->encs.enc2 = NULL;
+        fptr->encs.opts.flags = 0;
     }
     fptr->pathv = rb_str_new_frozen(filename);
     fptr->fd = rb_sysopen(RSTRING_PTR(fptr->pathv), modenum, perm);
@@ -4052,6 +4038,7 @@
     else {
         convconfig.enc = NULL;
         convconfig.enc2 = NULL;
+        convconfig.opts.flags = 0;
     }
 
     flags = rb_io_mode_flags(mode);
@@ -5745,6 +5732,7 @@
 #define argf_binmode      ARGF.binmode
 #define argf_enc          ARGF.encs.enc
 #define argf_enc2         ARGF.encs.enc2
+#define argf_ecopts       ARGF.encs.opts
 #define rb_argv           ARGF.argv
 
 static VALUE
@@ -5916,6 +5904,7 @@
 		GetOpenFile(current_file, fptr);
 		fptr->encs.enc = argf_enc;
 		fptr->encs.enc2 = argf_enc2;
+		fptr->encs.opts = argf_ecopts;
                 clear_codeconv(fptr);
 	    }
 	}
@@ -6644,12 +6633,14 @@
     if (argc == 2) {
 	fptr->encs.enc2 = rb_to_encoding(v1);
 	fptr->encs.enc = rb_to_encoding(v2);
+	fptr->encs.opts.flags = 0; /* xxx */
         clear_codeconv(fptr);
     }
     else if (argc == 1) {
 	if (NIL_P(v1)) {
 	    fptr->encs.enc = NULL;
 	    fptr->encs.enc2 = NULL;
+            fptr->encs.opts.flags = 0;
             clear_codeconv(fptr);
 	}
 	else {
@@ -6660,6 +6651,7 @@
 	    else {
 		fptr->encs.enc = rb_to_encoding(v1);
 		fptr->encs.enc2 = NULL;
+                fptr->encs.opts.flags = 0;
                 clear_codeconv(fptr);
 	    }
 	}
@@ -7577,6 +7569,7 @@
     GetOpenFile(current_file, fptr);
     argf_enc = fptr->encs.enc;
     argf_enc2 = fptr->encs.enc2;
+    argf_ecopts.flags = 0; /* xxx */
     return argf;
 }
 

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

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