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

ruby-changes:7295

From: akr <ko1@a...>
Date: Sun, 24 Aug 2008 17:39:23 +0900 (JST)
Subject: [ruby-changes:7295] Ruby:r18814 (trunk): * include/ruby/encoding.h (rb_str_transcode): make 3rd argument

akr	2008-08-24 17:39:09 +0900 (Sun, 24 Aug 2008)

  New Revision: 18814

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

  Log:
    * include/ruby/encoding.h (rb_str_transcode): make 3rd argument
      rb_econv_option_t*.
    
    * transcode.c (transcode_loop): take rb_econv_option_t* as a argument.
      (str_transcode0): ditto.
      (str_transcode): make rb_econv_option_t and call str_transcode0 with
      it.
      (rb_str_transcode): take rb_econv_option_t*.
    
    * io.c (io_fwrite): follow the rb_str_transcode change.

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

Index: include/ruby/encoding.h
===================================================================
--- include/ruby/encoding.h	(revision 18813)
+++ include/ruby/encoding.h	(revision 18814)
@@ -194,8 +194,6 @@
     return ENC_DUMMY_P(enc) != 0;
 }
 
-VALUE rb_str_transcode(VALUE str, VALUE to, int ecflags);
-
 /* econv stuff */
 
 typedef enum {
@@ -254,6 +252,8 @@
     /* replacement character, etc. */
 } rb_econv_option_t;
 
+VALUE rb_str_transcode(VALUE str, VALUE to, rb_econv_option_t *ecopts);
+
 void rb_econv_opts(VALUE hash, rb_econv_option_t *opts);
 
 rb_econv_t *rb_econv_open(const char *source_encoding, const char *destination_encoding, rb_econv_option_t *opts);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 18813)
+++ ChangeLog	(revision 18814)
@@ -1,3 +1,16 @@
+Sun Aug 24 17:36:21 2008  Tanaka Akira  <akr@f...>
+
+	* include/ruby/encoding.h (rb_str_transcode): make 3rd argument
+	  rb_econv_option_t*.
+
+	* transcode.c (transcode_loop): take rb_econv_option_t* as a argument.
+	  (str_transcode0): ditto.
+	  (str_transcode): make rb_econv_option_t and call str_transcode0 with
+	  it.
+	  (rb_str_transcode): take rb_econv_option_t*.
+
+	* io.c (io_fwrite): follow the rb_str_transcode change.
+
 Sun Aug 24 16:47:32 2008  Tanaka Akira  <akr@f...>
 
 	* include/ruby/io.h (rb_io_t): make enc and enc2 as struct
