aboutsummaryrefslogtreecommitdiffstats
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-11-11 14:04:48 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-11-11 14:04:48 +0000
commita774aa4e79933d6c96258c1660f1b8ee2a0cc349 (patch)
tree31ba3072dece02773a970855883764cc51778051 /ext
parenta77d2ac5ba56e92fac2d9d88b7d57cce20129d57 (diff)
downloadruby-a774aa4e79933d6c96258c1660f1b8ee2a0cc349.tar.gz
* ext/iconv/iconv.c (warn_deprecated): show caller position.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29757 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/iconv/iconv.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index 2aab1e92f4..83a4b5e299 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -1179,12 +1179,36 @@ iconv_failure_inspect(VALUE self)
* * returns an error without setting errno properly
*/
+static void
+warn_deprecated(void)
+{
+ static const char message[] =
+ ": iconv will be deprecated in the future, use String#encode instead.\n";
+ VALUE msg = Qnil, caller = rb_make_backtrace();
+ long i;
+
+ for (i = 1; i < RARRAY_LEN(caller); ++i) {
+ VALUE s = RARRAY_PTR(caller)[i];
+ if (strncmp(RSTRING_PTR(s), "<internal:", 10) != 0) {
+ msg = s;
+ break;
+ }
+ }
+ if (NIL_P(msg)) {
+ msg = rb_str_new_cstr(message + 2);
+ }
+ else {
+ rb_str_cat(msg, message, sizeof(message) - 1);
+ }
+ rb_io_puts(1, &msg, rb_stderr);
+}
+
void
Init_iconv(void)
{
VALUE rb_cIconv = rb_define_class("Iconv", rb_cData);
- rb_warn("iconv will be deprecated in the future, use String#encode instead.");
+ warn_deprecated();
rb_define_alloc_func(rb_cIconv, iconv_s_allocate);
rb_define_singleton_method(rb_cIconv, "open", iconv_s_open, -1);
rb_define_singleton_method(rb_cIconv, "iconv", iconv_s_iconv, -1);