[前][次][番号順一覧][スレッド一覧]

ruby-changes:17746

From: nobu <ko1@a...>
Date: Thu, 11 Nov 2010 23:04:54 +0900 (JST)
Subject: [ruby-changes:17746] Ruby:r29757 (trunk): * ext/iconv/iconv.c (warn_deprecated): show caller position.

nobu	2010-11-11 23:04:48 +0900 (Thu, 11 Nov 2010)

  New Revision: 29757

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29757

  Log:
    * ext/iconv/iconv.c (warn_deprecated): show caller position.

  Modified files:
    trunk/ChangeLog
    trunk/ext/iconv/iconv.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 29756)
+++ ChangeLog	(revision 29757)
@@ -1,3 +1,7 @@
+Thu Nov 11 23:04:44 2010  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/iconv/iconv.c (warn_deprecated): show caller position.
+
 Thu Nov 11 23:03:12 2010  Nobuyoshi Nakada  <nobu@r...>
 
 	* io.c (argf_close): untie tied io before closing.
Index: ext/iconv/iconv.c
===================================================================
--- ext/iconv/iconv.c	(revision 29756)
+++ ext/iconv/iconv.c	(revision 29757)
@@ -1179,12 +1179,36 @@
  * * 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);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]