-
Notifications
You must be signed in to change notification settings - Fork 185
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
Raising a RuntimeError when calling Kernel#binding from a C/non-ruby frame. #3449
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
fails:CApiBindingSpecs Kernel#binding gives the top-most Ruby binding when called from C | ||
fails:CApiBindingSpecs Kernel#binding raises when called from C |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,13 +17,15 @@ | |
import java.util.Objects; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import com.oracle.truffle.api.Truffle; | ||
import com.oracle.truffle.api.dsl.Bind; | ||
import com.oracle.truffle.api.dsl.Cached.Shared; | ||
import com.oracle.truffle.api.dsl.Fallback; | ||
import com.oracle.truffle.api.dsl.GenerateCached; | ||
import com.oracle.truffle.api.dsl.GenerateInline; | ||
import com.oracle.truffle.api.dsl.NeverDefault; | ||
import com.oracle.truffle.api.frame.Frame; | ||
import com.oracle.truffle.api.frame.FrameInstance; | ||
import com.oracle.truffle.api.interop.InteropLibrary; | ||
import com.oracle.truffle.api.interop.UnsupportedMessageException; | ||
import com.oracle.truffle.api.object.PropertyGetter; | ||
|
@@ -92,6 +94,7 @@ | |
import org.truffleruby.interop.ToJavaStringNode; | ||
import org.truffleruby.core.string.ImmutableRubyString; | ||
import org.truffleruby.interop.TranslateInteropExceptionNode; | ||
import org.truffleruby.language.CallStackManager; | ||
import org.truffleruby.language.ImmutableRubyObject; | ||
import org.truffleruby.language.LexicalScope; | ||
import org.truffleruby.language.Nil; | ||
|
@@ -334,6 +337,18 @@ RubyBinding binding(Frame callerFrame, Object self, Object[] rubyArgs, RootCallT | |
@Cached( | ||
value = "getAdoptedNode(this).getEncapsulatingSourceSection()", | ||
allowUncached = true, neverDefault = false) SourceSection sourceSection) { | ||
|
||
final MaterializedFrame materializedCallerFrame = Truffle.getRuntime() | ||
.iterateFrames(f -> f.getFrame(FrameInstance.FrameAccess.MATERIALIZE).materialize(), 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We definitely can't do One way to detect C extension methods quickly is #3436 (comment). The aim of this new exception is to not give an empty/unconnected binding for situations where there isn't a real binding. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feel free to try #3436 (comment) in this PR. |
||
|
||
if (!CallStackManager.isRubyFrame(materializedCallerFrame)) { | ||
throw new RaiseException( | ||
getContext(), | ||
coreExceptions().runtimeError( | ||
"Cannot create Binding object for non-Ruby caller", | ||
this)); | ||
} | ||
|
||
needCallerFrame(callerFrame, target); | ||
return BindingNodes.createBinding(getContext(), getLanguage(), callerFrame.materialize(), sourceSection); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what the materializedCallerFrame looks like in the debugger:
Compared to when called from Ruby: