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

ruby-changes:2793

From: ko1@a...
Date: 18 Dec 2007 08:07:11 +0900
Subject: [ruby-changes:2793] matz - Ruby:r14284 (trunk): * proc.c (rb_obj_public_method): Object#public_method to retrieve

matz	2007-12-18 08:01:50 +0900 (Tue, 18 Dec 2007)

  New Revision: 14284

  Modified files:
    trunk/ChangeLog
    trunk/eval_error.ci
    trunk/eval_intern.h
    trunk/eval_method.ci
    trunk/proc.c

  Log:
    * proc.c (rb_obj_public_method): Object#public_method to retrieve
      public method object.
    
    * proc.c (rb_mod_public_instance_method): Module#public_instance_method 
      to retrieve public instance method from class / module.
    
    * proc.c (mnew): visibility check added.
    
    * eval_error.ci (rb_print_undef): add rb_ prefix.
    
    * eval_error.ci (rb_print_undef): add visibility in the error
      message.

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/eval_error.ci?r1=14284&r2=14283
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14284&r2=14283
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/eval_method.ci?r1=14284&r2=14283
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/proc.c?r1=14284&r2=14283
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/eval_intern.h?r1=14284&r2=14283

Index: eval_intern.h
===================================================================
--- eval_intern.h	(revision 14283)
+++ eval_intern.h	(revision 14284)
@@ -204,7 +204,7 @@
 NORETURN(void rb_fiber_start(void));
 
 NORETURN(void rb_raise_jump _((VALUE)));
-NORETURN(void print_undef _((VALUE, ID)));
+NORETURN(void rb_print_undef _((VALUE, ID, int)));
 NORETURN(void vm_localjump_error(const char *, VALUE, int));
 NORETURN(void vm_jump_tag_but_local_jump(int, VALUE));
 
Index: eval_method.ci
===================================================================
--- eval_method.ci	(revision 14283)
+++ eval_method.ci	(revision 14284)
@@ -385,7 +385,7 @@
 	fbody = search_method(rb_cObject, name, &origin);
     }
     if (!fbody || !fbody->nd_body) {
-	print_undef(klass, name);
+	rb_print_undef(klass, name, 0);
     }
     if (fbody->nd_body->nd_noex != noex) {
 	if (klass == origin) {
@@ -573,7 +573,7 @@
 	}
     }
     if (!orig_fbody || !orig_fbody->nd_body) {
-	print_undef(klass, def);
+	rb_print_undef(klass, def, 0);
     }
     if (FL_TEST(klass, FL_SINGLETON)) {
 	singleton = rb_iv_get(klass, "__attached__");
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 14283)
+++ ChangeLog	(revision 14284)
@@ -1,3 +1,18 @@
+Tue Dec 18 07:56:57 2007  Yukihiro Matsumoto  <matz@r...>
+
+	* proc.c (rb_obj_public_method): Object#public_method to retrieve
+	  public method object.
+
+	* proc.c (rb_mod_public_instance_method): Module#public_instance_method 
+	  to retrieve public instance method from class / module.
+	
+	* proc.c (mnew): visibility check added.
+
+	* eval_error.ci (rb_print_undef): add rb_ prefix.
+
+	* eval_error.ci (rb_print_undef): add visibility in the error
+	  message. 
+
 Tue Dec 18 05:54:26 2007  Yukihiro Matsumoto  <matz@r...>
 
 	* lib/Env.rb, lib/base64.rb, lib/importenv.rb, lib/eregex.rb: removed.
Index: proc.c
===================================================================
--- proc.c	(revision 14283)
+++ proc.c	(revision 14284)
@@ -638,7 +638,7 @@
 NODE *rb_get_method_body(VALUE klass, ID id, ID *idp);
 
 static VALUE
