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

ruby-changes:7294

From: akr <ko1@a...>
Date: Sun, 24 Aug 2008 16:49:33 +0900 (JST)
Subject: [ruby-changes:7294] Ruby:r18813 (trunk): * include/ruby/io.h (rb_io_t): make enc and enc2 as struct

akr	2008-08-24 16:49:13 +0900 (Sun, 24 Aug 2008)

  New Revision: 18813

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

  Log:
    * include/ruby/io.h (rb_io_t): make enc and enc2 as struct
      rb_io_enc_t;
    
    * io.c: follow the structure change.
      (convconfig_t): defined by rb_io_enc_t.

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

Index: include/ruby/io.h
===================================================================
--- include/ruby/io.h	(revision 18812)
+++ include/ruby/io.h	(revision 18813)
@@ -55,8 +55,10 @@
      * e1   NULL force_encoding(e1)               convert str.encoding to e1
      * e1   e2   convert from e2 to e1            convert str.encoding to e2
      */
-    rb_encoding *enc;
-    rb_encoding *enc2;
+    struct rb_io_enc_t {
+        rb_encoding *enc;
+        rb_encoding *enc2;
+    } encs;
 
     rb_econv_t *readconv;
     char *crbuf;                /* crbuf_off + crbuf_len <= crbuf_capa */
@@ -129,8 +131,8 @@
     fp->writeconv_stateless = Qnil;\
     fp->writeconv_initialized = 0;\
     fp->tied_io_for_writing = 0;\
-    fp->enc = 0;\
-    fp->enc2 = 0;\
+    fp->encs.enc = NULL;\
+    fp->encs.enc2 = NULL;\
 } while (0)
 
 FILE *rb_io_stdio_file(rb_io_t *fptr);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 18812)
+++ ChangeLog	(revision 18813)
@@ -1,3 +1,11 @@
+Sun Aug 24 16:47:32 2008  Tanaka Akira  <akr@f...>
+
+	* include/ruby/io.h (rb_io_t): make enc and enc2 as struct
+	  rb_io_enc_t;
+
+	* io.c: follow the structure change.
+	  (convconfig_t): defined by rb_io_enc_t.
+
 Sun Aug 24 16:19:25 2008  Tanaka Akira  <akr@f...>
 
 	* include/ruby/encoding.h (rb_econv_opts): declared.
