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

ruby-changes:72896

From: Jeremy <ko1@a...>
Date: Thu, 11 Aug 2022 05:03:02 +0900 (JST)
Subject: [ruby-changes:72896] ff42e2359b (master): Revert "Add {Method, UnboundMethod}#{public?, private?, protected?}"

https://git.ruby-lang.org/ruby.git/commit/?id=ff42e2359b

From ff42e2359bdbf37e1721a82b4cfd95b31f494f3f Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Fri, 3 Jun 2022 18:15:56 -0700
Subject: Revert "Add {Method,UnboundMethod}#{public?,private?,protected?}"

This reverts commit 27278150685e738f84105d09843d3ba371146c7a and
58dc8bf8f15df9a33d191074e8a5d4946a3d59d5.

Visibility is an attribute of the method entry in a class, not an
attribute of the Method object.

Fixes [#18729]
Fixes [#18751]
Fixes [#18435]
---
 proc.c                   | 60 +-----------------------------------------------
 test/ruby/test_method.rb | 53 ++----------------------------------------
 2 files changed, 3 insertions(+), 110 deletions(-)

diff --git a/proc.c b/proc.c
index a525562230..c234ed3f93 100644
--- a/proc.c
+++ b/proc.c
@@ -40,7 +40,6 @@ struct METHOD { https://github.com/ruby/ruby/blob/trunk/proc.c#L40
     const VALUE iclass;
     const rb_method_entry_t * const me;
     /* for bound methods, `me' should be rb_callable_method_entry_t * */
-    rb_method_visibility_t visibility;
 };
 
 VALUE rb_cUnboundMethod;
@@ -1664,7 +1663,6 @@ mnew_missing(VALUE klass, VALUE obj, ID id, VALUE mclass) https://github.com/ruby/ruby/blob/trunk/proc.c#L1663
     me = rb_method_entry_create(id, klass, METHOD_VISI_UNDEF, def);
 
     RB_OBJ_WRITE(method, &data->me, me);
-    data->visibility = METHOD_ENTRY_VISI(me);
 
     return method;
 }
@@ -1722,7 +1720,6 @@ mnew_internal(const rb_method_entry_t *me, VALUE klass, VALUE iclass, https://github.com/ruby/ruby/blob/trunk/proc.c#L1720
     RB_OBJ_WRITE(method, &data->klass, klass);
     RB_OBJ_WRITE(method, &data->iclass, iclass);
     RB_OBJ_WRITE(method, &data->me, me);
-    data->visibility = visi;
 
     return method;
 }
@@ -1820,7 +1817,6 @@ method_eq(VALUE method, VALUE other) https://github.com/ruby/ruby/blob/trunk/proc.c#L1817
 
     if (!rb_method_entry_eq(m1->me, m2->me) ||
         klass1 != klass2 ||
-        m1->visibility != m2->visibility ||
         m1->klass != m2->klass ||
         m1->recv != m2->recv) {
         return Qfalse;
@@ -1874,7 +1870,6 @@ method_unbind(VALUE obj) https://github.com/ruby/ruby/blob/trunk/proc.c#L1870
     RB_OBJ_WRITE(method, &data->klass, orig->klass);
     RB_OBJ_WRITE(method, &data->iclass, orig->iclass);
     RB_OBJ_WRITE(method, &data->me, rb_method_entry_clone(orig->me));
-    data->visibility = orig->visibility;
 
     return method;
 }
@@ -2390,7 +2385,6 @@ method_clone(VALUE self) https://github.com/ruby/ruby/blob/trunk/proc.c#L2385
     RB_OBJ_WRITE(clone, &data->klass, orig->klass);
     RB_OBJ_WRITE(clone, &data->iclass, orig->iclass);
     RB_OBJ_WRITE(clone, &data->me, rb_method_entry_clone(orig->me));
-    data->visibility = orig->visibility;
     return clone;
 }
 
@@ -2641,7 +2635,6 @@ umethod_bind(VALUE method, VALUE recv) https://github.com/ruby/ruby/blob/trunk/proc.c#L2635
     RB_OBJ_WRITE(method, &bound->klass, klass);
     RB_OBJ_WRITE(method, &bound->iclass, iclass);
     RB_OBJ_WRITE(method, &bound->me, me);
-    bound->visibility = data->visibility;
 
     return method;
 }
