From ae75ec65dd87bfbe202ae5df3ecd42d45b576b9a Mon Sep 17 00:00:00 2001 From: Marcelo Matus Date: Tue, 9 Dec 2003 10:38:34 +0000 Subject: [PATCH] emitting and testing protected methods for director protected members git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5512 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- .../test-suite/ruby/director_nested_runme.rb | 39 ++++++++++++------- .../ruby/director_protected_runme.rb | 14 +++++-- Source/Modules/ruby.cxx | 16 +++++--- 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/Examples/test-suite/ruby/director_nested_runme.rb b/Examples/test-suite/ruby/director_nested_runme.rb index 1a2bba6d1..923f72b5d 100644 --- a/Examples/test-suite/ruby/director_nested_runme.rb +++ b/Examples/test-suite/ruby/director_nested_runme.rb @@ -1,32 +1,41 @@ require 'director_nested' +NoProtectedError = Kernel.const_defined?("NoMethodError") ? NoMethodError : NameError + class A < Director_nested::FooBar_int - def do_step - "A::do_step;" - end + protected + def do_step + "A::do_step;" + end - def get_value - "A::get_value" - end + def get_value + "A::get_value" + end end a = A.new +begin + a.do_advance +rescue NoProtectedError +end + raise RuntimeError if a.step != "Bar::step;Foo::advance;Bar::do_advance;A::do_step;" class B < Director_nested::FooBar_int - def do_advance - "B::do_advance;" + do_step - end + protected + def do_advance + "B::do_advance;" + do_step + end - def do_step - "B::do_step;" - end + def do_step + "B::do_step;" + end - def get_value - "B::get_value" - end + def get_value + "B::get_value" + end end diff --git a/Examples/test-suite/ruby/director_protected_runme.rb b/Examples/test-suite/ruby/director_protected_runme.rb index 535e9aef9..147d3ceb2 100644 --- a/Examples/test-suite/ruby/director_protected_runme.rb +++ b/Examples/test-suite/ruby/director_protected_runme.rb @@ -1,13 +1,21 @@ require 'director_protected' +NoProtectedError = Kernel.const_defined?("NoMethodError") ? NoMethodError : NameError + class FooBar < Director_protected::Bar - def ping - "FooBar::ping();" - end + protected + def ping + "FooBar::ping();" + end end b = Director_protected::Bar.new fb = FooBar.new +begin + fb.ping +rescue NoProtectedError +end + raise RuntimeError if b.pong != "Bar::pong();Foo::pong();Bar::ping();" raise RuntimeError if fb.pong != "Bar::pong();Foo::pong();FooBar::ping();" diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index 46fd26000..dbb94c7e3 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -588,13 +588,17 @@ public: String *temp = NewString(""); switch (current) { - case MEMBER_FUNC: - if (multipleInheritance) { - Printv(klass->init, tab4, "rb_define_method(", klass->mImpl, ", \"", - iname, "\", ", wname, ", -1);\n", NIL); + case MEMBER_FUNC: + if (multipleInheritance) { + const char* rb_define_method = !is_protected(n) ? + "rb_define_method" : "rb_define_protected_method"; + Printv(klass->init, tab4, rb_define_method,"(", klass->mImpl, ", \"", + iname, "\", ", wname, ", -1);\n", NIL); } else { - Printv(klass->init, tab4, "rb_define_method(", klass->vname, ", \"", - iname, "\", ", wname, ", -1);\n", NIL); + const char* rb_define_method = !is_protected(n) ? + "rb_define_method" : "rb_define_protected_method"; + Printv(klass->init, tab4, rb_define_method, "(", klass->vname, ", \"", + iname, "\", ", wname, ", -1);\n", NIL); } break; case CONSTRUCTOR_ALLOCATE: