Class: LLDB::NativeHandle
- Inherits:
-
Object
- Object
- LLDB::NativeHandle
- Defined in:
- lib/lldb/native_handle.rb
Constant Summary collapse
- NULL_POINTER =
FFI::Pointer.new(0)
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize(ptr, release:) ⇒ NativeHandle
constructor
A new instance of NativeHandle.
- #to_ptr ⇒ Object
Constructor Details
#initialize(ptr, release:) ⇒ NativeHandle
Returns a new instance of NativeHandle.
12 13 14 15 16 17 18 |
# File 'lib/lldb/native_handle.rb', line 12 def initialize(ptr, release:) # The resource is detached with Array#shift, which is a single Ruby VM # operation. Finalizers cannot safely acquire a Mutex on all supported # Rubies, so the detach itself must not depend on one. @state = [[ptr, release]] ObjectSpace.define_finalizer(self, self.class.finalizer(@state)) end |
Class Method Details
.finalizer(state) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/lldb/native_handle.rb', line 44 def self.finalizer(state) ->(_object_id) do resource = state.shift next unless resource pointer, release = resource next unless pointer && !pointer.null? begin release.call(pointer) rescue StandardError # Finalizers must never raise into an unrelated Ruby thread. end end end |
Instance Method Details
#close ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/lldb/native_handle.rb', line 32 def close resource = @state.shift return false unless resource pointer, release = resource release.call(pointer) unless pointer.null? true end |
#closed? ⇒ Boolean
27 28 29 |
# File 'lib/lldb/native_handle.rb', line 27 def closed? @state.empty? end |
#to_ptr ⇒ Object
21 22 23 24 |
# File 'lib/lldb/native_handle.rb', line 21 def to_ptr resource = @state.first resource ? resource.first : NULL_POINTER end |