summaryrefslogtreecommitdiff
path: root/ext/dl/lib/dl/callback.rb
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-31 21:13:09 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-31 21:13:09 +0000
commit07308c4d30b8c5260e5366c8eed2abf054d86fe7 (patch)
tree0444881bba7151db3ff7e6776404cfc1643a8383 /ext/dl/lib/dl/callback.rb
parent88326272bc079cd0f47759e02e174f9ff1a73774 (diff)
* ext/dl/*: remove DL as it is replaced by Fiddle.
[Feature #5458] Thanks to Jonan Scheffler <jonanscheffler@gmail.com> for this patch * test/dl/*: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48217 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/dl/lib/dl/callback.rb')
-rw-r--r--ext/dl/lib/dl/callback.rb112
1 files changed, 0 insertions, 112 deletions
diff --git a/ext/dl/lib/dl/callback.rb b/ext/dl/lib/dl/callback.rb
deleted file mode 100644
index 1722d3c6b98..00000000000
--- a/ext/dl/lib/dl/callback.rb
+++ /dev/null
@@ -1,112 +0,0 @@
-require 'dl'
-require 'thread'
-
-module DL
- # The mutual exclusion (Mutex) semaphore for the DL module
- SEM = Mutex.new # :nodoc:
-
- if DL.fiddle?
- # A Hash of callback Procs
- #
- # Uses Fiddle
- CdeclCallbackProcs = {} # :nodoc:
-
- # A Hash of the addresses of callback Proc
- #
- # Uses Fiddle
- CdeclCallbackAddrs = {} # :nodoc:
-
- # A Hash of Stdcall callback Procs
- #
- # Uses Fiddle on win32
- StdcallCallbackProcs = {} # :nodoc:
-
- # A Hash of the addresses of Stdcall callback Procs
- #
- # Uses Fiddle on win32
- StdcallCallbackAddrs = {} # :nodoc:
- end
-
- def set_callback_internal(proc_entry, addr_entry, argc, ty, abi = nil, &cbp)
- if( argc < 0 )
- raise(ArgumentError, "arity should not be less than 0.")
- end
- addr = nil
-
- if DL.fiddle?
- abi ||= Fiddle::Function::DEFAULT
- closure = Fiddle::Closure::BlockCaller.new(ty, [TYPE_VOIDP] * argc, abi, &cbp)
- proc_entry[closure.to_i] = closure
- addr = closure.to_i
- else
- SEM.synchronize{
- ary = proc_entry[ty]
- (0...MAX_CALLBACK).each{|n|
- idx = (n * DLSTACK_SIZE) + argc
- if( ary[idx].nil? )
- ary[idx] = cbp
- addr = addr_entry[ty][idx]
- break
- end
- }
- }
- end
-
- addr
- end
-
- def set_cdecl_callback(ty, argc, &cbp)
- set_callback_internal(CdeclCallbackProcs, CdeclCallbackAddrs, argc, ty, &cbp)
- end
-
- def set_stdcall_callback(ty, argc, &cbp)
- if DL.fiddle?
- set_callback_internal(StdcallCallbackProcs, StdcallCallbackAddrs, argc, ty, Fiddle::Function::STDCALL, &cbp)
- else
- set_callback_internal(StdcallCallbackProcs, StdcallCallbackAddrs, argc, ty, &cbp)
- end
- end
-
- def remove_callback_internal(proc_entry, addr_entry, addr, ctype = nil)
- if DL.fiddle?
- addr = addr.to_i
- return false unless proc_entry.key?(addr)
- proc_entry.delete(addr)
- true
- else
- index = nil
- if( ctype )
- addr_entry[ctype].each_with_index{|xaddr, idx|
- if( xaddr == addr )
- index = idx
- end
- }
- else
- addr_entry.each{|ty,entry|
- entry.each_with_index{|xaddr, idx|
- if( xaddr == addr )
- index = idx
- end
- }
- }
- end
- if( index and proc_entry[ctype][index] )
- proc_entry[ctype][index] = nil
- return true
- else
- return false
- end
- end
- end
-
- def remove_cdecl_callback(addr, ctype = nil)
- remove_callback_internal(CdeclCallbackProcs, CdeclCallbackAddrs, addr, ctype)
- end
-
- def remove_stdcall_callback(addr, ctype = nil)
- remove_callback_internal(StdcallCallbackProcs, StdcallCallbackAddrs, addr, ctype)
- end
-
- alias set_callback set_cdecl_callback
- alias remove_callback remove_cdecl_callback
-end