ruby-changes:7331
From: akr <ko1@a...>
Date: Tue, 26 Aug 2008 00:27:07 +0900 (JST)
Subject: [ruby-changes:7331] Ruby:r18850 (trunk): * transcode.c (make_econv_exception): show readagain part for invalid
akr 2008-08-26 00:26:54 +0900 (Tue, 26 Aug 2008) New Revision: 18850 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18850 Log: * transcode.c (make_econv_exception): show readagain part for invalid byte sequence exception. store the part as an instance variable. (ecerr_readagain_bytes): new method to access the readagain part. Modified files: trunk/ChangeLog trunk/test/ruby/test_econv.rb trunk/transcode.c Index: ChangeLog =================================================================== --- ChangeLog (revision 18849) +++ ChangeLog (revision 18850) @@ -1,3 +1,9 @@ +Tue Aug 26 00:24:23 2008 Tanaka Akira <akr@f...> + + * transcode.c (make_econv_exception): show readagain part for invalid + byte sequence exception. store the part as an instance variable. + (ecerr_readagain_bytes): new method to access the readagain part. + Tue Aug 26 00:02:49 2008 Yusuke Endoh <mame@t...> * ext/bigdecimal/bigdecimal.c (VpMult): fix double free. Index: test/ruby/test_econv.rb =================================================================== --- test/ruby/test_econv.rb (revision 18849) +++ test/ruby/test_econv.rb (revision 18850) @@ -425,6 +425,7 @@ assert_equal("EUC-JP", err.source_encoding) assert_equal("UTF-8", err.destination_encoding) assert_equal("\xA4".force_encoding("ASCII-8BIT"), err.error_bytes) + assert_equal("d", err.readagain_bytes) end def test_exc_undef Index: transcode.c =================================================================== --- transcode.c (revision 18849) +++ transcode.c (revision 18850) @@ -1547,17 +1547,32 @@ { VALUE mesg, exc; if (ec->last_error.result == econv_invalid_byte_sequence) { - VALUE bytes = rb_str_new((const char *)ec->last_error.error_bytes_start, - ec->last_error.error_bytes_len); - VALUE dumped; - dumped = rb_str_dump(bytes); - mesg = rb_sprintf("invalid byte sequence: %s on %s", - StringValueCStr(dumped), - ec->last_error.source_encoding); + const char *err = (const char *)ec->last_error.error_bytes_start; + size_t error_len = ec->last_error.error_bytes_len; + VALUE bytes = rb_str_new(err, error_len); + VALUE dumped = rb_str_dump(bytes); + size_t readagain_len = ec->last_error.readagain_len; + VALUE bytes2 = Qnil; + VALUE dumped2; + if (readagain_len) { + bytes2 = rb_str_new(err+error_len, readagain_len); + dumped2 = rb_str_dump(bytes2); + mesg = rb_sprintf("invalid byte sequence: %s followed by %s on %s", + StringValueCStr(dumped), + StringValueCStr(dumped2), + ec->last_error.source_encoding); + } + else { + mesg = rb_sprintf("invalid byte sequence: %s on %s", + StringValueCStr(dumped), + ec->last_error.source_encoding); + } + exc = rb_exc_new3(rb_eInvalidByteSequence, mesg); rb_ivar_set(exc, rb_intern("source_encoding"), rb_str_new2(ec->last_error.source_encoding)); rb_ivar_set(exc, rb_intern("destination_encoding"), rb_str_new2(ec->last_error.destination_encoding)); rb_ivar_set(exc, rb_intern("error_bytes"), bytes); + rb_ivar_set(exc, rb_intern("readagain_bytes"), bytes2); return exc; } if (ec->last_error.result == econv_undefined_conversion) { @@ -2514,6 +2529,12 @@ return rb_attr_get(self, rb_intern("error_bytes")); } +static VALUE +ecerr_readagain_bytes(VALUE self) +{ + return rb_attr_get(self, rb_intern("readagain_bytes")); +} + extern void Init_newline(void); void @@ -2562,6 +2583,7 @@ rb_define_method(rb_eInvalidByteSequence, "source_encoding", ecerr_source_encoding, 0); rb_define_method(rb_eInvalidByteSequence, "destination_encoding", ecerr_destination_encoding, 0); rb_define_method(rb_eInvalidByteSequence, "error_bytes", ecerr_error_bytes, 0); + rb_define_method(rb_eInvalidByteSequence, "readagain_bytes", ecerr_readagain_bytes, 0); Init_newline(); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/