Skip to content
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

Import JRuby implementation #147

Merged
merged 4 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
- '3.1'
- '3.2'
- debug
- jruby
include:
- { os: windows-latest , ruby: mingw }
- { os: windows-latest , ruby: mswin }
Expand Down Expand Up @@ -53,13 +54,10 @@ jobs:
matrix.ruby == 'mingw' ||
matrix.ruby == 'mswin'

- run: rake build
# This is for ensuring using Fiddle in this repository.
- run: ruby -Ilib test/run.rb

- run: gem install pkg/*.gem

- run: rake test
env:
RUBYOPT: --disable=gems
- run: rake install

- name: Run test against installed gem
# We can't use Fiddle gem with RubyInstaller because
Expand All @@ -69,6 +67,7 @@ jobs:
matrix.os != 'windows-latest' ||
(matrix.os == 'windows-latest' && matrix.ruby == 'mswin')
run: |
ruby -run -e mkdir -- -p tmp/
ruby -run -e cp -- -pr test/ tmp/
cd tmp
ruby test/run.rb
Expand Down
13 changes: 9 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ namespace :version do
end
end

require 'rake/extensiontask'
Rake::ExtensionTask.new("fiddle")
Rake::ExtensionTask.new("-test-/memory_view")
if RUBY_ENGINE == "ruby"
require 'rake/extensiontask'
Rake::ExtensionTask.new("fiddle")
Rake::ExtensionTask.new("-test-/memory_view")
task test: :compile
else
task :compile
end

task :default => [:compile, :test]
task default: :test
4 changes: 3 additions & 1 deletion dockerfiles/fedora-latest.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ RUN \
dnf clean all

RUN \
gem install bundler
gem install \
test-unit \
test-unit-ruby-core

RUN \
useradd --user-group --create-home user
Expand Down
5 changes: 5 additions & 0 deletions ext/fiddle/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# frozen_string_literal: true
require 'mkmf'

if RUBY_ENGINE == "jruby"
File.write('Makefile', dummy_makefile("").join)
return
end

# :stopdoc:

def gcc?
Expand Down
2 changes: 2 additions & 0 deletions fiddle.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ Gem::Specification.new do |spec|
"lib/fiddle/cparser.rb",
"lib/fiddle/function.rb",
"lib/fiddle/import.rb",
"lib/fiddle/jruby.rb",
"lib/fiddle/pack.rb",
"lib/fiddle/ruby.rb",
"lib/fiddle/struct.rb",
"lib/fiddle/types.rb",
"lib/fiddle/value.rb",
Expand Down
43 changes: 35 additions & 8 deletions lib/fiddle.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'fiddle.so'
require "fiddle/#{RUBY_ENGINE}"
require 'fiddle/closure'
require 'fiddle/function'
require 'fiddle/version'
Expand All @@ -10,36 +10,63 @@ module Fiddle
# Returns the last win32 +Error+ of the current executing +Thread+ or nil
# if none
def self.win32_last_error
Thread.current[:__FIDDLE_WIN32_LAST_ERROR__]
if RUBY_ENGINE == 'jruby'
errno = FFI.errno
errno == 0 ? nil : errno
else
Thread.current[:__FIDDLE_WIN32_LAST_ERROR__]
end
end

# Sets the last win32 +Error+ of the current executing +Thread+ to +error+
def self.win32_last_error= error
Thread.current[:__FIDDLE_WIN32_LAST_ERROR__] = error
if RUBY_ENGINE == 'jruby'
FFI.errno = error || 0
else
Thread.current[:__FIDDLE_WIN32_LAST_ERROR__] = error
end
end

# Returns the last win32 socket +Error+ of the current executing
# +Thread+ or nil if none
def self.win32_last_socket_error
Thread.current[:__FIDDLE_WIN32_LAST_SOCKET_ERROR__]
if RUBY_ENGINE == 'jruby'
errno = FFI.errno
errno == 0 ? nil : errno
else
Thread.current[:__FIDDLE_WIN32_LAST_SOCKET_ERROR__]
end
end

# Sets the last win32 socket +Error+ of the current executing
# +Thread+ to +error+
def self.win32_last_socket_error= error
Thread.current[:__FIDDLE_WIN32_LAST_SOCKET_ERROR__] = error
if RUBY_ENGINE == 'jruby'
FFI.errno = error || 0
else
Thread.current[:__FIDDLE_WIN32_LAST_SOCKET_ERROR__] = error
end
end
end

# Returns the last +Error+ of the current executing +Thread+ or nil if none
def self.last_error
Thread.current[:__FIDDLE_LAST_ERROR__]
if RUBY_ENGINE == 'jruby'
errno = FFI.errno
errno == 0 ? nil : errno
else
Thread.current[:__FIDDLE_LAST_ERROR__]
end
end

# Sets the last +Error+ of the current executing +Thread+ to +error+
def self.last_error= error
Thread.current[:__DL2_LAST_ERROR__] = error
Thread.current[:__FIDDLE_LAST_ERROR__] = error
if RUBY_ENGINE == 'jruby'
FFI.errno = error || 0
else
Thread.current[:__DL2_LAST_ERROR__] = error
Thread.current[:__FIDDLE_LAST_ERROR__] = error
end
end

# call-seq: dlopen(library) => Fiddle::Handle
Expand Down
Loading