1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Only expose Ruby Shape API if VM_CHECK_MODE is enabled

This commit is contained in:
Aaron Patterson 2022-10-12 14:37:02 -07:00
parent 1b0c9d0e3d
commit e5058b58c2
No known key found for this signature in database
GPG key ID: 953170BCB4FFAFC6
5 changed files with 40 additions and 13 deletions

View file

@ -356,7 +356,7 @@ module RubyVM::MJIT
source_shape_id = if dest_shape_id == C.INVALID_SHAPE_ID
dest_shape_id
else
RubyVM::Shape.find_by_id(dest_shape_id).parent_id
C.rb_shape_get_shape_by_id(dest_shape_id).parent_id
end
src = +''

View file

@ -6,11 +6,11 @@ module RubyVM::MJIT
class << C
def SHAPE_BITS
RubyVM::Shape::SHAPE_BITS
Primitive.cexpr! 'UINT2NUM(SHAPE_BITS)'
end
def SHAPE_FLAG_SHIFT
RubyVM::Shape::SHAPE_FLAG_SHIFT
Primitive.cexpr! 'UINT2NUM(SHAPE_FLAG_SHIFT)'
end
def ROBJECT_EMBED_LEN_MAX
@ -29,6 +29,12 @@ module RubyVM::MJIT
Primitive.has_cache_for_send(cc.to_i, insn)
end
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)))'
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)))'
@ -595,6 +601,21 @@ module RubyVM::MJIT
@rb_serial_t ||= CType::Immediate.parse("unsigned long long")
end
def C.rb_shape
@rb_shape ||= CType::Struct.new(
"rb_shape", Primitive.cexpr!("SIZEOF(struct rb_shape)"),
edges: [CType::Pointer.new { self.rb_id_table }, Primitive.cexpr!("OFFSETOF((*((struct rb_shape *)NULL)), edges)")],
edge_name: [self.ID, Primitive.cexpr!("OFFSETOF((*((struct rb_shape *)NULL)), edge_name)")],
iv_count: [self.attr_index_t, Primitive.cexpr!("OFFSETOF((*((struct rb_shape *)NULL)), iv_count)")],
type: [CType::Immediate.parse("uint8_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_shape *)NULL)), type)")],
parent_id: [self.shape_id_t, Primitive.cexpr!("OFFSETOF((*((struct rb_shape *)NULL)), parent_id)")],
)
end
def C.rb_shape_t
@rb_shape_t ||= self.rb_shape
end
def C.VALUE
@VALUE ||= CType::Immediate.find(Primitive.cexpr!("SIZEOF(VALUE)"), Primitive.cexpr!("SIGNED_TYPE_P(VALUE)"))
end

22
shape.c
View file

@ -306,6 +306,13 @@ rb_shape_set_shape(VALUE obj, rb_shape_t* shape)
rb_shape_set_shape_id(obj, rb_shape_id(shape));
}
VALUE
rb_shape_flags_mask(void)
{
return SHAPE_FLAG_MASK;
}
#if VM_CHECK_MODE > 0
VALUE rb_cShape;
/*
@ -440,19 +447,19 @@ rb_shape_parent(VALUE self)
}
}
VALUE
static VALUE
rb_shape_debug_shape(VALUE self, VALUE obj)
{
return rb_shape_t_to_rb_cShape(rb_shape_get_shape(obj));
}
VALUE
static VALUE
rb_shape_root_shape(VALUE self)
{
return rb_shape_t_to_rb_cShape(rb_shape_get_root_shape());
}
VALUE
static VALUE
rb_shape_frozen_root_shape(VALUE self)
{
return rb_shape_t_to_rb_cShape(rb_shape_get_frozen_root_shape());
@ -505,12 +512,6 @@ next_shape_id(VALUE self)
return INT2NUM(GET_VM()->next_shape_id);
}
VALUE
rb_shape_flags_mask(void)
{
return SHAPE_FLAG_MASK;
}
static VALUE
rb_shape_find_by_id(VALUE mod, VALUE id)
{
@ -520,10 +521,12 @@ rb_shape_find_by_id(VALUE mod, VALUE id)
}
return rb_shape_t_to_rb_cShape(rb_shape_get_shape_by_id(shape_id));
}
#endif
void
Init_shape(void)
{
#if VM_CHECK_MODE > 0
rb_cShape = rb_define_class_under(rb_cRubyVM, "Shape", rb_cObject);
rb_undef_alloc_func(rb_cShape);
@ -548,4 +551,5 @@ Init_shape(void)
rb_define_singleton_method(rb_cShape, "of", rb_shape_debug_shape, 1);
rb_define_singleton_method(rb_cShape, "root_shape", rb_shape_root_shape, 0);
rb_define_singleton_method(rb_cShape, "frozen_root_shape", rb_shape_frozen_root_shape, 0);
#endif
}

View file

@ -179,4 +179,4 @@ class TestShapes < Test::Unit::TestCase
RubyVM::Shape.find_by_id(-1)
end
end
end
end if defined?(RubyVM::Shape)

View file

@ -380,6 +380,8 @@ generator = BindingGenerator.new(
rb_mjit_compile_info
rb_mjit_unit
rb_serial_t
rb_shape
rb_shape_t
],
dynamic_types: %w[
VALUE