mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@f8a2d54
This commit is contained in:
parent
ed377cc9aa
commit
809f0b8a13
76 changed files with 2451 additions and 224 deletions
|
@ -345,6 +345,40 @@ static VALUE object_spec_rb_class_inherited_p(VALUE self, VALUE mod, VALUE arg)
|
|||
return rb_class_inherited_p(mod, arg);
|
||||
}
|
||||
|
||||
static VALUE speced_allocator(VALUE klass) {
|
||||
VALUE flags = 0;
|
||||
VALUE instance;
|
||||
if (rb_class_inherited_p(klass, rb_cString)) {
|
||||
flags = T_STRING;
|
||||
} else if (rb_class_inherited_p(klass, rb_cArray)) {
|
||||
flags = T_ARRAY;
|
||||
} else {
|
||||
flags = T_OBJECT;
|
||||
}
|
||||
instance = rb_newobj_of(klass, flags);
|
||||
rb_iv_set(instance, "@from_custom_allocator", Qtrue);
|
||||
return instance;
|
||||
}
|
||||
|
||||
static VALUE define_alloc_func(VALUE self, VALUE klass) {
|
||||
rb_define_alloc_func(klass, speced_allocator);
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE undef_alloc_func(VALUE self, VALUE klass) {
|
||||
rb_undef_alloc_func(klass);
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE speced_allocator_p(VALUE self, VALUE klass) {
|
||||
rb_alloc_func_t allocator = rb_get_alloc_func(klass);
|
||||
return (allocator == speced_allocator) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
static VALUE custom_alloc_func_p(VALUE self, VALUE klass) {
|
||||
rb_alloc_func_t allocator = rb_get_alloc_func(klass);
|
||||
return allocator ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
void Init_object_spec(void) {
|
||||
VALUE cls = rb_define_class("CApiObjectSpecs", rb_cObject);
|
||||
|
@ -412,6 +446,10 @@ void Init_object_spec(void) {
|
|||
rb_define_method(cls, "rb_ivar_defined", object_spec_rb_ivar_defined, 2);
|
||||
rb_define_method(cls, "rb_copy_generic_ivar", object_spec_rb_copy_generic_ivar, 2);
|
||||
rb_define_method(cls, "rb_free_generic_ivar", object_spec_rb_free_generic_ivar, 1);
|
||||
rb_define_method(cls, "rb_define_alloc_func", define_alloc_func, 1);
|
||||
rb_define_method(cls, "rb_undef_alloc_func", undef_alloc_func, 1);
|
||||
rb_define_method(cls, "speced_allocator?", speced_allocator_p, 1);
|
||||
rb_define_method(cls, "custom_alloc_func?", custom_alloc_func_p, 1);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue