Skip to content

Commit 1de566b

Browse files
committed
[GR-14422] Misc interop fixes.
PullRequest: truffleruby/693
2 parents 4689685 + 76eebc7 commit 1de566b

File tree

4 files changed

+32
-22
lines changed

4 files changed

+32
-22
lines changed

spec/truffle/interop/boxed_spec.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# Copyright (c) 2016, 2017 Oracle and/or its affiliates. All rights reserved. This
22
# code is released under a tri EPL/GPL/LGPL license. You can use it,
33
# redistribute it and/or modify it under the terms of the:
4-
#
4+
#
55
# Eclipse Public License version 1.0, or
66
# GNU General Public License version 2, or
77
# GNU Lesser General Public License version 2.1.
88

99
require_relative '../../ruby/spec_helper'
1010

1111
describe "Truffle::Interop.boxed?" do
12-
12+
1313
it "returns true for strings" do
1414
Truffle::Interop.boxed?('test').should be_true
1515
end
16-
16+
1717
it "returns true for symbols" do
1818
Truffle::Interop.boxed?(:test).should be_true
1919
end
@@ -25,10 +25,11 @@
2525
it "returns true for objects that respond to #unbox" do
2626
unboxable = Object.new
2727
def unboxable.unbox
28+
1
2829
end
2930
Truffle::Interop.boxed?(unboxable).should be_true
3031
end
31-
32+
3233
it "returns false for other objects" do
3334
Truffle::Interop.boxed?(Object.new).should be_false
3435
end

spec/truffle/interop/remove_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,24 @@
5757
before :each do
5858
@object = TruffleInteropSpecs::InteropKeysClass.new
5959
end
60-
60+
6161
it "removes an instance variable that exists" do
6262
Truffle::Interop.remove(@object, :@a).should == true
6363
@object.instance_variable_defined?(:@a).should be_false
6464
end
65-
65+
6666
it "raises an error when the instance variable doesn't exist" do
6767
lambda {
6868
Truffle::Interop.remove(@object, :@foo)
6969
}.should raise_error(NameError)
7070
end
7171
end
72-
72+
7373
describe "with a name that doesn't start with @" do
7474
it "raises an unsupported message error" do
7575
lambda {
7676
Truffle::Interop.remove("abc", 1)
77-
}.should raise_error(RuntimeError, /Message not supported: REMOVE/)
77+
}.should raise_error(RuntimeError, /Message not supported/)
7878
end
7979
end
8080
end

src/main/c/cext/ruby.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ int rb_obj_method_arity(VALUE object, ID id) {
495495
}
496496

497497
int rb_obj_respond_to(VALUE object, ID id, int priv) {
498-
return polyglot_as_i32(polyglot_invoke(RUBY_CEXT, "rb_obj_respond_to", rb_tr_unwrap(object), rb_tr_unwrap(id), priv));
498+
return polyglot_as_boolean(polyglot_invoke(RUBY_CEXT, "rb_obj_respond_to", rb_tr_unwrap(object), rb_tr_unwrap(id), priv));
499499
}
500500

501501
int rb_special_const_p(VALUE object) {
@@ -2640,11 +2640,11 @@ VALUE rb_get_path(VALUE object) {
26402640
}
26412641

26422642
int rb_tr_readable(int mode) {
2643-
return polyglot_as_i32(polyglot_invoke(RUBY_CEXT, "rb_tr_readable", mode));
2643+
return polyglot_as_boolean(polyglot_invoke(RUBY_CEXT, "rb_tr_readable", mode));
26442644
}
26452645

26462646
int rb_tr_writable(int mode) {
2647-
return polyglot_as_i32(polyglot_invoke(RUBY_CEXT, "rb_tr_writable", mode));
2647+
return polyglot_as_boolean(polyglot_invoke(RUBY_CEXT, "rb_tr_writable", mode));
26482648
}
26492649

26502650
MUST_INLINE

src/main/java/org/truffleruby/interop/OutgoingForeignCallNode.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,7 @@
1010
package org.truffleruby.interop;
1111

1212
import java.util.Arrays;
13-
14-
import com.oracle.truffle.api.object.DynamicObject;
15-
16-
import org.truffleruby.language.RubyBaseNode;
17-
import org.truffleruby.language.control.JavaException;
18-
import org.truffleruby.language.control.RaiseException;
19-
import org.truffleruby.language.dispatch.CallDispatchHeadNode;
20-
import org.truffleruby.language.dispatch.DispatchNode;
21-
import org.truffleruby.language.methods.ExceptionTranslatingNode;
22-
import org.truffleruby.language.methods.UnsupportedOperationBehavior;
13+
import java.util.stream.Collectors;
2314

2415
import com.oracle.truffle.api.CompilerDirectives;
2516
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -33,7 +24,15 @@
3324
import com.oracle.truffle.api.interop.UnsupportedMessageException;
3425
import com.oracle.truffle.api.interop.UnsupportedTypeException;
3526
import com.oracle.truffle.api.nodes.Node;
27+
import com.oracle.truffle.api.object.DynamicObject;
3628
import com.oracle.truffle.api.profiles.BranchProfile;
29+
import org.truffleruby.language.RubyBaseNode;
30+
import org.truffleruby.language.control.JavaException;
31+
import org.truffleruby.language.control.RaiseException;
32+
import org.truffleruby.language.dispatch.CallDispatchHeadNode;
33+
import org.truffleruby.language.dispatch.DispatchNode;
34+
import org.truffleruby.language.methods.ExceptionTranslatingNode;
35+
import org.truffleruby.language.methods.UnsupportedOperationBehavior;
3736

3837
public abstract class OutgoingForeignCallNode extends RubyBaseNode {
3938

@@ -224,14 +223,24 @@ public Object executeCall(TruffleObject receiver, Object[] args) {
224223
node,
225224
receiver,
226225
rubyToForeignArgumentsNode.executeConvert(args));
227-
} catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e) {
226+
} catch (UnsupportedTypeException e) {
227+
exceptionProfile.enter();
228+
throw new RaiseException(getContext(), translate(e));
229+
} catch (ArityException | UnsupportedMessageException e) {
228230
exceptionProfile.enter();
229231
throw new JavaException(e);
230232
}
231233

232234
return foreignToRubyNode.executeConvert(foreign);
233235
}
234236

237+
@TruffleBoundary
238+
private DynamicObject translate(UnsupportedTypeException e) {
239+
return coreExceptions().typeError(
240+
"Wrong arguments: " + Arrays.stream(e.getSuppliedValues()).map(Object::toString).collect(Collectors.joining(", ")),
241+
this);
242+
}
243+
235244
}
236245

237246
protected class SendOutgoingNode extends OutgoingNode {

0 commit comments

Comments
 (0)