Index: io.c
===================================================================
--- io.c	(revision 18812)
+++ io.c	(revision 18813)
@@ -385,8 +385,8 @@
 static rb_encoding*
 io_read_encoding(rb_io_t *fptr)
 {
-    if (fptr->enc) {
-	return fptr->enc;
+    if (fptr->encs.enc) {
+	return fptr->encs.enc;
     }
     return rb_default_external_encoding();
 }
@@ -394,8 +394,8 @@
 static rb_encoding*
 io_input_encoding(rb_io_t *fptr)
 {
-    if (fptr->enc2) {
-	return fptr->enc2;
+    if (fptr->encs.enc2) {
+	return fptr->encs.enc2;
     }
     return io_read_encoding(fptr);
 }
@@ -685,8 +685,8 @@
 # define NEED_NEWLINE_DECODER(fptr) (fptr->mode & FMODE_TEXTMODE)
 # define NEED_NEWLINE_ENCODER(fptr) 0
 #endif
-#define NEED_READCONV(fptr) (fptr->enc2 != NULL || NEED_NEWLINE_DECODER(fptr))
-#define NEED_WRITECONV(fptr) (fptr->enc != NULL || NEED_NEWLINE_ENCODER(fptr))
+#define NEED_READCONV(fptr) (fptr->encs.enc2 != NULL || NEED_NEWLINE_DECODER(fptr))
+#define NEED_WRITECONV(fptr) (fptr->encs.enc != NULL || NEED_NEWLINE_ENCODER(fptr))
 
 static void
 make_writeconv(rb_io_t *fptr)
@@ -709,7 +709,7 @@
         if (NEED_NEWLINE_ENCODER(fptr))
             ecopts.flags |= TEXTMODE_NEWLINE_ENCODER;
 
-        if (!fptr->enc) {
+        if (!fptr->encs.enc) {
             fptr->writeconv = rb_econv_open("", "", &ecopts);
             if (!fptr->writeconv)
                 rb_exc_raise(rb_econv_open_exc("", "", &ecopts));
@@ -718,7 +718,7 @@
         }
 #endif
 
-        enc = fptr->enc2 ? fptr->enc2 : fptr->enc;
+        enc = fptr->encs.enc2 ? fptr->encs.enc2 : fptr->encs.enc;
         senc = rb_econv_stateless_encoding(enc->name);
         if (senc) {
             denc = enc->name;
@@ -754,10 +754,10 @@
                 common_encoding = fptr->writeconv_stateless;
         }
         else {
-            if (fptr->enc2)
-                common_encoding = rb_enc_from_encoding(fptr->enc2);
+            if (fptr->encs.enc2)
+                common_encoding = rb_enc_from_encoding(fptr->encs.enc2);
             else
-                common_encoding = rb_enc_from_encoding(fptr->enc);
+                common_encoding = rb_enc_from_encoding(fptr->encs.enc);
         }
 
         if (!NIL_P(common_encoding)) {
@@ -1460,9 +1460,9 @@
             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->enc2) {
-            sname = fptr->enc2->name;
-            dname = fptr->enc->name;
+        if (fptr->encs.enc2) {
+            sname = fptr->encs.enc2->name;
+            dname = fptr->encs.enc->name;
         }
         else {
             sname = dname = "";
@@ -1555,7 +1555,7 @@
     fptr->crbuf_off += len;
     fptr->crbuf_len -= len;
     OBJ_TAINT(str);
-    rb_enc_associate(str, fptr->enc);
+    rb_enc_associate(str, fptr->encs.enc);
     /* xxx: set coderange */
     if (fptr->crbuf_len == 0)
         fptr->crbuf_off = 0;
@@ -2162,8 +2162,8 @@
 	}
 	newline = (unsigned char)rsptr[rslen - 1];
 
-        if (fptr->enc2)
-            enc = fptr->enc;
+        if (fptr->encs.enc2)
+            enc = fptr->encs.enc;
         else
             enc = io_input_encoding(fptr);
 	while ((c = appendline(fptr, newline, &str, &limit)) != EOF) {
@@ -2470,10 +2470,10 @@
 
         while (1) {
             if (fptr->crbuf_len) {
-                if (fptr->enc)
+                if (fptr->encs.enc)
                     r = rb_enc_precise_mbclen(fptr->crbuf+fptr->crbuf_off,
                                               fptr->crbuf+fptr->crbuf_off+fptr->crbuf_len,
-                                              fptr->enc);
+                                              fptr->encs.enc);
                 else
                     r = ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(1);
                 if (!MBCLEN_NEEDMORE_P(r))
@@ -2493,7 +2493,7 @@
         if (MBCLEN_INVALID_P(r)) {
             r = rb_enc_mbclen(fptr->crbuf+fptr->crbuf_off,
                               fptr->crbuf+fptr->crbuf_off+fptr->crbuf_len,
-                              fptr->enc);
+                              fptr->encs.enc);
             return io_shift_crbuf(fptr, r, &str);
         }
         return io_shift_crbuf(fptr, MBCLEN_CHARFOUND_LEN(r), &str);
@@ -3786,7 +3786,7 @@
 {
     clear_codeconv(fptr);
 
-    parse_mode_enc(estr, &fptr->enc, &fptr->enc2);
+    parse_mode_enc(estr, &fptr->encs.enc, &fptr->encs.enc2);
 }
 
 void
@@ -3849,10 +3849,7 @@
     return extracted;
 }
 
-typedef struct convconfig_t {
-    rb_encoding *enc;
-    rb_encoding *enc2;
-} convconfig_t;
+typedef struct rb_io_enc_t convconfig_t;
 
 static void
 rb_io_extract_modeenc(VALUE *mode_p, VALUE opthash,
@@ -4028,12 +4025,11 @@
     MakeOpenFile(io, fptr);
     fptr->mode = flags;
     if (convconfig) {
-        fptr->enc = convconfig->enc;
-        fptr->enc2 = convconfig->enc2;
+        fptr->encs = *convconfig;
     }
     else {
-        fptr->enc = NULL;
-        fptr->enc2 = NULL;
+        fptr->encs.enc = NULL;
+        fptr->encs.enc2 = NULL;
     }
     fptr->pathv = rb_str_new_frozen(filename);
     fptr->fd = rb_sysopen(RSTRING_PTR(fptr->pathv), modenum, perm);
@@ -4433,8 +4429,7 @@
     fptr->stdio_file = fp;
     fptr->mode = flags | FMODE_SYNC|FMODE_DUPLEX;
     if (convconfig) {
-        fptr->enc = convconfig->enc;
-        fptr->enc2 = convconfig->enc2;
+        fptr->encs = *convconfig;
     }
     fptr->pid = pid;
 
@@ -5581,8 +5576,7 @@
 	MakeOpenFile(io, fp);
         fp->fd = fd;
 	fp->mode = flags;
-        fp->enc = convconfig.enc;
-        fp->enc2 = convconfig.enc2;
+        fp->encs = convconfig;
         clear_codeconv(fp);
         io_check_tty(fp);
     }
@@ -5919,8 +5913,8 @@
 		rb_io_t *fptr;
 
 		GetOpenFile(current_file, fptr);
-		fptr->enc = argf_enc;
-		fptr->enc2 = argf_enc2;
+		fptr->encs.enc = argf_enc;
+		fptr->encs.enc2 = argf_enc2;
                 clear_codeconv(fptr);
 	    }
 	}
@@ -6647,14 +6641,14 @@
 {
     if (NIL_P(v2)) argc = 1;
     if (argc == 2) {
-	fptr->enc2 = rb_to_encoding(v1);
-	fptr->enc = rb_to_encoding(v2);
+	fptr->encs.enc2 = rb_to_encoding(v1);
+	fptr->encs.enc = rb_to_encoding(v2);
         clear_codeconv(fptr);
     }
     else if (argc == 1) {
 	if (NIL_P(v1)) {
-	    fptr->enc = 0;
-	    fptr->enc2 = 0;
+	    fptr->encs.enc = NULL;
+	    fptr->encs.enc2 = NULL;
             clear_codeconv(fptr);
 	}
 	else {
@@ -6663,8 +6657,8 @@
 		mode_enc(fptr, StringValueCStr(tmp));
 	    }
 	    else {
-		fptr->enc = rb_to_encoding(v1);
-		fptr->enc2 = 0;
+		fptr->encs.enc = rb_to_encoding(v1);
+		fptr->encs.enc2 = NULL;
                 clear_codeconv(fptr);
 	    }
 	}
@@ -7496,12 +7490,12 @@
     rb_io_t *fptr;
 
     GetOpenFile(io, fptr);
-    if (fptr->enc2) {
-	return rb_enc_from_encoding(fptr->enc2);
+    if (fptr->encs.enc2) {
+	return rb_enc_from_encoding(fptr->encs.enc2);
     }
     if (fptr->mode & FMODE_WRITABLE) {
-	if (fptr->enc)
-	    return rb_enc_from_encoding(fptr->enc);
+	if (fptr->encs.enc)
+	    return rb_enc_from_encoding(fptr->encs.enc);
 	return Qnil;
     }
     return rb_enc_from_encoding(io_read_encoding(fptr));
@@ -7521,7 +7515,7 @@
     rb_io_t *fptr;
 
     GetOpenFile(io, fptr);
-    if (!fptr->enc2) return Qnil;
+    if (!fptr->encs.enc2) return Qnil;
     return rb_enc_from_encoding(io_read_encoding(fptr));
 }
 
@@ -7580,8 +7574,8 @@
     }
     rb_io_set_encoding(argc, argv, current_file);
     GetOpenFile(current_file, fptr);
-    argf_enc = fptr->enc;
-    argf_enc2 = fptr->enc2;
+    argf_enc = fptr->encs.enc;
+    argf_enc2 = fptr->encs.enc2;
     return argf;
 }
 

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

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