summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog13
-rw-r--r--include/ruby/encoding.h8
-rw-r--r--io.c31
-rw-r--r--transcode.c33
4 files changed, 53 insertions, 32 deletions
diff --git a/ChangeLog b/ChangeLog
index 624aa45a2..f7f0d1467 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+Sun Aug 24 16:06:30 2008 Tanaka Akira <akr@fsij.org>
+
+ * include/ruby/encoding.h (rb_econv_option_t): defined.
+ (rb_econv_open): 3rd arg changed.
+ (rb_econv_open_exc): ditto.
+
+ * io.c (make_writeconv): use rb_econv_option_t.
+ (make_readconv): ditto.
+ (rb_econv_open): take rb_econv_option_t for options.
+ (rb_econv_open_exc): ditto.
+ (transcode_loop): use rb_econv_option_t.
+ (econv_init): use rb_econv_option_t.
+
Sun Aug 24 15:43:41 2008 Tanaka Akira <akr@fsij.org>
* transcode.c (rb_econv_substr_append): associate dst with destination
diff --git a/include/ruby/encoding.h b/include/ruby/encoding.h
index 3701b2d12..b952c7402 100644
--- a/include/ruby/encoding.h
+++ b/include/ruby/encoding.h
@@ -249,14 +249,18 @@ typedef struct {
rb_encoding *destination_encoding;
} rb_econv_t;
-rb_econv_t *rb_econv_open(const char *source_encoding, const char *destination_encoding, int flags);
+typedef struct {
+ int flags;
+} rb_econv_option_t;
+
+rb_econv_t *rb_econv_open(const char *source_encoding, const char *destination_encoding, rb_econv_option_t *opts);
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, int flags);
+VALUE rb_econv_open_exc(const char *senc, const char *denc, rb_econv_option_t *opts);
/* result: 0:success -1:failure */
int rb_econv_insert_output(rb_econv_t *ec,
diff --git a/io.c b/io.c
index 69ed01caa..147670e49 100644
--- a/io.c
+++ b/io.c
@@ -694,25 +694,25 @@ make_writeconv(rb_io_t *fptr)
if (!fptr->writeconv_initialized) {
const char *senc, *denc;
rb_encoding *enc;
- int ecflags;
+ rb_econv_option_t ecopts;
fptr->writeconv_initialized = 1;
- ecflags = 0;
+ 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;
+ ecopts.flags |= (fptr->mode / (FMODE_UNDEF_MASK/ECONV_UNDEF_MASK)) & ECONV_UNDEF_MASK;
#ifdef TEXTMODE_NEWLINE_ENCODER
if (NEED_NEWLINE_ENCODER(fptr))
- ecflags |= TEXTMODE_NEWLINE_ENCODER;
+ ecopts.flags |= TEXTMODE_NEWLINE_ENCODER;
if (!fptr->enc) {
- fptr->writeconv = rb_econv_open("", "", ecflags);
+ fptr->writeconv = rb_econv_open("", "", &ecopts);
if (!fptr->writeconv)
- rb_exc_raise(rb_econv_open_exc("", "", ecflags));
+ rb_exc_raise(rb_econv_open_exc("", "", &ecopts));
fptr->writeconv_stateless = Qnil;
return;
}
@@ -729,9 +729,9 @@ make_writeconv(rb_io_t *fptr)
fptr->writeconv_stateless = Qnil;
}
if (senc) {
- fptr->writeconv = rb_econv_open(senc, denc, ecflags);
+ fptr->writeconv = rb_econv_open(senc, denc, &ecopts);
if (!fptr->writeconv)
- rb_exc_raise(rb_econv_open_exc(senc, denc, ecflags));
+ rb_exc_raise(rb_econv_open_exc(senc, denc, &ecopts));
}
else {
fptr->writeconv = NULL;
@@ -1451,14 +1451,15 @@ static void
make_readconv(rb_io_t *fptr)
{
if (!fptr->readconv) {
- int ecflags = 0;
+ rb_econv_option_t ecopts;
const char *sname, *dname;
+ ecopts.flags = 0;
if (NEED_NEWLINE_DECODER(fptr))
- ecflags |= ECONV_UNIVERSAL_NEWLINE_DECODER;
+ ecopts.flags |= ECONV_UNIVERSAL_NEWLINE_DECODER;
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;
+ ecopts.flags |= (fptr->mode / (FMODE_UNDEF_MASK/ECONV_UNDEF_MASK)) & ECONV_UNDEF_MASK;
if (fptr->enc2) {
sname = fptr->enc2->name;
dname = fptr->enc->name;
@@ -1466,9 +1467,9 @@ make_readconv(rb_io_t *fptr)
else {
sname = dname = "";
}
- fptr->readconv = rb_econv_open(sname, dname, ecflags);
+ fptr->readconv = rb_econv_open(sname, dname, &ecopts);
if (!fptr->readconv)
- rb_exc_raise(rb_econv_open_exc(sname, dname, ecflags));
+ rb_exc_raise(rb_econv_open_exc(sname, dname, &ecopts));
fptr->crbuf_off = 0;
fptr->crbuf_len = 0;
fptr->crbuf_capa = 1024;
diff --git a/transcode.c b/transcode.c
index fdabb2fd1..66287c957 100644
--- a/transcode.c
+++ b/transcode.c
@@ -733,11 +733,12 @@ trans_open_i(const char *from, const char *to, int depth, void *arg)
}
rb_econv_t *
-rb_econv_open(const char *from, const char *to, int flags)
+rb_econv_open(const char *from, const char *to, rb_econv_option_t *opts)
{
transcoder_entry_t **entries = NULL;
int num_trans;
static rb_econv_t *ec;
+ int flags = opts ? opts->flags : 0;
if (*from == '\0' && *to == '\0') {
num_trans = 0;
@@ -1123,7 +1124,7 @@ allocate_converted_string(const char *str_encoding, const char *insert_encoding,
if (dst_bufsize == 0)
dst_bufsize += 1;
- ec = rb_econv_open(str_encoding, insert_encoding, 0);
+ ec = rb_econv_open(str_encoding, insert_encoding, NULL);
if (ec == NULL)
return NULL;
dst_str = xmalloc(dst_bufsize);
@@ -1410,8 +1411,9 @@ rb_econv_binmode(rb_econv_t *ec)
}
VALUE
-rb_econv_open_exc(const char *senc, const char *denc, int flags)
+rb_econv_open_exc(const char *senc, const char *denc, rb_econv_option_t *opts)
{
+ int flags = opts ? opts->flags : 0;
VALUE mesg, exc;
int noenc = 0;
mesg = rb_str_new_cstr("code converter open failed (");
@@ -1553,12 +1555,12 @@ transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
unsigned char *out_start = *out_pos;
int max_output;
VALUE exc;
- int ecflags;
+ rb_econv_option_t ecopts;
- ecflags = opt & (ECONV_INVALID_MASK|ECONV_UNDEF_MASK);
- ec = rb_econv_open(from_encoding, to_encoding, ecflags);
+ ecopts.flags = opt & (ECONV_INVALID_MASK|ECONV_UNDEF_MASK);
+ ec = rb_econv_open(from_encoding, to_encoding, &ecopts);
if (!ec)
- rb_exc_raise(rb_econv_open_exc(from_encoding, to_encoding, ecflags));
+ 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;
@@ -1604,11 +1606,12 @@ transcode_loop(const unsigned char **in_pos, unsigned char **out_pos,
int max_output;
VALUE exc;
int ecflags;
+ rb_econv_option_t ecopts;
- ecflags = opt & (ECONV_INVALID_MASK|ECONV_UNDEF_MASK);
- ec = rb_econv_open(from_encoding, to_encoding, ecflags);
+ ecopts.flags = opt & (ECONV_INVALID_MASK|ECONV_UNDEF_MASK);
+ ec = rb_econv_open(from_encoding, to_encoding, &ecopts);
if (!ec)
- rb_exc_raise(rb_econv_open_exc(from_encoding, to_encoding, ecflags));
+ 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;
@@ -1955,14 +1958,14 @@ econv_init(int argc, VALUE *argv, VALUE self)
const char *sname, *dname;
rb_encoding *senc, *denc;
rb_econv_t *ec;
- int flags;
+ rb_econv_option_t ecopts;
rb_scan_args(argc, argv, "21", &source_encoding, &destination_encoding, &flags_v);
if (flags_v == Qnil)
- flags = 0;
+ ecopts.flags = 0;
else
- flags = NUM2INT(flags_v);
+ ecopts.flags = NUM2INT(flags_v);
senc = NULL;
sidx = rb_to_encoding_index(source_encoding);
@@ -1989,9 +1992,9 @@ econv_init(int argc, VALUE *argv, VALUE self)
rb_raise(rb_eTypeError, "already initialized");
}
- ec = rb_econv_open(sname, dname, flags);
+ ec = rb_econv_open(sname, dname, &ecopts);
if (!ec) {
- rb_exc_raise(rb_econv_open_exc(sname, dname, flags));
+ rb_exc_raise(rb_econv_open_exc(sname, dname, &ecopts));
}
if (*sname && *dname) { /* check "" to "universal_newline" */