-mnew(VALUE klass, VALUE obj, ID id, VALUE mclass)
+mnew(VALUE klass, VALUE obj, ID id, VALUE mclass, int scope)
 {
     VALUE method;
     NODE *body;
@@ -648,8 +648,11 @@
 
   again:
     if ((body = rb_get_method_body(klass, id, 0)) == 0) {
-	print_undef(rclass, oid);
+	rb_print_undef(rclass, oid, 0);
     }
+    if (scope && (body->nd_noex & NOEX_MASK) != NOEX_PUBLIC) {
+	rb_print_undef(rclass, oid, (body->nd_noex & NOEX_MASK));
+    }
 
     klass = body->nd_clss;
     body = body->nd_body;
@@ -864,9 +867,15 @@
 VALUE
 rb_obj_method(VALUE obj, VALUE vid)
 {
-    return mnew(CLASS_OF(obj), obj, rb_to_id(vid), rb_cMethod);
+    return mnew(CLASS_OF(obj), obj, rb_to_id(vid), rb_cMethod, Qfalse);
 }
 
+VALUE
+rb_obj_public_method(VALUE obj, VALUE vid)
+{
+    return mnew(CLASS_OF(obj), obj, rb_to_id(vid), rb_cMethod, Qtrue);
+}
+
 /*
  *  call-seq:
  *     mod.instance_method(symbol)   => unbound_method
@@ -900,11 +909,17 @@
  */
 
 static VALUE
-rb_mod_method(VALUE mod, VALUE vid)
+rb_mod_instance_method(VALUE mod, VALUE vid)
 {
-    return mnew(mod, Qundef, rb_to_id(vid), rb_cUnboundMethod);
+    return mnew(mod, Qundef, rb_to_id(vid), rb_cUnboundMethod, Qfalse);
 }
 
+static VALUE
+rb_mod_public_instance_method(VALUE mod, VALUE vid)
+{
+    return mnew(mod, Qundef, rb_to_id(vid), rb_cUnboundMethod, Qtrue);
+}
+
 /*
  *  call-seq:
  *     define_method(symbol, method)     => new_method
@@ -1518,6 +1533,7 @@
     rb_define_method(rb_cMethod, "owner", method_owner, 0);
     rb_define_method(rb_cMethod, "unbind", method_unbind, 0);
     rb_define_method(rb_mKernel, "method", rb_obj_method, 1);
+    rb_define_method(rb_mKernel, "public_method", rb_obj_public_method, 1);
 
     /* UnboundMethod */
     rb_cUnboundMethod = rb_define_class("UnboundMethod", rb_cObject);
@@ -1535,7 +1551,8 @@
     rb_define_method(rb_cUnboundMethod, "bind", umethod_bind, 1);
 
     /* Module#*_method */
-    rb_define_method(rb_cModule, "instance_method", rb_mod_method, 1);
+    rb_define_method(rb_cModule, "instance_method", rb_mod_instance_method, 1);
+    rb_define_method(rb_cModule, "public_instance_method", rb_mod_public_instance_method, 1);
     rb_define_private_method(rb_cModule, "define_method", rb_mod_define_method, -1);
 
     /* Kernel */
Index: eval_error.ci
===================================================================
--- eval_error.ci	(revision 14283)
+++ eval_error.ci	(revision 14284)
@@ -207,9 +207,17 @@
 }
 
 void
-print_undef(VALUE klass, ID id)
+rb_print_undef(VALUE klass, ID id, int scope)
 {
-    rb_name_error(id, "undefined method `%s' for %s `%s'",
+    char *v;
+
+    switch (scope) {
+      default:
+      case NOEX_PUBLIC: v = ""; break;
+      case NOEX_PRIVATE: v = " private"; break;
+      case NOEX_PROTECTED: v = " protected"; break;
+    }
+    rb_name_error(id, "undefined%s method `%s' for %s `%s'", v,
 		  rb_id2name(id),
 		  (TYPE(klass) == T_MODULE) ? "module" : "class",
 		  rb_class2name(klass));

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

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