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

ruby-changes:7582

From: akr <ko1@a...>
Date: Thu, 4 Sep 2008 00:13:06 +0900 (JST)
Subject: [ruby-changes:7582] Ruby:r19103 (trunk): * include/ruby/encoding.h (rb_econv_option_t): removed. Since

akr	2008-09-04 00:11:46 +0900 (Thu, 04 Sep 2008)

  New Revision: 19103

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

  Log:
    * include/ruby/encoding.h (rb_econv_option_t): removed.  Since
      rb_econv_option_t has only one field, int flags, rb_econv_option_t is
      replaced by int.
    
    * include/ruby/io.h: follow the above change.
    
    * io.c: ditto.
    
    * transcode.c: ditto.

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

Index: include/ruby/encoding.h
===================================================================
--- include/ruby/encoding.h	(revision 19102)
+++ include/ruby/encoding.h	(revision 19103)
@@ -206,25 +206,20 @@
     econv_incomplete_input,
 } rb_econv_result_t;
 
-typedef struct {
-    int flags;
-    /* replacement character, etc. */
-} rb_econv_option_t;
-
 typedef struct rb_econv_t rb_econv_t;
 
-VALUE rb_str_transcode(VALUE str, VALUE to, rb_econv_option_t *ecopts);
+VALUE rb_str_transcode(VALUE str, VALUE to, int ecflags);
 
-void rb_econv_opts(VALUE hash, rb_econv_option_t *opts);
+int rb_econv_flags(VALUE hash);
 
-rb_econv_t *rb_econv_open(const char *source_encoding, const char *destination_encoding, rb_econv_option_t *opts);
+rb_econv_t *rb_econv_open(const char *source_encoding, const char *destination_encoding, int ecflags);
 rb_econv_result_t rb_econv_convert(rb_econv_t *ec,
     const unsigned char **source_buffer_ptr, const unsigned char *source_buffer_end,
     unsigned char **destination_buffer_ptr, unsigned char *destination_buffer_end,
     int flags);
 void rb_econv_close(rb_econv_t *ec);
 
-VALUE rb_econv_open_exc(const char *senc, const char *denc, rb_econv_option_t *opts);
+VALUE rb_econv_open_exc(const char *senc, const char *denc, int ecflags);
 
 /* result: 0:success -1:failure */
 int rb_econv_insert_output(rb_econv_t *ec,
Index: include/ruby/io.h
===================================================================
--- include/ruby/io.h	(revision 19102)
+++ include/ruby/io.h	(revision 19103)
@@ -57,7 +57,7 @@
     struct rb_io_enc_t {
         rb_encoding *enc;
         rb_encoding *enc2;
-        rb_econv_option_t opts;
+        int flags;
     } encs;
 
     rb_econv_t *readconv;
@@ -68,7 +68,7 @@
 
     rb_econv_t *writeconv;
     VALUE writeconv_stateless;
-    rb_econv_option_t writeconv_pre_opts;
+    int writeconv_pre_flags;
     int writeconv_initialized;
 
 } rb_io_t;
@@ -127,7 +127,7 @@
     fp->tied_io_for_writing = 0;\
     fp->encs.enc = NULL;\
     fp->encs.enc2 = NULL;\
-    fp->encs.opts.flags = 0;\
+    fp->encs.flags = 0;\
 } while (0)
 
 FILE *rb_io_stdio_file(rb_io_t *fptr);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19102)
+++ ChangeLog	(revision 19103)
@@ -1,3 +1,15 @@
+Thu Sep  4 00:09:05 2008  Tanaka Akira  <akr@f...>
+
+	* include/ruby/encoding.h (rb_econv_option_t): removed.  Since
+	  rb_econv_option_t has only one field, int flags, rb_econv_option_t is
+	  replaced by int.
+
+	* include/ruby/io.h: follow the above change.
+
+	* io.c: ditto.
+
+	* transcode.c: ditto.
+
 Thu Sep  4 00:04:59 2008  Koichi Sasada  <ko1@a...>
 
 	* win32/win32.c: fix ruby/signal.h depending codes.
