summaryrefslogtreecommitdiff
path: root/ext/fiddle/lib
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-06 06:59:24 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-06 06:59:24 +0000
commit4bada8b864e445b6eebe1a341e30cad94dbcaf84 (patch)
treebb7e4ed991aa16eda953d536265c6f9e5dc03a5d /ext/fiddle/lib
parentca3c007f058f17b2f0bf3c5ccc6701f3f6d49ca5 (diff)
* ext/fiddle/*: Adding fiddle library to wrap libffi
* test/fiddle/*: testing fiddle extension * ext/dl/lib/dl.rb: Requiring fiddle if it is available * ext/dl/lib/dl/callback.rb: using Fiddle if it is available * ext/dl/lib/dl/func.rb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27640 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/fiddle/lib')
-rw-r--r--ext/fiddle/lib/fiddle.rb27
-rw-r--r--ext/fiddle/lib/fiddle/closure.rb17
-rw-r--r--ext/fiddle/lib/fiddle/function.rb5
3 files changed, 49 insertions, 0 deletions
diff --git a/ext/fiddle/lib/fiddle.rb b/ext/fiddle/lib/fiddle.rb
new file mode 100644
index 0000000..bc4017e
--- /dev/null
+++ b/ext/fiddle/lib/fiddle.rb
@@ -0,0 +1,27 @@
+require 'fiddle.so'
+require 'fiddle/function'
+require 'fiddle/closure'
+require 'dl'
+
+module Fiddle
+ Pointer = DL::CPtr
+
+ if WINDOWS
+ def self.win32_last_error
+ Thread.current[:__FIDDLE_WIN32_LAST_ERROR__]
+ end
+
+ def self.win32_last_error= error
+ Thread.current[:__FIDDLE_WIN32_LAST_ERROR__] = error
+ end
+ end
+
+ def self.last_error
+ Thread.current[:__FIDDLE_LAST_ERROR__]
+ end
+
+ def self.last_error= error
+ Thread.current[:__DL2_LAST_ERROR__] = error
+ Thread.current[:__FIDDLE_LAST_ERROR__] = error
+ end
+end
diff --git a/ext/fiddle/lib/fiddle/closure.rb b/ext/fiddle/lib/fiddle/closure.rb
new file mode 100644
index 0000000..dc2b7a6
--- /dev/null
+++ b/ext/fiddle/lib/fiddle/closure.rb
@@ -0,0 +1,17 @@
+module Fiddle
+ class Closure
+ attr_reader :ctype
+ attr_reader :args
+
+ class BlockCaller < Fiddle::Closure
+ def initialize ctype, args, abi = Fiddle::Function::DEFAULT, &block
+ super(ctype, args, abi)
+ @block = block
+ end
+
+ def call *args
+ @block.call(*args)
+ end
+ end
+ end
+end
diff --git a/ext/fiddle/lib/fiddle/function.rb b/ext/fiddle/lib/fiddle/function.rb
new file mode 100644
index 0000000..7b9e735
--- /dev/null
+++ b/ext/fiddle/lib/fiddle/function.rb
@@ -0,0 +1,5 @@
+module Fiddle
+ class Function
+ attr_reader :abi
+ end
+end