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

Implement rb_frame_method_id_and_class internal API. #3363

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mtortonesi
Copy link
Contributor

This commit implements the rb_frame_method_and_id internal API, that is needed by the rice gem. The corresponding changeset represents a first but hopefully significant step to get the torch.rb gem working on Truffleruby.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Dec 27, 2023
@mtortonesi mtortonesi changed the title Implement rb_frame_method_and_id internal API. Implement rb_frame_method_id_and_class internal API. Dec 27, 2023
@mtortonesi mtortonesi closed this Dec 30, 2023
This commit implements rb_frame_method_and_id internal API, that is
needed by the rice gem. The corresponding changeset represents a first
but hopefully significant step to get torch.rb working on Truffleruby.
@mtortonesi mtortonesi reopened this Dec 30, 2023
boolean frameMethodAndId(Object frameMethod, Object frameId) {
final Frame callingMethodFrame = findCallingMethodFrame();
frameMethod = RubyArguments.getMethod(callingMethodFrame);
frameId = System.identityHashCode(RubyArguments.tryGetSelf(callingMethodFrame));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These assignments have no effect, they only assign the local Java variable, not the C pointer.
You need to return something which contains both (e.g. a Method Ruby object or a Ruby Array of two elements).


int rb_frame_method_id_and_class(ID *idp, VALUE *klassp) {
return RUBY_CEXT_INVOKE("rb_frame_method_id_and_class", idp, klassp);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would need specs for this, under spec/ruby/optional/capi.
rb_frame_method_id_and_class is actually not a private function but it seems public C API, it's declared and documented in https://github.com/ruby/ruby/blob/fc48a679062e422b475ccea11574bf5b4368b732/include/ruby/internal/intern/vm.h#L62

}

@TruffleBoundary
private static Frame findCallingMethodFrame() {
Copy link
Member

@eregon eregon Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think org.truffleruby.language.CallStackManager#getCallingMethod should work instead of this and be a lot cleaner. And if not probably a variant of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants