зеркало из https://github.com/github/ruby.git
* struct.c: accessing >10 member caused segmentation fault. [ruby-dev:26247]
* test/ruby/test_struct.rb: test it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8546 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
a9543d64f1
Коммит
3aa5496c98
|
@ -1,3 +1,10 @@
|
||||||
|
Thu Jun 2 00:02:16 2005 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
|
* struct.c: accessing >10 member caused segmentation fault.
|
||||||
|
[ruby-dev:26247]
|
||||||
|
|
||||||
|
* test/ruby/test_struct.rb: test it.
|
||||||
|
|
||||||
Wed Jun 1 11:30:09 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
Wed Jun 1 11:30:09 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
||||||
|
|
||||||
* bcc32/Makefile.sub: can use single quote character in DESTDIR.
|
* bcc32/Makefile.sub: can use single quote character in DESTDIR.
|
||||||
|
|
6
struct.c
6
struct.c
|
@ -132,7 +132,9 @@ static VALUE rb_struct_ref7(obj) VALUE obj; {return RSTRUCT(obj)->ptr[7];}
|
||||||
static VALUE rb_struct_ref8(obj) VALUE obj; {return RSTRUCT(obj)->ptr[8];}
|
static VALUE rb_struct_ref8(obj) VALUE obj; {return RSTRUCT(obj)->ptr[8];}
|
||||||
static VALUE rb_struct_ref9(obj) VALUE obj; {return RSTRUCT(obj)->ptr[9];}
|
static VALUE rb_struct_ref9(obj) VALUE obj; {return RSTRUCT(obj)->ptr[9];}
|
||||||
|
|
||||||
static VALUE (*ref_func[10])() = {
|
#define N_REF_FUNC (sizeof(ref_func) / sizeof(VALUE (*)()))
|
||||||
|
|
||||||
|
static VALUE (*ref_func[])() = {
|
||||||
rb_struct_ref0,
|
rb_struct_ref0,
|
||||||
rb_struct_ref1,
|
rb_struct_ref1,
|
||||||
rb_struct_ref2,
|
rb_struct_ref2,
|
||||||
|
@ -211,7 +213,7 @@ make_struct(name, members, klass)
|
||||||
for (i=0; i< RARRAY(members)->len; i++) {
|
for (i=0; i< RARRAY(members)->len; i++) {
|
||||||
ID id = SYM2ID(RARRAY(members)->ptr[i]);
|
ID id = SYM2ID(RARRAY(members)->ptr[i]);
|
||||||
if (rb_is_local_id(id) || rb_is_const_id(id)) {
|
if (rb_is_local_id(id) || rb_is_const_id(id)) {
|
||||||
if (i<sizeof(ref_func)) {
|
if (i < N_REF_FUNC) {
|
||||||
rb_define_method_id(nstr, id, ref_func[i], 0);
|
rb_define_method_id(nstr, id, ref_func[i], 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -21,4 +21,16 @@ class TestStruct < Test::Unit::TestCase
|
||||||
test.bar = 47
|
test.bar = 47
|
||||||
assert_equal(47, test.bar)
|
assert_equal(47, test.bar)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# [ruby-dev:26247] more than 10 struct members causes segmentation fault
|
||||||
|
def test_morethan10members
|
||||||
|
list = %w( a b c d e f g h i j k l m n o p )
|
||||||
|
until list.empty?
|
||||||
|
c = Struct.new(* list.map {|ch| ch.intern }).new
|
||||||
|
list.each do |ch|
|
||||||
|
c.__send__(ch)
|
||||||
|
end
|
||||||
|
list.pop
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Загрузка…
Ссылка в новой задаче