/usr/lib/ruby/vendor_ruby/ffi-glib/ptr_array.rb is in ruby-gir-ffi 0.9.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | require 'ffi-glib/container_class_methods'
require 'ffi-glib/array_methods'
GLib.load_class :PtrArray
module GLib
# Overrides for GPtrArray, GLib's automatically growing array of
# pointers.
class PtrArray
include Enumerable
include ArrayMethods
extend ContainerClassMethods
attr_reader :element_type
POINTER_SIZE = FFI.type_size(:pointer)
class << self
# Remove stub generated by builder.
remove_method :add if method_defined? :add
end
def initialize(type)
@element_type = type
store_pointer Lib.g_ptr_array_new
end
def self.from_enumerable(type, it)
new(type).tap { |arr| arr.add_array it }
end
def self.add(array, data)
array.add data
end
def reset_typespec(typespec)
@element_type = typespec
self
end
def add(data)
ptr = GirFFI::InPointer.from element_type, data
Lib.g_ptr_array_add self, ptr
end
def add_array(ary)
ary.each { |item| add item }
end
def data_ptr
@struct[:pdata]
end
def element_size
POINTER_SIZE
end
def each
length.times do |idx|
yield index(idx)
end
end
def length
@struct[:len]
end
def ==(other)
to_a == other.to_a
end
end
end
|