Index: io.c
===================================================================
--- io.c	(revision 18813)
+++ io.c	(revision 18814)
@@ -761,12 +761,13 @@
         }
 
         if (!NIL_P(common_encoding)) {
-            int ecflags = 0;
+            rb_econv_option_t ecopts;
+            ecopts.flags = 0;
             if (fptr->mode & FMODE_INVALID_MASK)
-                ecflags |= (fptr->mode / (FMODE_INVALID_MASK/ECONV_INVALID_MASK)) & ECONV_INVALID_MASK;
+                ecopts.flags |= (fptr->mode / (FMODE_INVALID_MASK/ECONV_INVALID_MASK)) & ECONV_INVALID_MASK;
             if (fptr->mode & FMODE_UNDEF_MASK)
-                ecflags |= (fptr->mode / (FMODE_UNDEF_MASK/ECONV_UNDEF_MASK)) & ECONV_UNDEF_MASK;
-            str = rb_str_transcode(str, common_encoding, ecflags);
+                ecopts.flags |= (fptr->mode / (FMODE_UNDEF_MASK/ECONV_UNDEF_MASK)) & ECONV_UNDEF_MASK;
+            str = rb_str_transcode(str, common_encoding, &ecopts);
         }
 
         if (fptr->writeconv) {
Index: transcode.c
===================================================================
--- transcode.c	(revision 18813)
+++ transcode.c	(revision 18814)
@@ -1547,7 +1547,7 @@
                unsigned char *(*resize_destination)(VALUE, int, int),
                const char *from_encoding,
                const char *to_encoding,
-	       const int opt)
+               rb_econv_option_t *ecopts)
 {
     rb_econv_t *ec;
     rb_transcoding *last_tc;
@@ -1555,18 +1555,16 @@
     unsigned char *out_start = *out_pos;
     int max_output;
     VALUE exc;
-    rb_econv_option_t ecopts;
 
-    ecopts.flags = opt & (ECONV_INVALID_MASK|ECONV_UNDEF_MASK);
-    ec = rb_econv_open(from_encoding, to_encoding, &ecopts);
+    ec = rb_econv_open(from_encoding, to_encoding, ecopts);
     if (!ec)
-        rb_exc_raise(rb_econv_open_exc(from_encoding, to_encoding, &ecopts));
+        rb_exc_raise(rb_econv_open_exc(from_encoding, to_encoding, ecopts));
 
     last_tc = ec->last_tc;
     max_output = last_tc ? last_tc->transcoder->max_output : 1;
 
 resume:
-    ret = rb_econv_convert(ec, in_pos, in_stop, out_pos, out_stop, opt);
+    ret = rb_econv_convert(ec, in_pos, in_stop, out_pos, out_stop, 0);
 
     if (ret == econv_invalid_byte_sequence) {
         exc = make_econv_exception(ec);
@@ -1596,7 +1594,7 @@
                unsigned char *(*resize_destination)(VALUE, int, int),
                const char *from_encoding,
                const char *to_encoding,
-	       const int opt)
+               rb_econv_option_t *ecopts)
 {
     rb_econv_t *ec;
     rb_transcoding *last_tc;
@@ -1605,13 +1603,10 @@
     const unsigned char *ptr;
     int max_output;
     VALUE exc;
-    int ecflags;
-    rb_econv_option_t ecopts;
 
-    ecopts.flags = opt & (ECONV_INVALID_MASK|ECONV_UNDEF_MASK);
-    ec = rb_econv_open(from_encoding, to_encoding, &ecopts);
+    ec = rb_econv_open(from_encoding, to_encoding, ecopts);
     if (!ec)
-        rb_exc_raise(rb_econv_open_exc(from_encoding, to_encoding, &ecopts));
+        rb_exc_raise(rb_econv_open_exc(from_encoding, to_encoding, ecopts));
 
     last_tc = ec->last_tc;
     max_output = last_tc ? last_tc->transcoder->max_output : 1;
@@ -1758,7 +1753,7 @@
 }
 
 static int
-str_transcode0(int argc, VALUE *argv, VALUE *self, int options)
+str_transcode0(int argc, VALUE *argv, VALUE *self, rb_econv_option_t *ecopts)
 {
     VALUE dest;
     VALUE str = *self;
@@ -1793,7 +1788,7 @@
     dest = rb_str_tmp_new(blen);
     bp = (unsigned char *)RSTRING_PTR(dest);
 
-    transcode_loop(&fromp, &bp, (sp+slen), (bp+blen), dest, str_transcoding_resize, from_e, to_e, options);
+    transcode_loop(&fromp, &bp, (sp+slen), (bp+blen), dest, str_transcoding_resize, from_e, to_e, ecopts);
     if (fromp != sp+slen) {
         rb_raise(rb_eArgError, "not fully converted, %"PRIdPTRDIFF" bytes left", sp+slen-fromp);
     }
@@ -1814,16 +1809,17 @@
 str_transcode(int argc, VALUE *argv, VALUE *self)
 {
     VALUE opt;
-    int options = 0;
+    rb_econv_option_t ecopts;
+    ecopts.flags = 0;
 
     if (0 < argc) {
         opt = rb_check_convert_type(argv[argc-1], T_HASH, "Hash", "to_hash");
         if (!NIL_P(opt)) {
             argc--;
-            options = econv_opts(opt);
+            rb_econv_opts(opt, &ecopts);
         }
     }
-    return str_transcode0(argc, argv, self, options);
+    return str_transcode0(argc, argv, self, &ecopts);
 }
 
 static inline VALUE
@@ -1894,12 +1890,12 @@
 }
 
 VALUE
-rb_str_transcode(VALUE str, VALUE to, int flags)
+rb_str_transcode(VALUE str, VALUE to, rb_econv_option_t *ecopts)
 {
     int argc = 1;
     VALUE *argv = &to;
     VALUE newstr = str;
-    int encidx = str_transcode0(argc, argv, &newstr, flags);
+    int encidx = str_transcode0(argc, argv, &newstr, ecopts);
 
     if (encidx < 0) return rb_str_dup(str);
     RBASIC(newstr)->klass = rb_obj_class(str);

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

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