类 RubyVM::RJIT::CPointer::Pointer

属性

type[R]

公共类方法

new(addr, type) 点击以切换源代码

@param addr [Integer] @param type [Class] RubyVM::RJIT::CType::*

# File ruby_vm/rjit/c_pointer.rb, line 280
def initialize(addr, type)
  @addr = addr
  @type = type
end

私有类方法

define(block) 点击以切换源代码
调用父类方法
# File ruby_vm/rjit/c_pointer.rb, line 321
def self.define(block)
  Class.new(self) do
    define_method(:initialize) do |addr|
      super(addr, block.call)
    end

    # Type-level []=: Used by struct fields
    # @param addr [Integer]
    # @param value [Integer, RubyVM::RJIT::CPointer::Struct] an address itself, or an object that return an address with to_i
    define_singleton_method(:[]=) do |addr, value|
      value = value.to_i
      Fiddle::Pointer.new(addr)[0, Fiddle::SIZEOF_VOIDP] = [value].pack(Fiddle::PackInfo::PACK_MAP[Fiddle::TYPE_VOIDP])
    end
  end
end

公共实例方法

*() 点击以切换源代码

解引用

# File ruby_vm/rjit/c_pointer.rb, line 292
def *
  return nil if dest_addr == 0
  @type.new(dest_addr)
end
+(index) 点击以切换源代码

将地址移动到像数组一样的指针

# File ruby_vm/rjit/c_pointer.rb, line 286
def +(index)
  raise ArgumentError unless index.is_a?(Integer)
  Pointer.new(@addr + index * Fiddle::SIZEOF_VOIDP, @type)
end
[](index) 点击以切换源代码

Array 访问

# File ruby_vm/rjit/c_pointer.rb, line 298
def [](index)
  (self + index).*
end
[]=(index, value) 点击以切换源代码

Array 设置 @param index [Integer] @param value [Integer, RubyVM::RJIT::CPointer::Struct] 地址本身或使用 to_i 返回地址的对象

# File ruby_vm/rjit/c_pointer.rb, line 305
def []=(index, value)
  Fiddle::Pointer.new(@addr + index * Fiddle::SIZEOF_VOIDP)[0, Fiddle::SIZEOF_VOIDP] =
    [value.to_i].pack(Fiddle::PackInfo::PACK_MAP[Fiddle::TYPE_VOIDP])
end
to_i() 点击以切换源代码

获取原始地址

# File ruby_vm/rjit/c_pointer.rb, line 311
def to_i
  @addr
end

私有实例方法

dest_addr() 点击以切换源代码
# File ruby_vm/rjit/c_pointer.rb, line 317
def dest_addr
  Fiddle::Pointer.new(@addr)[0, Fiddle::SIZEOF_VOIDP].unpack1(Fiddle::PackInfo::PACK_MAP[Fiddle::TYPE_VOIDP])
end