Skip to content

Commit

Permalink
RJIT: Use SIZET macros instead of original PTR ones
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Mar 12, 2023
1 parent c6bea54 commit 46a3634
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 27 deletions.
8 changes: 0 additions & 8 deletions rjit_c.c
Expand Up @@ -206,14 +206,6 @@ rjit_get_proc_ptr(VALUE procv)
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.
// Multiplying 8 for compatibility with libclang's offsetof.
#define OFFSETOF(ptr, member) RB_SIZE2NUM(((char *)&ptr.member - (char*)&ptr) * 8)
Expand Down
36 changes: 18 additions & 18 deletions rjit_c.rb
Expand Up @@ -421,38 +421,38 @@ def rb_str_getbyte

def rb_shape_get_shape_by_id(shape_id)
_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)
end

def rb_iseq_check(iseq)
_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)
end

def rb_iseq_path(iseq)
_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

def vm_ci_argc(ci)
_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

def vm_ci_flag(ci)
_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

def vm_ci_mid(ci)
_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

def rjit_opts
addr = Primitive.cexpr! 'PTR2NUM((VALUE)&rb_rjit_opts)'
addr = Primitive.cexpr! 'SIZET2NUM((VALUE)&rb_rjit_opts)'
rjit_options.new(addr)
end

Expand All @@ -466,12 +466,12 @@ def rjit_cancel_all(reason)
# Convert an encoded VM pointer to an insn BIN.
def rb_vm_insn_decode(encoded)
# 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

# Convert Integer VALUE to an actual Ruby object
def to_ruby(value)
Primitive.cexpr! '(VALUE)NUM2PTR(value)'
Primitive.cexpr! '(VALUE)NUM2SIZET(value)'
end

def HAVE_LIBCAPSTONE
Expand All @@ -490,12 +490,12 @@ def HAVE_LIBCAPSTONE

# Convert insn BINs to encoded VM pointers.
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

# Convert RubyVM::InstructionSequence to C.rb_iseq_t.
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)
end
end
Expand Down Expand Up @@ -879,31 +879,31 @@ def C.SHAPE_MASK
end

def C.rb_block_param_proxy
Primitive.cexpr! %q{ PTR2NUM(rb_block_param_proxy) }
Primitive.cexpr! %q{ SIZET2NUM(rb_block_param_proxy) }
end

def C.rb_cFalseClass
Primitive.cexpr! %q{ PTR2NUM(rb_cFalseClass) }
Primitive.cexpr! %q{ SIZET2NUM(rb_cFalseClass) }
end

def C.rb_cFloat
Primitive.cexpr! %q{ PTR2NUM(rb_cFloat) }
Primitive.cexpr! %q{ SIZET2NUM(rb_cFloat) }
end

def C.rb_cInteger
Primitive.cexpr! %q{ PTR2NUM(rb_cInteger) }
Primitive.cexpr! %q{ SIZET2NUM(rb_cInteger) }
end

def C.rb_cNilClass
Primitive.cexpr! %q{ PTR2NUM(rb_cNilClass) }
Primitive.cexpr! %q{ SIZET2NUM(rb_cNilClass) }
end

def C.rb_cSymbol
Primitive.cexpr! %q{ PTR2NUM(rb_cSymbol) }
Primitive.cexpr! %q{ SIZET2NUM(rb_cSymbol) }
end

def C.rb_cTrueClass
Primitive.cexpr! %q{ PTR2NUM(rb_cTrueClass) }
Primitive.cexpr! %q{ SIZET2NUM(rb_cTrueClass) }
end

def C.CALL_DATA
Expand Down
2 changes: 1 addition & 1 deletion tool/rjit/bindgen.rb
Expand Up @@ -443,7 +443,7 @@ def push_target(target)
RUBY_FL_SINGLETON
RSTRUCT_EMBED_LEN_MASK
],
PTR: %w[
SIZET: %w[
rb_cFalseClass
rb_cFloat
rb_cInteger
Expand Down

0 comments on commit 46a3634

Please sign in to comment.