RJIT: Use SIZET macros instead of original PTR ones

This commit is contained in:
Takashi Kokubun 2023-03-11 20:46:58 -08:00
parent c6bea54c70
commit 46a3634bcf
3 changed files with 19 additions and 27 deletions

View File

@ -206,14 +206,6 @@ rjit_get_proc_ptr(VALUE procv)
return proc; return proc;
} }
#if SIZEOF_LONG == SIZEOF_VOIDP
#define NUM2PTR(x) NUM2ULONG(x)
#define PTR2NUM(x) ULONG2NUM(x)
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
#define NUM2PTR(x) NUM2ULL(x)
#define PTR2NUM(x) ULL2NUM(x)
#endif
// An offsetof implementation that works for unnamed struct and union. // An offsetof implementation that works for unnamed struct and union.
// Multiplying 8 for compatibility with libclang's offsetof. // Multiplying 8 for compatibility with libclang's offsetof.
#define OFFSETOF(ptr, member) RB_SIZE2NUM(((char *)&ptr.member - (char*)&ptr) * 8) #define OFFSETOF(ptr, member) RB_SIZE2NUM(((char *)&ptr.member - (char*)&ptr) * 8)

View File

@ -421,38 +421,38 @@ module RubyVM::RJIT # :nodoc: all
def rb_shape_get_shape_by_id(shape_id) def rb_shape_get_shape_by_id(shape_id)
_shape_id = shape_id.to_i _shape_id = shape_id.to_i
shape_addr = Primitive.cexpr! 'PTR2NUM((VALUE)rb_shape_get_shape_by_id((shape_id_t)NUM2UINT(_shape_id)))' shape_addr = Primitive.cexpr! 'SIZET2NUM((VALUE)rb_shape_get_shape_by_id((shape_id_t)NUM2UINT(_shape_id)))'
rb_shape_t.new(shape_addr) rb_shape_t.new(shape_addr)
end end
def rb_iseq_check(iseq) def rb_iseq_check(iseq)
_iseq_addr = iseq.to_i _iseq_addr = iseq.to_i
iseq_addr = Primitive.cexpr! 'PTR2NUM((VALUE)rb_iseq_check((rb_iseq_t *)NUM2PTR(_iseq_addr)))' iseq_addr = Primitive.cexpr! 'SIZET2NUM((VALUE)rb_iseq_check((rb_iseq_t *)NUM2SIZET(_iseq_addr)))'
rb_iseq_t.new(iseq_addr) rb_iseq_t.new(iseq_addr)
end end
def rb_iseq_path(iseq) def rb_iseq_path(iseq)
_iseq_addr = iseq.to_i _iseq_addr = iseq.to_i
Primitive.cexpr! 'rb_iseq_path((rb_iseq_t *)NUM2PTR(_iseq_addr))' Primitive.cexpr! 'rb_iseq_path((rb_iseq_t *)NUM2SIZET(_iseq_addr))'
end end
def vm_ci_argc(ci) def vm_ci_argc(ci)
_ci_addr = ci.to_i _ci_addr = ci.to_i
Primitive.cexpr! 'UINT2NUM(vm_ci_argc((CALL_INFO)NUM2PTR(_ci_addr)))' Primitive.cexpr! 'UINT2NUM(vm_ci_argc((CALL_INFO)NUM2SIZET(_ci_addr)))'
end end
def vm_ci_flag(ci) def vm_ci_flag(ci)
_ci_addr = ci.to_i _ci_addr = ci.to_i
Primitive.cexpr! 'UINT2NUM(vm_ci_flag((CALL_INFO)NUM2PTR(_ci_addr)))' Primitive.cexpr! 'UINT2NUM(vm_ci_flag((CALL_INFO)NUM2SIZET(_ci_addr)))'
end end
def vm_ci_mid(ci) def vm_ci_mid(ci)
_ci_addr = ci.to_i _ci_addr = ci.to_i
Primitive.cexpr! 'SIZET2NUM((size_t)vm_ci_mid((CALL_INFO)NUM2PTR(_ci_addr)))' Primitive.cexpr! 'SIZET2NUM((size_t)vm_ci_mid((CALL_INFO)NUM2SIZET(_ci_addr)))'
end end
def rjit_opts def rjit_opts
addr = Primitive.cexpr! 'PTR2NUM((VALUE)&rb_rjit_opts)' addr = Primitive.cexpr! 'SIZET2NUM((VALUE)&rb_rjit_opts)'
rjit_options.new(addr) rjit_options.new(addr)
end end
@ -466,12 +466,12 @@ module RubyVM::RJIT # :nodoc: all
# Convert an encoded VM pointer to an insn BIN. # Convert an encoded VM pointer to an insn BIN.
def rb_vm_insn_decode(encoded) def rb_vm_insn_decode(encoded)
# Using rb_vm_insn_addr2opcode to return trace_ insns # Using rb_vm_insn_addr2opcode to return trace_ insns
Primitive.cexpr! 'INT2NUM(rb_vm_insn_addr2opcode((void *)NUM2PTR(encoded)))' Primitive.cexpr! 'INT2NUM(rb_vm_insn_addr2opcode((void *)NUM2SIZET(encoded)))'
end end
# Convert Integer VALUE to an actual Ruby object # Convert Integer VALUE to an actual Ruby object
def to_ruby(value) def to_ruby(value)
Primitive.cexpr! '(VALUE)NUM2PTR(value)' Primitive.cexpr! '(VALUE)NUM2SIZET(value)'
end end
def HAVE_LIBCAPSTONE def HAVE_LIBCAPSTONE
@ -490,12 +490,12 @@ module RubyVM::RJIT # :nodoc: all
# Convert insn BINs to encoded VM pointers. # Convert insn BINs to encoded VM pointers.
def rb_vm_insn_encode(bin) def rb_vm_insn_encode(bin)
Primitive.cexpr! 'PTR2NUM((VALUE)rb_vm_get_insns_address_table()[NUM2INT(bin)])' Primitive.cexpr! 'SIZET2NUM((VALUE)rb_vm_get_insns_address_table()[NUM2INT(bin)])'
end end
# Convert RubyVM::InstructionSequence to C.rb_iseq_t. # Convert RubyVM::InstructionSequence to C.rb_iseq_t.
def rb_iseqw_to_iseq(iseqw) def rb_iseqw_to_iseq(iseqw)
iseq_addr = Primitive.cexpr! 'PTR2NUM((VALUE)rb_iseqw_to_iseq(iseqw))' iseq_addr = Primitive.cexpr! 'SIZET2NUM((VALUE)rb_iseqw_to_iseq(iseqw))'
rb_iseq_t.new(iseq_addr) rb_iseq_t.new(iseq_addr)
end end
end end
@ -879,31 +879,31 @@ module RubyVM::RJIT # :nodoc: all
end end
def C.rb_block_param_proxy def C.rb_block_param_proxy
Primitive.cexpr! %q{ PTR2NUM(rb_block_param_proxy) } Primitive.cexpr! %q{ SIZET2NUM(rb_block_param_proxy) }
end end
def C.rb_cFalseClass def C.rb_cFalseClass
Primitive.cexpr! %q{ PTR2NUM(rb_cFalseClass) } Primitive.cexpr! %q{ SIZET2NUM(rb_cFalseClass) }
end end
def C.rb_cFloat def C.rb_cFloat
Primitive.cexpr! %q{ PTR2NUM(rb_cFloat) } Primitive.cexpr! %q{ SIZET2NUM(rb_cFloat) }
end end
def C.rb_cInteger def C.rb_cInteger
Primitive.cexpr! %q{ PTR2NUM(rb_cInteger) } Primitive.cexpr! %q{ SIZET2NUM(rb_cInteger) }
end end
def C.rb_cNilClass def C.rb_cNilClass
Primitive.cexpr! %q{ PTR2NUM(rb_cNilClass) } Primitive.cexpr! %q{ SIZET2NUM(rb_cNilClass) }
end end
def C.rb_cSymbol def C.rb_cSymbol
Primitive.cexpr! %q{ PTR2NUM(rb_cSymbol) } Primitive.cexpr! %q{ SIZET2NUM(rb_cSymbol) }
end end
def C.rb_cTrueClass def C.rb_cTrueClass
Primitive.cexpr! %q{ PTR2NUM(rb_cTrueClass) } Primitive.cexpr! %q{ SIZET2NUM(rb_cTrueClass) }
end end
def C.CALL_DATA def C.CALL_DATA

View File

@ -443,7 +443,7 @@ generator = BindingGenerator.new(
RUBY_FL_SINGLETON RUBY_FL_SINGLETON
RSTRUCT_EMBED_LEN_MASK RSTRUCT_EMBED_LEN_MASK
], ],
PTR: %w[ SIZET: %w[
rb_cFalseClass rb_cFalseClass
rb_cFloat rb_cFloat
rb_cInteger rb_cInteger