Skip to content

Commit

Permalink
Import TruffleRuby implementation
Browse files Browse the repository at this point in the history
Fix GH-145

lib/fiddle/truffleruby.rb is based on
https://github.com/oracle/truffleruby/blob/master/lib/truffle/truffle/fiddle_backend.rb
.

Here are changes for it:

* Add `Fiddle::Types::VARIADIC`
* Add `Fiddle::Types::CONST_STRING`
* Add `Fiddle::Types::BOOL`
* Add `Fiddle::ALIGN_BOOL`
* Add `Fiddle::SIZEOF_BOOL`
* Add `Fiddle::SIZEOF_CONST_STRING`
* Add support for specifying type as not only `Fiddle::Types::*` but also
  `Symbol` like `:int`
* Add `Fiddle::Error` as base the error class
* Add support for `Fiddle::Pointer.malloc {}`
  `Fiddle::Pointer`
* Add support for `Fiddle.free(#to_int)`
* Accept `Fiddle::Function(need_gvl:)` but it's just ignored
* `Fiddle::Function#initialize`: Add an argument validation
* `Fiddle::Function#initialize`: Keep arguments as instance variables for
  getters
* Add support for `Fiddle::Handle.sym`
* Add support for `Fiddle::Handle.[]`
* Add support for `Fiddle::Handle.sym_defined?`
* Add support for `Fiddle::Handle#sym`
* Add support for `Fiddle::Handle#[]`
* Add support for `Fiddle::Handle#sym_defined?`
* Add support for `Fiddle::Pointer.malloc`
* Add support for `Fiddle::Pointer.to_ptr(#to_ptr)`
* Add support for `Fiddle::Pointer#free=`
* Add `Fiddle::Pointer#freed?`
* Add support for `Fiddle::Pointer#call_free`
* Add support for `Fiddle::Pointer#to_i`
* Add support for `Fiddle::Pointer#to_int`
* Add support for `Fiddle::Pointer#ptr`
* Add support for `Fiddle::Pointer#+@`
* Add support for `Fiddle::Pointer#ref`
* Add support for `Fiddle::Pointer#-@`
* Add support for `Fiddle::Pointer#null?`
* Add support for `Fiddle::Pointer#to_s`
* Add support for `Fiddle::Pointer#to_str`
* Add support for `Fiddle::Pointer#inspect`
* Add support for `Fiddle::Pointer#<=>`
* Add support for `Fiddle::Pointer#==`
* Add support for `Fiddle::Pointer#eql?`
* Add support for `Fiddle::Pointer#+`
* Add support for `Fiddle::Pointer#-`
* Add support for `Fiddle::Pointer#[]=`
* Add support for `Fiddle::Pointer#size`
* Add support for `Fiddle::Pointer#size=`
* Add `Fiddle::ClearedReferenceError`
* Add no-op `Fiddle::Pinned`
* Add `Fiddle::NULL`

Some features are still "not implemented". So there are some "omit"s
for TruffleRuby in tests.
  • Loading branch information
kou committed Sep 29, 2024
1 parent 833bd73 commit 494e3f6
Show file tree
Hide file tree
Showing 14 changed files with 719 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ jobs:
- '3.2'
- debug
- jruby
- truffleruby
include:
- { os: windows-latest , ruby: mingw }
- { os: windows-latest , ruby: mswin }
exclude:
- { os: macos-14 , ruby: '2.5' }
- { os: windows-latest , ruby: '3.0' }
- { os: windows-latest , ruby: debug }
- { os: windows-latest , ruby: truffleruby }

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion ext/fiddle/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'mkmf'

if RUBY_ENGINE == "jruby"
unless RUBY_ENGINE == "ruby"
File.write('Makefile', dummy_makefile("").join)
return
end
Expand Down
2 changes: 2 additions & 0 deletions fiddle.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ Gem::Specification.new do |spec|
"lib/fiddle/import.rb",
"lib/fiddle/jruby.rb",
"lib/fiddle/pack.rb",
"lib/fiddle/ruby.rb",
"lib/fiddle/struct.rb",
"lib/fiddle/truffleruby.rb",
"lib/fiddle/types.rb",
"lib/fiddle/value.rb",
"lib/fiddle/version.rb",
Expand Down
7 changes: 1 addition & 6 deletions lib/fiddle.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# frozen_string_literal: true

case RUBY_ENGINE
when 'jruby'
require 'fiddle/jruby'
else
require 'fiddle.so'
end
require "fiddle/#{RUBY_ENGINE}"
require 'fiddle/closure'
require 'fiddle/function'
require 'fiddle/version'
Expand Down
2 changes: 1 addition & 1 deletion lib/fiddle/jruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def -@
end

def ref
cptr = Pointer.malloc(FFI::Type::POINTER.size)
cptr = Pointer.malloc(FFI::Type::POINTER.size, RUBY_FREE)
cptr.ffi_ptr.put_pointer(0, ffi_ptr)
cptr
end
Expand Down
1 change: 1 addition & 0 deletions lib/fiddle/ruby.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "fiddle.so"
Loading

0 comments on commit 494e3f6

Please sign in to comment.