Skip to content

Commit ab30432

Browse files
committed
Get Fiddle MRI tests working
1 parent 3d04110 commit ab30432

File tree

10 files changed

+30
-27
lines changed

10 files changed

+30
-27
lines changed

lib/truffle/truffle/fiddle_backend.rb

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ module Truffle::Fiddle
1212
SIZEOF_LONG = Truffle::FFI::Pointer.find_type_size(:long)
1313

1414
INT_NFI_TYPE = "SINT#{SIZEOF_INT * 8}"
15+
UINT_NFI_TYPE = "UINT#{SIZEOF_INT * 8}"
1516
LONG_NFI_TYPE = "SINT#{SIZEOF_LONG * 8}"
17+
ULONG_NFI_TYPE = "UINT#{SIZEOF_LONG * 8}"
1618

1719
def self.type_to_nfi(type)
1820
case type
@@ -28,12 +30,14 @@ def self.type_to_nfi(type)
2830
INT_NFI_TYPE
2931
when Fiddle::TYPE_LONG
3032
LONG_NFI_TYPE
33+
when -Fiddle::TYPE_LONG
34+
ULONG_NFI_TYPE
3135
when Fiddle::TYPE_FLOAT
3236
'FLOAT'
3337
when Fiddle::TYPE_DOUBLE
3438
'DOUBLE'
3539
else
36-
raise 'not implemented'
40+
raise "#{type} not implemented"
3741
end
3842
end
3943

@@ -66,7 +70,9 @@ def self.convert_ruby_to_native(type, val)
6670
end
6771
when Fiddle::TYPE_INT
6872
Integer(val)
69-
when Fiddle::TYPE_DOUBLE
73+
when -Fiddle::TYPE_LONG
74+
Integer(val)
75+
when Fiddle::TYPE_FLOAT, Fiddle::TYPE_DOUBLE
7076
Float(val)
7177
else
7278
raise "#{val.inspect} to type #{type}"
@@ -79,7 +85,7 @@ def self.convert_native_to_ruby(type, val)
7985
nil
8086
when Fiddle::TYPE_VOIDP
8187
Fiddle::Pointer.new(Truffle::Interop.to_native(val))
82-
when Fiddle::TYPE_INT, Fiddle::TYPE_DOUBLE
88+
when Fiddle::TYPE_INT, Fiddle::TYPE_FLOAT, Fiddle::TYPE_DOUBLE
8389
val
8490
else
8591
raise "#{val.inspect} from type #{type}"
@@ -169,14 +175,19 @@ class Function
169175

170176
DEFAULT = :default_abi
171177

172-
def initialize(ptr, args, ret_type, abi = DEFAULT, name:)
178+
def initialize(ptr, args, ret_type, abi = DEFAULT, name: nil)
173179
@arg_types = args
174180
@ret_type = ret_type
175181
args = args.map { |arg| Truffle::Fiddle.type_to_nfi(arg) }
176182
ret_type = Truffle::Fiddle.type_to_nfi(ret_type)
177183
signature = "(#{args.join(',')}):#{ret_type}"
178-
ptr = Truffle::POSIX.nfi_symbol_from_pointer(ptr, signature)
179-
@function = ptr.bind(signature)
184+
185+
if ptr.is_a?(Closure)
186+
@function = ptr.method(:call)
187+
else
188+
ptr = Truffle::POSIX.nfi_symbol_from_pointer(ptr, signature)
189+
@function = ptr.bind(signature)
190+
end
180191
end
181192

182193
def call(*args)
@@ -189,8 +200,8 @@ def call(*args)
189200

190201
class Closure
191202

192-
def initialize(*args)
193-
raise 'not implemented'
203+
def initialize(ret, args, abi = Function::DEFAULT)
204+
# does nothing - 'not implemented' when used
194205
end
195206

196207
def to_i(*args)
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
exclude :test_class_size, "needs investigation"
2-
exclude :test_class_size_with_count, "needs investigation"
31
exclude :test_aref_pointer, "needs investigation"
42
exclude :test_aref_pointer_array, "needs investigation"
53
exclude :test_set_ctypes, "needs investigation"
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
exclude :test_set_ctypes, "needs investigation"
2-
exclude :test_class_size_with_count, "needs investigation"
3-
exclude :test_class_size, "needs investigation"