Index: io.c
===================================================================
--- io.c	(revision 19102)
+++ io.c	(revision 19103)
@@ -690,22 +690,22 @@
     if (!fptr->writeconv_initialized) {
         const char *senc, *denc;
         rb_encoding *enc;
-        rb_econv_option_t ecopts;
+        int ecflags;
 
         fptr->writeconv_initialized = 1;
 
         /* ECONV_INVALID_XXX and ECONV_UNDEF_XXX should be set both.
          * But ECONV_CRLF_NEWLINE_ENCODER should be set only for the first. */
-        fptr->writeconv_pre_opts = fptr->encs.opts;
-        ecopts = fptr->encs.opts;
+        fptr->writeconv_pre_flags = fptr->encs.flags;
+        ecflags = fptr->encs.flags;
 
 #ifdef TEXTMODE_NEWLINE_ENCODER
         if (!fptr->encs.enc) {
             if (NEED_NEWLINE_ENCODER(fptr))
-                ecopts.flags |= TEXTMODE_NEWLINE_ENCODER;
-            fptr->writeconv = rb_econv_open("", "", &ecopts);
+                ecflags |= TEXTMODE_NEWLINE_ENCODER;
+            fptr->writeconv = rb_econv_open("", "", ecflags);
             if (!fptr->writeconv)
-                rb_exc_raise(rb_econv_open_exc("", "", &ecopts));
+                rb_exc_raise(rb_econv_open_exc("", "", ecflags));
             fptr->writeconv_stateless = Qnil;
             return;
         }
@@ -719,9 +719,9 @@
         if (senc) {
             denc = enc->name;
             fptr->writeconv_stateless = rb_str_new2(senc);
-            fptr->writeconv = rb_econv_open(senc, denc, &ecopts);
+            fptr->writeconv = rb_econv_open(senc, denc, ecflags);
             if (!fptr->writeconv)
-                rb_exc_raise(rb_econv_open_exc(senc, denc, &ecopts));
+                rb_exc_raise(rb_econv_open_exc(senc, denc, ecflags));
         }
         else {
             denc = NULL;
@@ -753,7 +753,7 @@
         }
 
         if (!NIL_P(common_encoding)) {
-            str = rb_str_transcode(str, common_encoding, &fptr->writeconv_pre_opts);
+            str = rb_str_transcode(str, common_encoding, fptr->writeconv_pre_flags);
         }
 
         if (fptr->writeconv) {
@@ -1437,11 +1437,11 @@
 make_readconv(rb_io_t *fptr)
 {
     if (!fptr->readconv) {
-        rb_econv_option_t ecopts;
+        int ecflags;
         const char *sname, *dname;
-        ecopts = fptr->encs.opts;
+        ecflags = fptr->encs.flags;
         if (NEED_NEWLINE_DECODER(fptr))
-            ecopts.flags |= ECONV_UNIVERSAL_NEWLINE_DECODER;
+            ecflags |= ECONV_UNIVERSAL_NEWLINE_DECODER;
         if (fptr->encs.enc2) {
             sname = fptr->encs.enc2->name;
             dname = fptr->encs.enc->name;
@@ -1449,9 +1449,9 @@
         else {
             sname = dname = "";
         }
-        fptr->readconv = rb_econv_open(sname, dname, &ecopts);
+        fptr->readconv = rb_econv_open(sname, dname, ecflags);
         if (!fptr->readconv)
-            rb_exc_raise(rb_econv_open_exc(sname, dname, &ecopts));
+            rb_exc_raise(rb_econv_open_exc(sname, dname, ecflags));
         fptr->cbuf_off = 0;
         fptr->cbuf_len = 0;
         fptr->cbuf_capa = 1024;
@@ -3832,7 +3832,7 @@
     VALUE mode;
     int modenum, flags;
     rb_encoding *enc, *enc2;
-    rb_econv_option_t ecopts;
+    int ecflags;
     int has_enc = 0;
     VALUE intmode;
 
@@ -3864,7 +3864,7 @@
     }
 
     if (NIL_P(opthash)) {
-        rb_econv_opts(Qnil, &ecopts);
+        ecflags = 0;
     }
     else {
 	VALUE v;
@@ -3878,7 +3878,7 @@
             modenum |= O_BINARY;
 #endif
         }
-        rb_econv_opts(opthash, &ecopts);
+        ecflags = rb_econv_flags(opthash);
 
         if (io_extract_encoding_option(opthash, &enc, &enc2)) {
             if (has_enc) {
@@ -3896,7 +3896,7 @@
     *flags_p = flags;
     convconfig_p->enc = enc;
     convconfig_p->enc2 = enc2;
-    convconfig_p->opts = ecopts;
+    convconfig_p->flags = ecflags;
 }
 
 struct sysopen_struct {
@@ -4004,7 +4004,7 @@
     else {
         fptr->encs.enc = NULL;
         fptr->encs.enc2 = NULL;
-        rb_econv_opts(Qnil, &fptr->encs.opts);
+        fptr->encs.flags = 0;
     }
     fptr->pathv = rb_str_new_frozen(filename);
     fptr->fd = rb_sysopen(RSTRING_PTR(fptr->pathv), modenum, perm);
@@ -4026,7 +4026,7 @@
     else {
         convconfig.enc = NULL;
         convconfig.enc2 = NULL;
-        rb_econv_opts(Qnil, &convconfig.opts);
+        convconfig.flags = 0;
     }
 
     flags = rb_io_mode_flags(mode);
@@ -5011,7 +5011,7 @@
 	}
 	fptr->mode = flags;
 	rb_io_mode_enc(fptr, StringValueCStr(nmode));
-        rb_econv_opts(Qnil, &fptr->encs.opts);
+        fptr->encs.flags = 0;
     }
 
     fptr->pathv = rb_str_new_frozen(fname);
@@ -5698,7 +5698,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 argf_ecflags       ARGF.encs.flags
 #define rb_argv           ARGF.argv
 
 static VALUE
@@ -5870,7 +5870,7 @@
 		GetOpenFile(current_file, fptr);
 		fptr->encs.enc = argf_enc;
 		fptr->encs.enc2 = argf_enc2;
-		fptr->encs.opts = argf_ecopts;
+		fptr->encs.flags = argf_ecflags;
                 clear_codeconv(fptr);
 	    }
 	}
@@ -6595,26 +6595,26 @@
     if (argc == 2) {
 	fptr->encs.enc2 = rb_to_encoding(v1);
 	fptr->encs.enc = rb_to_encoding(v2);
-        rb_econv_opts(opt, &fptr->encs.opts);
+        fptr->encs.flags = rb_econv_flags(opt);
         clear_codeconv(fptr);
     }
     else if (argc == 1) {
 	if (NIL_P(v1)) {
 	    fptr->encs.enc = NULL;
 	    fptr->encs.enc2 = NULL;
-            rb_econv_opts(Qnil, &fptr->encs.opts);
+            fptr->encs.flags = 0;
             clear_codeconv(fptr);
 	}
 	else {
 	    VALUE tmp = rb_check_string_type(v1);
 	    if (!NIL_P(tmp)) {
 		mode_enc(fptr, StringValueCStr(tmp));
-                rb_econv_opts(opt, &fptr->encs.opts);
+                fptr->encs.flags = rb_econv_flags(opt);
 	    }
 	    else {
 		fptr->encs.enc = rb_to_encoding(v1);
 		fptr->encs.enc2 = NULL;
-                rb_econv_opts(Qnil, &fptr->encs.opts);
+                fptr->encs.flags = 0;
                 clear_codeconv(fptr);
 	    }
 	}
@@ -7547,7 +7547,7 @@
     GetOpenFile(current_file, fptr);
     argf_enc = fptr->encs.enc;
     argf_enc2 = fptr->encs.enc2;
-    argf_ecopts = fptr->encs.opts;
+    argf_ecflags = fptr->encs.flags;
     return argf;
 }
 
Index: transcode.c
===================================================================
--- transcode.c	(revision 19102)
+++ transcode.c	(revision 19103)
@@ -83,7 +83,7 @@
 } rb_econv_elem_t;
 
 struct rb_econv_t {
-    rb_econv_option_t opts;
+    int flags;
     const char *source_encoding_name;
     const char *destination_encoding_name;
 
@@ -790,7 +790,7 @@
     }
 
     ec = ALLOC(rb_econv_t);
-    ec->opts.flags = 0;
+    ec->flags = 0;
     ec->source_encoding_name = NULL;
     ec->destination_encoding_name = NULL;
     ec->in_buf_start = NULL;
@@ -855,13 +855,12 @@
 }
 
 rb_econv_t *
-rb_econv_open(const char *from, const char *to, rb_econv_option_t *opts)
+rb_econv_open(const char *from, const char *to, int ecflags)
 {
     transcoder_entry_t **entries = NULL;
     int num_trans;
     int num_additional;
     static rb_econv_t *ec;
-    int flags = opts ? opts->flags : 0;
     int universal_newline_decoder_added = 0;
 
     rb_encoding *senc, *denc;
@@ -898,13 +897,13 @@
 
     num_additional = 0;
     if ((!*from || (senc && rb_enc_asciicompat(senc))) &&
-        (flags & (ECONV_CRLF_NEWLINE_ENCODER|ECONV_CR_NEWLINE_ENCODER))) {
-        const char *name = (flags & ECONV_CRLF_NEWLINE_ENCODER) ? "crlf_newline" : "cr_newline";
+        (ecflags & (ECONV_CRLF_NEWLINE_ENCODER|ECONV_CR_NEWLINE_ENCODER))) {
+        const char *name = (ecflags & ECONV_CRLF_NEWLINE_ENCODER) ? "crlf_newline" : "cr_newline";
         transcoder_entry_t *e = get_transcoder_entry("", name);
-        if (flags & ECONV_CRLF_NEWLINE_ENCODER)
-            flags &= ~ECONV_CR_NEWLINE_ENCODER;
+        if (ecflags & ECONV_CRLF_NEWLINE_ENCODER)
+            ecflags &= ~ECONV_CR_NEWLINE_ENCODER;
         else
-            flags &= ~ECONV_CRLF_NEWLINE_ENCODER;
+            ecflags &= ~ECONV_CRLF_NEWLINE_ENCODER;
         if (!e) {
             xfree(entries);
             return NULL;
@@ -915,11 +914,11 @@
         num_additional++;
     }
     else {
-        flags &= ~(ECONV_CRLF_NEWLINE_ENCODER|ECONV_CR_NEWLINE_ENCODER);
+        ecflags &= ~(ECONV_CRLF_NEWLINE_ENCODER|ECONV_CR_NEWLINE_ENCODER);
     }
 
     if ((!*to || (denc && rb_enc_asciicompat(denc))) &&
-        (flags & ECONV_UNIVERSAL_NEWLINE_DECODER)) {
+        (ecflags & ECONV_UNIVERSAL_NEWLINE_DECODER)) {
         transcoder_entry_t *e = get_transcoder_entry("universal_newline", "");
         if (!e) {
             xfree(entries);
@@ -930,7 +929,7 @@
         universal_newline_decoder_added = 1;
     }
     else {
-        flags &= ~ECONV_UNIVERSAL_NEWLINE_DECODER;
+        ecflags &= ~ECONV_UNIVERSAL_NEWLINE_DECODER;
     }
 
     ec = rb_econv_open_by_transcoder_entries(num_trans, entries);
@@ -938,11 +937,7 @@
     if (!ec)
         return NULL;
 
-    if (!opts)
-        ec->opts.flags = 0;
-    else
-        ec->opts = *opts;
-    ec->opts.flags = flags;
+    ec->flags = ecflags;
     ec->source_encoding_name = from;
     ec->destination_encoding_name = to;
 
@@ -1283,10 +1278,10 @@
         ret == econv_incomplete_input) {
 	/* deal with invalid byte sequence */
 	/* todo: add more alternative behaviors */
-	if (ec->opts.flags&ECONV_INVALID_IGNORE) {
+	if (ec->flags&ECONV_INVALID_IGNORE) {
             goto resume;
 	}
-	else if (ec->opts.flags&ECONV_INVALID_REPLACE) {
+	else if (ec->flags&ECONV_INVALID_REPLACE) {
 	    if (output_replacement_character(ec) == 0)
                 goto resume;
 	}
@@ -1296,10 +1291,10 @@
 	/* valid character in source encoding
 	 * but no related character(s) in destination encoding */
 	/* todo: add more alternative behaviors */
-	if (ec->opts.flags&ECONV_UNDEF_IGNORE) {
+	if (ec->flags&ECONV_UNDEF_IGNORE) {
 	    goto resume;
 	}
-	else if (ec->opts.flags&ECONV_UNDEF_REPLACE) {
+	else if (ec->flags&ECONV_UNDEF_REPLACE) {
 	    if (output_replacement_character(ec) == 0)
                 goto resume;
 	}
@@ -1342,7 +1337,7 @@
     if (dst_bufsize == 0)
         dst_bufsize += 1;
 
-    ec = rb_econv_open(str_encoding, insert_encoding, NULL);
+    ec = rb_econv_open(str_encoding, insert_encoding, 0);
     if (ec == NULL)
         return NULL;
     dst_str = xmalloc(dst_bufsize);
@@ -1615,7 +1610,7 @@
 void
 rb_econv_binmode(rb_econv_t *ec)
 {
-    if (ec->opts.flags & ECONV_UNIVERSAL_NEWLINE_DECODER) {
+    if (ec->flags & ECONV_UNIVERSAL_NEWLINE_DECODER) {
         int i = ec->num_trans-1;
         rb_transcoding_close(ec->elems[i].tc);
         xfree(ec->elems[i].out_buf_start);
@@ -1625,21 +1620,20 @@
         ec->elems[i].out_data_end = NULL;
         ec->elems[i].out_buf_end = NULL;
         ec->num_trans--;
-        ec->opts.flags &= ~ECONV_UNIVERSAL_NEWLINE_DECODER;
+        ec->flags &= ~ECONV_UNIVERSAL_NEWLINE_DECODER;
     }
-    if (ec->opts.flags & (ECONV_CRLF_NEWLINE_ENCODER|ECONV_CR_NEWLINE_ENCODER)) {
+    if (ec->flags & (ECONV_CRLF_NEWLINE_ENCODER|ECONV_CR_NEWLINE_ENCODER)) {
         rb_transcoding_close(ec->elems[0].tc);
         xfree(ec->elems[0].out_buf_start);
         MEMMOVE(&ec->elems[0], &ec->elems[1], rb_econv_elem_t, ec->num_trans-1);
         ec->num_trans--;
-        ec->opts.flags &= ~(ECONV_CRLF_NEWLINE_ENCODER|ECONV_CR_NEWLINE_ENCODER);
+        ec->flags &= ~(ECONV_CRLF_NEWLINE_ENCODER|ECONV_CR_NEWLINE_ENCODER);
     }
 }
 
 static VALUE
-econv_description(const char *senc, const char *denc, rb_econv_option_t *opts, VALUE mesg)
+econv_description(const char *senc, const char *denc, int ecflags, VALUE mesg)
 {
-    int flags = opts ? opts->flags : 0;
     int has_description = 0;
 
     if (NIL_P(mesg))
@@ -1655,21 +1649,21 @@
         has_description = 1;
     }
 
-    if (flags & (ECONV_UNIVERSAL_NEWLINE_DECODER|
-                 ECONV_CRLF_NEWLINE_ENCODER|
-                 ECONV_CR_NEWLINE_ENCODER)) {
+    if (ecflags & (ECONV_UNIVERSAL_NEWLINE_DECODER|
+                   ECONV_CRLF_NEWLINE_ENCODER|
+                   ECONV_CR_NEWLINE_ENCODER)) {
         const char *pre = "";
         if (has_description)
             rb_str_cat2(mesg, " with ");
-        if (flags & ECONV_UNIVERSAL_NEWLINE_DECODER)  {
+        if (ecflags & ECONV_UNIVERSAL_NEWLINE_DECODER)  {
             rb_str_cat2(mesg, pre); pre = ",";
             rb_str_cat2(mesg, "Universal-newline");
         }
-        if (flags & ECONV_CRLF_NEWLINE_ENCODER) {
+        if (ecflags & ECONV_CRLF_NEWLINE_ENCODER) {
             rb_str_cat2(mesg, pre); pre = ",";
             rb_str_cat2(mesg, "CRLF-newline");
         }
-        if (flags & ECONV_CR_NEWLINE_ENCODER) {
+        if (ecflags & ECONV_CR_NEWLINE_ENCODER) {
             rb_str_cat2(mesg, pre); pre = ",";
             rb_str_cat2(mesg, "CR-newline");
         }
@@ -1683,11 +1677,11 @@
 }
 
 VALUE
-rb_econv_open_exc(const char *senc, const char *denc, rb_econv_option_t *opts)
+rb_econv_open_exc(const char *senc, const char *denc, int ecflags)
 {
     VALUE mesg, exc;
     mesg = rb_str_new_cstr("code converter open failed (");
-    econv_description(senc, denc, opts, mesg);
+    econv_description(senc, denc, ecflags, mesg);
     rb_str_cat2(mesg, ")");
     exc = rb_exc_new3(rb_eNoConverter, mesg);
     return exc;
@@ -1816,7 +1810,7 @@
                unsigned char *(*resize_destination)(VALUE, int, int),
                const char *from_encoding,
                const char *to_encoding,
-               rb_econv_option_t *ecopts)
+               int ecflags)
 {
     rb_econv_t *ec;
     rb_transcoding *last_tc;
@@ -1825,9 +1819,9 @@
     int max_output;
     VALUE exc;
 
-    ec = rb_econv_open(from_encoding, to_encoding, ecopts);
+    ec = rb_econv_open(from_encoding, to_encoding, ecflags);
     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, ecflags));
 
     last_tc = ec->last_tc;
     max_output = last_tc ? last_tc->transcoder->max_output : 1;
@@ -1860,7 +1854,7 @@
                unsigned char *(*resize_destination)(VALUE, int, int),
                const char *from_encoding,
                const char *to_encoding,
-               rb_econv_option_t *ecopts)
+               int ecflags)
 {
     rb_econv_t *ec;
     rb_transcoding *last_tc;
@@ -1870,9 +1864,9 @@
     int max_output;
     VALUE exc;
 
-    ec = rb_econv_open(from_encoding, to_encoding, ecopts);
+    ec = rb_econv_open(from_encoding, to_encoding, ecflags);
     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, ecflags));
 
     last_tc = ec->last_tc;
     max_output = last_tc ? last_tc->transcoder->max_output : 1;
@@ -1968,13 +1962,13 @@
     return options;
 }
 
-void
-rb_econv_opts(VALUE hash, rb_econv_option_t *opts)
+int
+rb_econv_flags(VALUE hash)
 {
     if (NIL_P(hash))
-        opts->flags = 0;
+        return 0;
     else
-        opts->flags = econv_opts(hash);
+        return econv_opts(hash);
 }
 
 static int
@@ -2018,7 +2012,7 @@
 }
 
 static int
-str_transcode0(int argc, VALUE *argv, VALUE *self, rb_econv_option_t *ecopts_arg)
+str_transcode0(int argc, VALUE *argv, VALUE *self, int ecflags)
 {
     VALUE dest;
     VALUE str = *self;
@@ -2028,7 +2022,6 @@
     rb_encoding *from_enc, *to_enc;
     const char *from_e, *to_e;
     int to_encidx;
-    rb_econv_option_t ecopts;
 
     if (argc < 1 || argc > 2) {
 	rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..2)", argc);
@@ -2036,14 +2029,9 @@
 
     to_encidx = str_transcode_enc_args(str, argv[0], argc==1 ? Qnil : argv[1], &from_e, &from_enc, &to_e, &to_enc);
 
-    if (ecopts_arg)
-        ecopts = *ecopts_arg;
-    else
-        rb_econv_opts(Qnil, &ecopts);
-
-    if ((ecopts.flags & (ECONV_UNIVERSAL_NEWLINE_DECODER|
-                         ECONV_CRLF_NEWLINE_ENCODER|
-                         ECONV_CR_NEWLINE_ENCODER)) == 0) {
+    if ((ecflags & (ECONV_UNIVERSAL_NEWLINE_DECODER|
+                    ECONV_CRLF_NEWLINE_ENCODER|
+                    ECONV_CR_NEWLINE_ENCODER)) == 0) {
         if (from_enc && from_enc == to_enc) {
             return -1;
         }
@@ -2069,7 +2057,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, &ecopts);
+    transcode_loop(&fromp, &bp, (sp+slen), (bp+blen), dest, str_transcoding_resize, from_e, to_e, ecflags);
     if (fromp != sp+slen) {
         rb_raise(rb_eArgError, "not fully converted, %"PRIdPTRDIFF" bytes left", sp+slen-fromp);
     }
@@ -2090,17 +2078,16 @@
 str_transcode(int argc, VALUE *argv, VALUE *self)
 {
     VALUE opt;
-    rb_econv_option_t ecopts;
-    ecopts.flags = 0;
+    int ecflags = 0;
 
     if (0 < argc) {
         opt = rb_check_convert_type(argv[argc-1], T_HASH, "Hash", "to_hash");
         if (!NIL_P(opt)) {
             argc--;
-            rb_econv_opts(opt, &ecopts);
+            ecflags = rb_econv_flags(opt);
         }
     }
-    return str_transcode0(argc, argv, self, &ecopts);
+    return str_transcode0(argc, argv, self, ecflags);
 }
 
 static inline VALUE
@@ -2171,12 +2158,12 @@
 }
 
 VALUE
-rb_str_transcode(VALUE str, VALUE to, rb_econv_option_t *ecopts)
+rb_str_transcode(VALUE str, VALUE to, int ecflags)
 {
     int argc = 1;
     VALUE *argv = &to;
     VALUE newstr = str;
-    int encidx = str_transcode0(argc, argv, &newstr, ecopts);
+    int encidx = str_transcode0(argc, argv, &newstr, ecflags);
 
     if (encidx < 0) return rb_str_dup(str);
     RBASIC(newstr)->klass = rb_obj_class(str);
@@ -2243,14 +2230,14 @@
     const char *sname, *dname;
     rb_encoding *senc, *denc;
     rb_econv_t *ec;
-    rb_econv_option_t ecopts;
+    int ecflags;
 
     rb_scan_args(argc, argv, "21", &source_encoding, &destination_encoding, &flags_v);
 
     if (flags_v == Qnil)
-        ecopts.flags = 0;
+        ecflags = 0;
     else
-        ecopts.flags = NUM2INT(flags_v);
+        ecflags = NUM2INT(flags_v);
 
     senc = NULL;
     sidx = rb_to_encoding_index(source_encoding);
@@ -2277,9 +2264,9 @@
         rb_raise(rb_eTypeError, "already initialized");
     }
 
-    ec = rb_econv_open(sname, dname, &ecopts);
+    ec = rb_econv_open(sname, dname, ecflags);
     if (!ec) {
-        rb_exc_raise(rb_econv_open_exc(sname, dname, &ecopts));
+        rb_exc_raise(rb_econv_open_exc(sname, dname, ecflags));
     }
 
     if (*sname && *dname) { /* check "" to "universal_newline" */
@@ -2329,7 +2316,7 @@
         const char *dname = ec->destination_encoding_name;
         VALUE str;
         str = rb_sprintf("#<%s: ", cname);
-        econv_description(sname, dname, &ec->opts, str);
+        econv_description(sname, dname, ec->flags, str);
         rb_str_cat2(str, ">");
         return str;
     }

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

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