[#38323] [1.8.7][1.9.1][tk] 自前実装の拡張 widget を使いたい場合 — oshida@...

押田です。

22 messages 2009/04/24
[#38331] Re: [1.8.7][1.9.1][tk] 自前実装の拡張 widget を使いたい場合 — Hidetoshi NAGAI <nagai@...> 2009/04/26

永井@知能.九工大です.

[#38339] Re: [1.8.7][1.9.1][tk] 自前実装の拡張 widget を使いたい場合 — oshida@... 2009/04/27

押田です。

[#38340] Re: [1.8.7][1.9.1][tk] 自前実装の拡張 widget を使いたい場合 — Hidetoshi NAGAI <nagai@...> 2009/04/27

永井@知能.九工大です.

[#38697] Re: [1.8.7][1.9.1][tk] 自前実装の拡張 widget を使いたい場合 — Hidetoshi NAGAI <nagai@...> 2009/06/21

永井@知能.九工大です.

[#38711] Re: [1.8.7][1.9.1][tk] 自前実装の拡張 widget を使いたい場合 — oshida@... 2009/06/24

押田です。

[#38723] Re: [1.8.7][1.9.1][tk] 自前実装の拡張 widget を使いたい場合 — Hidetoshi NAGAI <nagai@...> 2009/07/01

永井@知能.九工大です.

[#38743] Re: [1.8.7][1.9.1][tk] 自前実装の拡張 widget を使いたい場合 — oshida@... 2009/07/07

押田です。

[#38747] Re: [1.8.7][1.9.1][tk] 自前実装の拡張 widget を使いたい場合 — Hidetoshi NAGAI <nagai@...> 2009/07/08

永井@知能.九工大です.

[#38748] Re: [1.8.7][1.9.1][tk] 自前実装の拡張 widget を使いたい場合 — oshida@... 2009/07/08

押田です。

[#38749] Re: [1.8.7][1.9.1][tk] 自前実装の拡張 widget を使いたい場合 — Hidetoshi NAGAI <nagai@...> 2009/07/08

永井@知能.九工大です.

[ruby-dev:38297] Re: rinda/eval.rb

From: Tanaka Akira <akr@...>
Date: 2009-04-09 03:36:22 UTC
List: ruby-dev #38297
In article <E1LpT4v-0000Vr-E7@x61.netlab.jp>,
  Yukihiro Matsumoto <matz@ruby-lang.org> writes:

> いろいろ考えましたが、これ、入れてもよいような気がして来まし
> た。が、タイミングが。1.9.2に入れてよいもんだか。どうするかと
> かの判断はYuguiさんに任せちゃうにしても、なんか、こうやって

とりあえず、respond_to? の挙動を 1.9 に入れることについては
だれも反対してないので、まずそこから始めるというのがいいんじゃ
ないですかね。

Ruby レベルのメソッドがないとテストがちょっと面倒ですが。

どうでしょうか yugui さん?

% svn diff --diff-cmd diff -x '-u -p'
Index: include/ruby/intern.h
===================================================================
--- include/ruby/intern.h	(revision 23162)
+++ include/ruby/intern.h	(working copy)
@@ -275,6 +275,8 @@ int rb_method_basic_definition_p(VALUE, 
 VALUE rb_eval_cmd(VALUE, VALUE, int);
 int rb_obj_respond_to(VALUE, ID, int);
 int rb_respond_to(VALUE, ID);
+void rb_define_notimplement_method_id(VALUE mod, ID id, int noex);
+VALUE rb_f_notimplement(int argc, VALUE *argv, VALUE obj);
 void rb_interrupt(void);
 VALUE rb_apply(VALUE, ID, VALUE);
 void rb_backtrace(void);
Index: proc.c
===================================================================
--- proc.c	(revision 23162)
+++ proc.c	(working copy)
@@ -1616,6 +1616,9 @@ method_inspect(VALUE method)
     }
     rb_str_buf_cat2(str, sharp);
     rb_str_append(str, rb_id2str(data->oid));
+    if (rb_notimplement_body_p(data->body)) {
+        rb_str_buf_cat2(str, " (not-implemented)");
+    }
     rb_str_buf_cat2(str, ">");
 
     return str;
Index: vm_method.c
===================================================================
--- vm_method.c	(revision 23162)
+++ vm_method.c	(working copy)
@@ -24,6 +24,8 @@ static struct cache_entry cache[CACHE_SI
 #define ruby_running (GET_VM()->running)
 /* int ruby_running = 0; */
 
+static NODE *notimplement_body = 0;
+
 void
 rb_clear_cache(void)
 {
@@ -414,6 +416,12 @@ rb_export_method(VALUE klass, ID name, I
 }
 
 int
+rb_notimplement_body_p(NODE *method)
+{
+    return method == notimplement_body ? Qtrue : Qfalse;
+}
+
+int
 rb_method_boundp(VALUE klass, ID id, int ex)
 {
     NODE *method;
@@ -422,6 +430,8 @@ rb_method_boundp(VALUE klass, ID id, int
 	if (ex && (method->nd_noex & NOEX_PRIVATE)) {
 	    return Qfalse;
 	}
+        if (rb_notimplement_body_p(method->nd_body))
+           return Qfalse;
 	return Qtrue;
     }
     return Qfalse;
@@ -811,6 +821,18 @@ rb_mod_alias_method(VALUE mod, VALUE new
     return mod;
 }
 
+VALUE
+rb_f_notimplement(int argc, VALUE *argv, VALUE obj)
+{
+    rb_notimplement();
+}
+
+void
+rb_define_notimplement_method_id(VALUE mod, ID id, int noex)
+{
+    rb_add_method(mod, id, notimplement_body, noex);
+}
+
 static void
 secure_visibility(VALUE self)
 {
@@ -1137,5 +1159,8 @@ Init_eval_method(void)
     singleton_removed = rb_intern("singleton_method_removed");
     undefined = rb_intern("method_undefined");
     singleton_undefined = rb_intern("singleton_method_undefined");
+
+    rb_global_variable(&notimplement_body);
+    notimplement_body = NEW_CFUNC(rb_f_notimplement, -1);
 }
 
Index: class.c
===================================================================
--- class.c	(revision 23162)
+++ class.c	(working copy)
@@ -807,25 +807,36 @@ rb_obj_singleton_methods(int argc, VALUE
 void
 rb_define_method_id(VALUE klass, ID name, VALUE (*func)(ANYARGS), int argc)
 {
-    rb_add_method(klass, name, NEW_CFUNC(func,argc), NOEX_PUBLIC);
+    if (func == rb_f_notimplement)
+        rb_define_notimplement_method_id(klass, name, NOEX_PUBLIC);
+    else
+        rb_add_method(klass, name, NEW_CFUNC(func,argc), NOEX_PUBLIC);
 }
 
 void
 rb_define_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
 {
-    rb_add_method(klass, rb_intern(name), NEW_CFUNC(func, argc), NOEX_PUBLIC);
+    rb_define_method_id(klass, rb_intern(name), func, argc);
 }
 
 void
 rb_define_protected_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
 {
-    rb_add_method(klass, rb_intern(name), NEW_CFUNC(func, argc), NOEX_PROTECTED);
+    ID id = rb_intern(name);
+    if (func == rb_f_notimplement)
+        rb_define_notimplement_method_id(klass, id, NOEX_PROTECTED);
+    else
+        rb_add_method(klass, id, NEW_CFUNC(func, argc), NOEX_PROTECTED);
 }
 
 void
 rb_define_private_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
 {
-    rb_add_method(klass, rb_intern(name), NEW_CFUNC(func, argc), NOEX_PRIVATE);
+    ID id = rb_intern(name);
+    if (func == rb_f_notimplement)
+        rb_define_notimplement_method_id(klass, id, NOEX_PRIVATE);
+    else
+        rb_add_method(klass, id, NEW_CFUNC(func, argc), NOEX_PRIVATE);
 }
 
 void
Index: process.c
===================================================================
--- process.c	(revision 23162)
+++ process.c	(working copy)
@@ -2601,10 +2601,10 @@ rb_fork(int *status, int (*chfunc)(void*
  *  fork doesn't copy other threads.
  */
 
+#if defined(HAVE_FORK) && !defined(CANNOT_FORK_WITH_PTHREAD)
 static VALUE
 rb_f_fork(VALUE obj)
 {
-#if defined(HAVE_FORK) && !defined(CANNOT_FORK_WITH_PTHREAD)
     rb_pid_t pid;
 
     rb_secure(2);
@@ -2630,11 +2630,10 @@ rb_f_fork(VALUE obj)
       default:
 	return PIDT2NUM(pid);
     }
+}
 #else
-    rb_notimplement();
+#define rb_f_fork rb_f_notimplement
 #endif
-}
-
 
 /*
  *  call-seq:
Index: test/ruby/test_notimp.rb
===================================================================
--- test/ruby/test_notimp.rb	(revision 0)
+++ test/ruby/test_notimp.rb	(revision 0)
@@ -0,0 +1,64 @@
+require 'test/unit'
+require 'tmpdir'
+
+class TestNotImplement < Test::Unit::TestCase
+  def test_respond_to_fork
+    assert_includes(Process.methods, :fork)
+    if /linux/ =~ RUBY_PLATFORM
+      assert_equal(true, Process.respond_to?(:fork))
+    end
+  end
+
+  def test_respond_to_lchmod
+    assert_includes(File.methods, :lchmod)
+    if /linux/ =~ RUBY_PLATFORM
+      assert_equal(false, File.respond_to?(:lchmod))
+    end
+    if /freebsd/ =~ RUBY_PLATFORM
+      assert_equal(true, File.respond_to?(:lchmod))
+    end
+  end
+
+  def test_call_fork
+    if Process.respond_to?(:fork)
+      assert_nothing_raised {
+        pid = fork {}
+        Process.wait pid
+      }
+    end
+  end
+
+  def test_call_lchmod
+    if File.respond_to?(:lchmod)
+      Dir.mktmpdir {|d|
+        f = "#{d}/f"
+        g = "#{d}/g"
+        File.open(f, "w") {}
+        File.symlink f, g
+        newmode = 0444
+        File.lchmod newmode, "#{d}/g"
+        snew = File.lstat(g)
+        assert_equal(newmode, snew.mode & 0777)
+      }
+    end
+  end
+
+  def test_method_inspect_fork
+    m = Process.method(:fork)
+    if Process.respond_to?(:fork)
+      assert_not_match(/not-implemented/, m.inspect)
+    else
+      assert_match(/not-implemented/, m.inspect)
+    end
+  end
+
+  def test_method_inspect_lchmod
+    m = File.method(:lchmod)
+    if File.respond_to?(:lchmod)
+      assert_not_match(/not-implemented/, m.inspect)
+    else
+      assert_match(/not-implemented/, m.inspect)
+    end
+  end
+
+end
Index: file.c
===================================================================
--- file.c	(revision 23162)
+++ file.c	(working copy)
@@ -1926,12 +1926,7 @@ rb_file_s_lchmod(int argc, VALUE *argv)
     return LONG2FIX(n);
 }
 #else
-static VALUE
-rb_file_s_lchmod(int argc, VALUE *argv)
-{
-    rb_notimplement();
-    return Qnil;		/* not reached */
-}
+#define rb_file_s_lchmod rb_f_notimplement
 #endif
 
 struct chown_args {
-- 
[田中 哲][たなか あきら][Tanaka Akira]

In This Thread