test/mri/excludes/Fiddle/TestClosure.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
exclude :test_argument_errors, "needs investigation"
22
exclude :test_block_caller, "needs investigation"
33
exclude :test_call, "needs investigation"
4+
exclude :test_conversion_char, "needs investigation"
5+
exclude :test_conversion_int, "needs investigation"
6+
exclude :test_conversion_long, "needs investigation"
7+
exclude :test_conversion_long_long, "needs investigation"
8+
exclude :test_conversion_short, "needs investigation"
9+
exclude :test_conversion_unsigned_char, "needs investigation"
10+
exclude :test_conversion_unsigned_int, "needs investigation"
11+
exclude :test_conversion_unsigned_long, "needs investigation"
12+
exclude :test_conversion_unsigned_long_long, "needs investigation"
13+
exclude :test_conversion_unsigned_short, "needs investigation"
414
exclude :test_returner, "needs investigation"
5-
exclude :test_memsize, "needs investigation"

test/mri/excludes/Fiddle/TestFunc.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
exclude :test_isdigit, "needs investigation"
21
exclude :test_string, "needs investigation"
3-
exclude :test_random, "needs investigation"
42
exclude :test_strtod, "needs investigation"
5-
exclude :test_atof, "needs investigation"
63
exclude :test_qsort1, "needs investigation"
74
exclude :test_sinf, "needs investigation"
85
exclude :test_syscall_with_tainted_string, "needs investigation"

test/mri/excludes/Fiddle/TestHandle.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
exclude :test_handle_close, "needs investigation"
99
exclude :test_handle_close_twice, "needs investigation"
1010
exclude :test_to_i, "needs investigation"
11-
exclude :test_initialize_flags, "needs investigation"
1211
exclude :test_sym_closed_handle, "needs investigation"
13-
exclude :test_dlopen_returns_handle, "needs investigation"
1412
exclude :test_initialize_noargs, "needs investigation"
1513
exclude :test_disable_close, "needs investigation"
1614
exclude :test_static_sym, "needs investigation"
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
exclude :test_ensure_call_dlload, "needs investigation"
21
exclude :test_strcpy, "needs investigation"
3-
exclude :test_atof, "needs investigation"
4-
exclude :test_malloc, "needs investigation"
52
exclude :test_struct, "needs investigation"
63
exclude :test_unsigned_result, "needs investigation"
74
exclude :test_value, "needs investigation"
8-
exclude :test_isdigit, "needs investigation"
9-
exclude :test_sizeof_double, "needs investigation"
105
exclude :test_io, "needs investigation"
116
exclude :test_sizeof, "needs investigation"
12-
exclude :test_no_message_with_debug, "needs investigation"

test/mri/excludes/Fiddle/TestPointer.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
exclude :test_no_memory_leak, "needs investigation"
21
exclude :test_minus, "needs investigation"
32
exclude :test_inspect, "needs investigation"
43
exclude :test_to_str, "needs investigation"

test/mri/failing.exclude

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ dtrace/test_require.rb
135135
dtrace/test_singleton_function.rb
136136
dtrace/test_string.rb
137137
erb/test_erb_command.rb
138-
fiddle/test_cparser.rb
139138
irb/test_completion.rb
140139
irb/test_option.rb
141140
irb/test_raise_no_backtrace_exception.rb

test/mri/tests/fiddle/test_pointer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def test_null_pointer
226226
end
227227

228228
def test_no_memory_leak
229-
assert_no_memory_leak(%w[-W0 -rfiddle.so], '', '100_000.times {Fiddle::Pointer.allocate}', rss: true)
229+
assert_no_memory_leak(%w[-W0 -rfiddle], '', '100_000.times {Fiddle::Pointer.allocate}', rss: true) # TruffleRuby - MRI was -rfiddle.so
230230
end
231231
end
232232
end if defined?(Fiddle)

0 commit comments

Comments
 (0)