@@ -2677,7 +2670,7 @@ umethod_bind_call(int argc, VALUE *argv, VALUE method) https://github.com/ruby/ruby/blob/trunk/proc.c#L2670
         VALUE methclass, klass, iclass;
         const rb_method_entry_t *me;
         convert_umethod_to_method_components(data, recv, &methclass, &klass, &iclass, &me);
-        struct METHOD bound = { recv, klass, 0, me, METHOD_ENTRY_VISI(me) };
+        struct METHOD bound = { recv, klass, 0, me };
 
         return call_method_data(ec, &bound, argc, argv, passed_procval, RB_PASS_CALLED_KEYWORDS);
     }
@@ -3354,51 +3347,6 @@ method_super_method(VALUE method) https://github.com/ruby/ruby/blob/trunk/proc.c#L3347
     return mnew_internal(me, me->owner, iclass, data->recv, mid, rb_obj_class(method), FALSE, FALSE);
 }
 
-/*
- *  call-seq:
- *    meth.public? -> true or false
- *
- *  Returns whether the method is public.
- */
-
-static VALUE
-method_public_p(VALUE method)
-{
-    const struct METHOD *data;
-    TypedData_Get_Struct(method, struct METHOD, &method_data_type, data);
-    return RBOOL(data->visibility == METHOD_VISI_PUBLIC);
-}
-
-/*
- *  call-seq:
- *    meth.protected? -> true or false
- *
- *  Returns whether the method is protected.
- */
-
-static VALUE
-method_protected_p(VALUE method)
-{
-    const struct METHOD *data;
-    TypedData_Get_Struct(method, struct METHOD, &method_data_type, data);
-    return RBOOL(data->visibility == METHOD_VISI_PROTECTED);
-}
-
-/*
- *  call-seq:
- *    meth.private? -> true or false
- *
- *  Returns whether the method is private.
- */
-
-static VALUE
-method_private_p(VALUE method)
-{
-    const struct METHOD *data;
-    TypedData_Get_Struct(method, struct METHOD, &method_data_type, data);
-    return RBOOL(data->visibility == METHOD_VISI_PRIVATE);
-}
-
 /*
  * call-seq:
  *   local_jump_error.exit_value  -> obj
@@ -4339,9 +4287,6 @@ Init_Proc(void) https://github.com/ruby/ruby/blob/trunk/proc.c#L4287
     rb_define_method(rb_cMethod, "source_location", rb_method_location, 0);
     rb_define_method(rb_cMethod, "parameters", rb_method_parameters, 0);
     rb_define_method(rb_cMethod, "super_method", method_super_method, 0);
-    rb_define_method(rb_cMethod, "public?", method_public_p, 0);
-    rb_define_method(rb_cMethod, "protected?", method_protected_p, 0);
-    rb_define_method(rb_cMethod, "private?", method_private_p, 0);
     rb_define_method(rb_mKernel, "method", rb_obj_method, 1);
     rb_define_method(rb_mKernel, "public_method", rb_obj_public_method, 1);
     rb_define_method(rb_mKernel, "singleton_method", rb_obj_singleton_method, 1);
@@ -4365,9 +4310,6 @@ Init_Proc(void) https://github.com/ruby/ruby/blob/trunk/proc.c#L4310
     rb_define_method(rb_cUnboundMethod, "source_location", rb_method_location, 0);
     rb_define_method(rb_cUnboundMethod, "parameters", rb_method_parameters, 0);
     rb_define_method(rb_cUnboundMethod, "super_method", method_super_method, 0);
-    rb_define_method(rb_cUnboundMethod, "public?", method_public_p, 0);
-    rb_define_method(rb_cUnboundMethod, "protected?", method_protected_p, 0);
-    rb_define_method(rb_cUnboundMethod, "private?", method_private_p, 0);
 
     /* Module#*_method */
     rb_define_method(rb_cModule, "instance_method", rb_mod_instance_method, 1);
diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb
index 83e499913a..56e94493d9 100644
--- a/test/ruby/test_method.rb
+++ b/test/ruby/test_method.rb
@@ -199,11 +199,6 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_method.rb#L199
     assert_equal(o.method(:foo), o.method(:foo))
     assert_equal(o.method(:foo), o.method(:bar))
     assert_not_equal(o.method(:foo), o.method(:baz))
-
-    class << o
-      private :bar
-    end
-    assert_not_equal(o.method(:foo), o.method(:bar))
   end
 
   def test_hash
@@ -330,8 +325,8 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_method.rb#L325
     def PUBLIC_SINGLETON_TEST.def; end
   end
   def test_define_singleton_method_public
-    assert_equal(true, PUBLIC_SINGLETON_TEST.method(:dsm).public?)
-    assert_equal(true, PUBLIC_SINGLETON_TEST.method(:def).public?)
+    assert_nil(PUBLIC_SINGLETON_TEST.dsm)
+    assert_nil(PUBLIC_SINGLETON_TEST.def)
   end
 
   def test_define_singleton_method_no_proc
@@ -1197,50 +1192,6 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_method.rb#L1192
     assert_nil(super_method)
   end
 
-  def test_method_visibility_predicates
-    v = Visibility.new
-    assert_equal(true, v.method(:mv1).public?)
-    assert_equal(true, v.method(:mv2).private?)
-    assert_equal(true, v.method(:mv3).protected?)
-    assert_equal(false, v.method(:mv2).public?)
-    assert_equal(false, v.method(:mv3).private?)
-    assert_equal(false, v.method(:mv1).protected?)
-  end
-
-  def test_unbound_method_visibility_predicates
-    assert_equal(true, Visibility.instance_method(:mv1).public?)
-    assert_equal(true, Visibility.instance_method(:mv2).private?)
-    assert_equal(true, Visibility.instance_method(:mv3).protected?)
-    assert_equal(false, Visibility.instance_method(:mv2).public?)
-    assert_equal(false, Visibility.instance_method(:mv3).private?)
-    assert_equal(false, Visibility.instance_method(:mv1).protected?)
-  end
-
-  class VisibilitySub < Visibility
-    protected :mv1
-    public :mv2
-    private :mv3
-  end
-
-  def test_method_visibility_predicates_with_subclass_visbility_change
-    v = VisibilitySub.new
-    assert_equal(false, v.method(:mv1).public?)
-    assert_equal(false, v.method(:mv2).private?)
-    assert_equal(false, v.method(:mv3).protected?)
-    assert_equal(true, v.method(:mv2).public?)
-    assert_equal(true, v.method(:mv3).private?)
-    assert_equal(true, v.method(:mv1).protected?)
-  end
-
-  def test_unbound_method_visibility_predicates_with_subclass_visbility_change
-    assert_equal(false, VisibilitySub.instance_method(:mv1).public?)
-    assert_equal(false, VisibilitySub.instance_method(:mv2).private?)
-    assert_equal(false, VisibilitySub.instance_method(:mv3).protected?)
-    assert_equal(true, VisibilitySub.instance_method(:mv2).public?)
-    assert_equal(true, VisibilitySub.instance_method(:mv3).private?)
-    assert_equal(true, VisibilitySub.instance_method(:mv1).protected?)
-  end
-
   def rest_parameter(*rest)
     rest
   end
-- 
cgit v1.2.1


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

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