mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Refined test [Bug #18140]
This commit is contained in:
parent
cb5a41c0a0
commit
ab63f6d854
2 changed files with 13 additions and 40 deletions
|
@ -1,63 +1,33 @@
|
||||||
#include "ruby.h"
|
#include "ruby.h"
|
||||||
|
|
||||||
VALUE cFoo;
|
|
||||||
|
|
||||||
// Foo
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int dummy;
|
|
||||||
} Foo;
|
|
||||||
|
|
||||||
static void Foo_free(void* _self) {
|
|
||||||
xfree(_self);
|
|
||||||
}
|
|
||||||
|
|
||||||
static rb_data_type_t Foo_type = {
|
|
||||||
"Foo",
|
|
||||||
{NULL, Foo_free, NULL },
|
|
||||||
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
|
||||||
};
|
|
||||||
|
|
||||||
static VALUE Foo_alloc(VALUE klass) {
|
|
||||||
Foo* _self = ALLOC(Foo);
|
|
||||||
return TypedData_Wrap_Struct(klass, &Foo_type, _self);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bar
|
// Bar
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int dummy;
|
int dummy;
|
||||||
} Bar;
|
} Bar;
|
||||||
|
|
||||||
static void Bar_free(void* _self) {
|
|
||||||
xfree(_self);
|
|
||||||
}
|
|
||||||
|
|
||||||
static rb_data_type_t Bar_type = {
|
static rb_data_type_t Bar_type = {
|
||||||
"Bar",
|
"Bar",
|
||||||
{NULL, Bar_free, NULL },
|
{NULL, RUBY_TYPED_DEFAULT_FREE, NULL },
|
||||||
.flags = RUBY_TYPED_FREE_IMMEDIATELY,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static VALUE Bar_alloc(VALUE klass) {
|
static VALUE
|
||||||
Bar* bar = ALLOC(Bar);
|
Bar_alloc(VALUE klass)
|
||||||
return TypedData_Wrap_Struct(klass, &Bar_type, bar);
|
{
|
||||||
|
return TypedData_Wrap_Struct(klass, &Bar_type, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE Bar_to_ary(VALUE _self) {
|
VALUE Bar_to_ary(VALUE _self) {
|
||||||
VALUE ary = rb_ary_new2(2);
|
VALUE ary = rb_ary_new2(2);
|
||||||
rb_ary_push(ary, Foo_alloc(cFoo));
|
VALUE foo = rb_ary_new2(0);
|
||||||
rb_ary_push(ary, Foo_alloc(cFoo));
|
rb_ary_push(ary, foo);
|
||||||
rb_ary_push(ary, Foo_alloc(cFoo));
|
rb_ary_push(ary, foo);
|
||||||
|
rb_ary_push(ary, foo);
|
||||||
return ary;
|
return ary;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Init_to_ary_concat() {
|
void Init_to_ary_concat() {
|
||||||
VALUE mBug = rb_define_module("Bug");
|
VALUE mBug = rb_define_module("Bug");
|
||||||
cFoo = rb_define_class_under(mBug, "Foo", rb_cObject);
|
|
||||||
rb_gc_register_address(&cFoo);
|
|
||||||
rb_define_alloc_func(cFoo, Foo_alloc);
|
|
||||||
|
|
||||||
VALUE bar = rb_define_class_under(mBug, "Bar", rb_cObject);
|
VALUE bar = rb_define_class_under(mBug, "Bar", rb_cObject);
|
||||||
rb_define_alloc_func(bar, Bar_alloc);
|
rb_define_alloc_func(bar, Bar_alloc);
|
||||||
rb_define_method(bar, "to_ary", Bar_to_ary, 0);
|
rb_define_method(bar, "to_ary", Bar_to_ary, 0);
|
||||||
|
|
|
@ -656,7 +656,10 @@ class TestArray < Test::Unit::TestCase
|
||||||
assert_raise(FrozenError) { @cls[0].freeze.concat(:foo) }
|
assert_raise(FrozenError) { @cls[0].freeze.concat(:foo) }
|
||||||
|
|
||||||
a = @cls[nil]
|
a = @cls[nil]
|
||||||
def (x = Object.new).to_ary; Array.new(10) {nil} << :ok; end
|
def (x = Object.new).to_ary
|
||||||
|
ary = Array.new(2)
|
||||||
|
ary << [] << [] << :ok
|
||||||
|
end
|
||||||
EnvUtil.under_gc_stress {a.concat(x)}
|
EnvUtil.under_gc_stress {a.concat(x)}
|
||||||
GC.start
|
GC.start
|
||||||
assert_equal(:ok, a.last)
|
assert_equal(:ok, a.last)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue