Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

define_method && define_constructor does not inherit access specifier. #57

Closed
chaizhenhua opened this issue Aug 23, 2013 · 3 comments · Fixed by #58
Closed

define_method && define_constructor does not inherit access specifier. #57

chaizhenhua opened this issue Aug 23, 2013 · 3 comments · Fixed by #58

Comments

@chaizhenhua
Copy link
Contributor

Hello,
I am wraping a C++ libray with rice. I found that the when use define_constructor or define_method, the method access specifier is changed to public.

The C++ code shoud consistent with the ruby code. but the access specifier are changed from private to public.

     // in C++
     ....
     Init_TestC {
     define_class<TestC>("TestC")
    .define_constructor(Constructor<TestC>());
    }
     # in ruby TestC is class defined in C++ above, 
     # the initialize function is public. which should be private
     require 'TestC'
     TestC.new.public_methods.include?(:initialize)
     => true 
# in ruby define a class, the initialize method is private
class TestRb
  def initialize
  end
end

# TestRb is defined in ruby, the initialize function is private
TestRb.new.public_methods.include?(:initialize)
 => false
@jasonroelofs
Copy link
Collaborator

I'm not sure I follow what you're asking here. If a constructor or method in C++ is anything but public, trying to wrap those methods in Rice shouldn't compile. If you want a method wrapped in C++ to appear in Ruby as private, you may need to fall back to MRI's API to make that change, as I don't believe that is available through the Rice API.

Does that answer your question?

@chaizhenhua
Copy link
Contributor Author

Hi, thanks for your reply. I mean if in ruby define an initialize method. the method is private. but if we use define_constructor in Rice the method is public. and if we use rb_define_method("initialize ") the method is also private. so I am wondering why rice violate the convention? I do not want to define a private method through the Rice API. I just want to keep the access specifier from base class (Object). I do not want to make initialize public. can this be done by using rice?

TestRb.new.public_methods.include?(:initialize)
 => false # TestRb is defined in ruby. 
TestC.new.public_methods.include?(:initialize)
 => true # TestC is wrapped by rice, this should return false. the previous code was wrong, sorry.

@jasonroelofs
Copy link
Collaborator

Ah, that makes sense then, I'll take a look, thanks!

chaizhenhua added a commit to chaizhenhua/rice that referenced this issue Aug 24, 2013
chaizhenhua added a commit to chaizhenhua/rice that referenced this issue Sep 12, 2013
jasonroelofs added a commit that referenced this issue Jan 30, 2014
Modified method data handling and fix #57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants