Class: FFI::MemoryPointer
Class Method Summary collapse
Methods inherited from Pointer
Class Method Details
.from_bytes(data) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/idevice/c.rb', line 28 def self.from_bytes(data) if block_given? new(data.bytesize) do |p| p.write_bytes(data) yield(p) end else p = new(data.size) p.write_bytes(data) p end end |
.null_terminated_array_of_strings(strs) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/idevice/c.rb', line 41 def self.null_terminated_array_of_strings(strs) psize = FFI::MemoryPointer.size * (strs.count+1) pstrs = strs.map{|str| FFI::MemoryPointer.from_string(str) } if block_given? new(psize) do |aryp| aryp.write_array_of_pointer(pstrs) yield(aryp) end else aryp.instance_variable_set(:@_string_pointers, pstrs) # retain reference for garbage collection aryp.write_array_of_pointer(pstrs) return aryp end end |