Skip to content

Commit 90ee82f

Browse files
committed
Use RARRAY_PTR() in util_spec_rb_scan_args()
* That way this does not force `argv` to be native and on the stack. * Also more representative of how (VALUE *argv) is set for `rb_define_method(..., -1)` functions, at least on TruffleRuby (i.e., it uses RARRAY_PTR()).
1 parent ddae1c4 commit 90ee82f

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

spec/nativeconversion.mspec

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
class NativeHandleChecker
32
EXPECTED_FAILURES = {
43
"C-API Debug function rb_debug_inspector_open creates a debug context and calls the given callback" => 2,
@@ -26,9 +25,6 @@ class NativeHandleChecker
2625
"C-API String function rb_string_value_cstr returns a non-null pointer for a UTF-16 string" => 1,
2726
"C-API String function rb_string_value_cstr raises an error if a string contains a null" => 1,
2827
"C-API String function rb_string_value_cstr raises an error if a UTF-16 string contains a null" => 1,
29-
"C-API Util function rb_scan_args assigns Hash arguments" => 1,
30-
"C-API Util function rb_scan_args assigns required and Hash arguments" => 1,
31-
"C-API Util function rb_scan_args assigns required, optional, splat, post-splat, Hash and block arguments" => 1,
3228
"C-API Util function rb_get_kwargs extracts required arguments in the order requested" => 2,
3329
"C-API Util function rb_get_kwargs extracts required and optional arguments in the order requested" => 1,
3430
"C-API Util function rb_get_kwargs raises an error if a required argument is not in the hash" => 1,
@@ -50,7 +46,11 @@ class NativeHandleChecker
5046
end
5147

5248
def passed(state, example)
53-
(Truffle::Debug.cexts_to_native_count - @start_count).should == (EXPECTED_FAILURES[state.description] || 0)
49+
expected = EXPECTED_FAILURES[state.description] || 0
50+
actual = Truffle::Debug.cexts_to_native_count - @start_count
51+
unless actual == expected
52+
raise SpecExpectationNotMetError, "Expected #{expected} conversions to native but was #{actual}"
53+
end
5454
end
5555
end
5656

spec/ruby/optional/capi/ext/util_spec.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ extern "C" {
77
#endif
88

99
VALUE util_spec_rb_scan_args(VALUE self, VALUE argv, VALUE fmt, VALUE expected, VALUE acc) {
10-
int i, result, argc = (int)RARRAY_LEN(argv);
11-
VALUE args[6], failed, a1, a2, a3, a4, a5, a6;
12-
13-
failed = rb_intern("failed");
14-
a1 = a2 = a3 = a4 = a5 = a6 = failed;
15-
16-
for(i = 0; i < argc; i++) {
17-
args[i] = rb_ary_entry(argv, i);
18-
}
10+
int result, argc;
11+
VALUE a1, a2, a3, a4, a5, a6;
12+
13+
argc = (int) RARRAY_LEN(argv);
14+
VALUE* args = RARRAY_PTR(argv);
15+
/* the line above can be replaced with this for Ruby implementations which do not support RARRAY_PTR() yet
16+
VALUE args[6];
17+
for(int i = 0; i < argc; i++) {
18+
args[i] = rb_ary_entry(argv, i);
19+
} */
20+
21+
a1 = a2 = a3 = a4 = a5 = a6 = INT2FIX(-1);
1922

2023
#ifdef RB_SCAN_ARGS_KEYWORDS
2124
if (*RSTRING_PTR(fmt) == 'k') {

spec/ruby/optional/capi/util_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
end
1616

1717
it "assigns the required arguments scanned" do
18-
@o.rb_scan_args([1, 2], "2", 2, @acc).should == 2
19-
ScratchPad.recorded.should == [1, 2]
18+
obj = Object.new
19+
@o.rb_scan_args([obj, 2], "2", 2, @acc).should == 2
20+
ScratchPad.recorded.should == [obj, 2]
2021
end
2122

2223
it "raises an ArgumentError if there are insufficient arguments" do

0 commit comments

Comments
 (0)