summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-24 08:39:09 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-24 08:39:09 +0000
commit09c7eba7b1293ec187e4acd12d11887540df41a7 (patch)
treec61d7bcc69a824833c86c62fbf5f8f4a4ac8f7ae
parentd7bf4546664feb3f8b4b07817978e389e9f2b381 (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18814 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog13
-rw-r--r--include/ruby/encoding.h4
-rw-r--r--io.c9
-rw-r--r--transcode.c34
4 files changed, 35 insertions, 25 deletions
diff --git a/ChangeLog b/ChangeLog
index f70e928b40..dc789d4ab9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+Sun Aug 24 17:36:21 2008 Tanaka Akira <akr@fsij.org>
+
+ * 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@fsij.org>
* include/ruby/io.h (rb_io_t): make enc and enc2 as struct
diff --git a/include/ruby/encoding.h b/include/ruby/encoding.h
index 9f219d5880..9ad7d3b53a 100644
--- a/include/ruby/encoding.h
+++ b/include/ruby/encoding.h
@@ -194,8 +194,6 @@ rb_enc_dummy_p(rb_encoding *enc)
return ENC_DUMMY_P(enc) != 0;
}
-VALUE rb_str_transcode(VALUE str, VALUE to, int ecflags);
-
/* econv stuff */
typedef enum {
@@ -254,6 +252,8 @@ typedef struct {
/* 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);
diff --git a/io.c b/io.c
index 380c0f3116..ea1528c509 100644
--- a/io.c
+++ b/io.c
@@ -761,12 +761,13 @@ io_fwrite(VALUE str, rb_io_t *fptr)
}
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) {
diff --git a/transcode.c b/transcode.c
index 78b41724b5..34a61c3363 100644
--- a/transcode.c
+++ b/transcode.c
@@ -1547,7 +1547,7 @@ transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
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 @@ transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
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 @@ transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
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 @@ transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
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 @@ str_transcode_enc_args(VALUE str, VALUE arg1, VALUE arg2,
}
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 @@ str_transcode0(int argc, VALUE *argv, VALUE *self, int options)
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 @@ static int
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 @@ str_encode(int argc, VALUE *argv, VALUE str)
}
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);