From c7afd1aef49c0dc459b3d9dda6ddc51e301f5473 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 15 Oct 2009 05:21:00 +0000 Subject: [PATCH] * ext/iconv/iconv.c (iconv_create): cannot retry with given block. [ruby-dev:39487] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ ext/iconv/iconv.c | 17 ++++++++++++----- test/iconv/test_basic.rb | 5 ++++- test/iconv/test_option.rb | 2 +- test/iconv/test_partial.rb | 2 +- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index e36c9314e7..b7fd03cef4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Oct 15 14:20:58 2009 Nobuyoshi Nakada + + * ext/iconv/iconv.c (iconv_create): cannot retry with given block. + [ruby-dev:39487] + Thu Oct 15 09:25:07 2009 NAKAMURA Usaku * ext/socket/init.c (rsock_init_sock): mswin doesn't have S_IFSOCK diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index 35e5c34634..81116b9b78 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -106,6 +106,7 @@ static VALUE rb_eIconvBrokenLibrary; static ID rb_success, rb_failed; static VALUE iconv_fail _((VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, const char *mesg)); +static VALUE iconv_fail_retry _((VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, const char *mesg)); static VALUE iconv_failure_initialize _((VALUE error, VALUE mesg, VALUE success, VALUE failed)); static VALUE iconv_failure_success _((VALUE self)); static VALUE iconv_failure_failed _((VALUE self)); @@ -231,8 +232,8 @@ iconv_create(VALUE to, VALUE from, struct rb_iconv_opt_t *opt, int *idx) s = RSTRING_PTR(msg); rb_str_set_len(msg, strlen(s)); if (!inval) rb_sys_fail(s); - iconv_fail(rb_eIconvInvalidEncoding, - Qnil, rb_ary_new3(2, to, from), NULL, s); + rb_exc_raise(iconv_fail(rb_eIconvInvalidEncoding, Qnil, + rb_ary_new3(2, to, from), NULL, s)); } } @@ -372,7 +373,13 @@ iconv_fail(VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, co args[2] = rb_ary_new4(env->argc, env->argv); } } - error = rb_class_new_instance(3, args, error); + return rb_class_new_instance(3, args, error); +} + +static VALUE +iconv_fail_retry(VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, const char *mesg) +{ + error = iconv_fail(error, success, failed, env, mesg); if (!rb_block_given_p()) rb_exc_raise(error); rb_set_errinfo(error); return rb_yield(failed); @@ -418,7 +425,7 @@ iconv_convert(iconv_t cd, VALUE str, long start, long length, int toidx, struct error = iconv_try(cd, &inptr, &inlen, &outptr, &outlen); if (RTEST(error)) { unsigned int i; - rescue = iconv_fail(error, Qnil, Qnil, env, 0); + rescue = iconv_fail_retry(error, Qnil, Qnil, env, 0); if (TYPE(rescue) == T_ARRAY) { str = RARRAY_LEN(rescue) > 0 ? RARRAY_PTR(rescue)[0] : Qnil; } @@ -502,7 +509,7 @@ iconv_convert(iconv_t cd, VALUE str, long start, long length, int toidx, struct rb_str_cat(ret, instart, inptr - instart); } str = rb_str_derive(str, inptr, inlen); - rescue = iconv_fail(error, ret, str, env, errmsg); + rescue = iconv_fail_retry(error, ret, str, env, errmsg); if (TYPE(rescue) == T_ARRAY) { if ((len = RARRAY_LEN(rescue)) > 0) rb_str_concat(ret, RARRAY_PTR(rescue)[0]); diff --git a/test/iconv/test_basic.rb b/test/iconv/test_basic.rb index 394d271bc1..2575b22eb9 100644 --- a/test/iconv/test_basic.rb +++ b/test/iconv/test_basic.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), "utils.rb") +require File.expand_path("../utils.rb", __FILE__) class TestIconv::Basic < TestIconv def test_euc2sjis @@ -52,5 +52,8 @@ class TestIconv::Basic < TestIconv def test_unknown_encoding assert_raise(Iconv::InvalidEncoding) { Iconv.iconv("utf-8", "X-UKNOWN", "heh") } + assert_raise(Iconv::InvalidEncoding, '[ruby-dev:39487]') { + Iconv.iconv("X-UNKNOWN-1", "X-UNKNOWN-2") {break} + } end end if defined?(TestIconv) diff --git a/test/iconv/test_option.rb b/test/iconv/test_option.rb index 340218b48b..b210fa498a 100644 --- a/test/iconv/test_option.rb +++ b/test/iconv/test_option.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), "utils.rb") +require File.expand_path("../utils.rb", __FILE__) class TestIconv::Option < TestIconv def test_ignore_option diff --git a/test/iconv/test_partial.rb b/test/iconv/test_partial.rb index aa4d0ba250..a98960b070 100644 --- a/test/iconv/test_partial.rb +++ b/test/iconv/test_partial.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), "utils.rb") +require File.expand_path("../utils.rb", __FILE__) class TestIconv::Partial < TestIconv def test_partial_ascii