diff --git a/ChangeLog b/ChangeLog index e9a7caa710..0995d34521 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Sat Aug 16 15:23:16 2008 Tanaka Akira + + * include/ruby/encoding.h (rb_econv_elem_t): fields removed: from and + to. + (rb_econv_t): new fields: source_encoding_name and + destination_encoding_name. + + * transcode.c (rb_econv_open_by_transcoder_entries): initialize the + new fields. + (rb_econv_open): set up the new fields. + (econv_inspect): use the new fields. + Sat Aug 16 14:22:04 2008 Tanaka Akira * include/ruby/encoding.h (rb_econv_t): add fields: in_buf_start, diff --git a/include/ruby/encoding.h b/include/ruby/encoding.h index 2d43ca354a..16cfef2539 100644 --- a/include/ruby/encoding.h +++ b/include/ruby/encoding.h @@ -208,8 +208,6 @@ typedef enum { } rb_econv_result_t; typedef struct { - const char *from; - const char *to; struct rb_transcoding *tc; unsigned char *out_buf_start; unsigned char *out_data_start; @@ -219,6 +217,9 @@ typedef struct { } rb_econv_elem_t; typedef struct { + const char *source_encoding_name; + const char *destination_encoding_name; + unsigned char *in_buf_start; unsigned char *in_data_start; unsigned char *in_data_end; diff --git a/transcode.c b/transcode.c index 9753e88c33..7e6e2ff2b4 100644 --- a/transcode.c +++ b/transcode.c @@ -677,6 +677,8 @@ rb_econv_open_by_transcoder_entries(int n, transcoder_entry_t **entries) } ec = ALLOC(rb_econv_t); + ec->source_encoding_name = NULL; + ec->destination_encoding_name = NULL; ec->in_buf_start = NULL; ec->in_data_start = NULL; ec->in_data_end = NULL; @@ -690,8 +692,6 @@ rb_econv_open_by_transcoder_entries(int n, transcoder_entry_t **entries) ec->destination_encoding = NULL; for (i = 0; i < ec->num_trans; i++) { const rb_transcoder *tr = load_transcoder_entry(entries[i]); - ec->elems[i].from = tr->from_encoding; - ec->elems[i].to = tr->to_encoding; ec->elems[i].tc = rb_transcoding_open_by_transcoder(tr, 0); ec->elems[i].out_buf_start = NULL; ec->elems[i].out_data_start = NULL; @@ -761,6 +761,11 @@ rb_econv_open(const char *from, const char *to, int flags) } ec = rb_econv_open_by_transcoder_entries(num_trans, entries); + if (!ec) + rb_raise(rb_eArgError, "encoding conversion not supported (from %s to %s)", from, to); + + ec->source_encoding_name = from; + ec->destination_encoding_name = to; if (flags & ECONV_UNIVERSAL_NEWLINE_DECODER) { ec->last_tc = ec->elems[ec->num_trans-2].tc; @@ -1687,6 +1692,9 @@ econv_init(int argc, VALUE *argv, VALUE self) ec->source_encoding = senc; ec->destination_encoding = denc; + ec->source_encoding_name = ec->elems[0].tc->transcoder->from_encoding; + ec->destination_encoding_name = ec->last_tc->transcoder->to_encoding; + DATA_PTR(self) = ec; return self; @@ -1702,8 +1710,8 @@ econv_inspect(VALUE self) return rb_sprintf("#<%s: uninitialized>", cname); else return rb_sprintf("#<%s: %s to %s>", cname, - ec->elems[0].from, - ec->last_tc->transcoder->to_encoding); + ec->source_encoding_name, + ec->destination_encoding_name); } #define IS_ECONV(obj) (RDATA(obj)->dfree == (RUBY_DATA_FUNC)econv_free)