[ruby-dev:27911] Re: ruby 1.8 dumps core
From:
Tanaka Akira <akr@...17n.org>
Date:
2005-12-01 04:10:35 UTC
List:
ruby-dev #27911
In article <20051130210645.7228E2B0.ocean@m2.ccsnet.ne.jp>,
H.Yamamoto <ocean@m2.ccsnet.ne.jp> writes:
> rb_funcall で GC が走るようにしたところ、私の環境でも test/yaml が
> 落ちるようになりました。逆に、GC を無効にするとメモリエラーも出なく
> なります。
rb_funcall では甘いんじゃないですかね。
次のように ruby_xmalloc とかの garbage_collect 呼び出し条件
を細工して常に GC させるようにすると、[ruby-dev:27905] のパッ
チを当てても yaml っぽい感じで落ちます。
Index: gc.c
===================================================================
RCS file: /src/ruby/gc.c,v
retrieving revision 1.216
diff -u -r1.216 gc.c
--- gc.c 25 Oct 2005 05:30:10 -0000 1.216
+++ gc.c 1 Dec 2005 03:43:04 -0000
@@ -106,6 +106,8 @@
rb_exc_raise(nomem_error);
}
+int always_gc = 0;
+
void *
ruby_xmalloc(long size)
{
@@ -117,7 +119,7 @@
if (size == 0) size = 1;
malloc_increase += size;
- if (malloc_increase > malloc_limit) {
+ if (always_gc || malloc_increase > malloc_limit) {
garbage_collect();
}
RUBY_CRITICAL(mem = malloc(size));
@@ -165,6 +167,7 @@
if (!ptr) return ruby_xmalloc(size);
if (size == 0) size = 1;
malloc_increase += size;
+ if (always_gc) garbage_collect();
RUBY_CRITICAL(mem = realloc(ptr, size));
if (!mem) {
if (garbage_collect()) {
@@ -394,7 +397,7 @@
{
VALUE obj;
- if (!freelist && !garbage_collect())
+ if ((always_gc || !freelist) && !garbage_collect())
rb_memerror();
obj = (VALUE)freelist;
@@ -1018,6 +1021,7 @@
unsigned long live = 0;
mark_source_filename(ruby_sourcefile);
+ if (source_filenames)
st_foreach(source_filenames, sweep_source_filename, 0);
freelist = 0;
Index: main.c
===================================================================
RCS file: /src/ruby/main.c,v
retrieving revision 1.14
diff -u -r1.14 main.c
--- main.c 12 Sep 2005 10:44:20 -0000 1.14
+++ main.c 1 Dec 2005 03:43:04 -0000
@@ -24,6 +24,8 @@
int
main(int argc, char **argv, char **envp)
{
+ extern int always_gc;
+ always_gc = getenv("RUBY_ALWAYS_GC") != NULL;
#ifdef _WIN32
NtInitialize(&argc, &argv);
#endif
Index: eval.c
===================================================================
RCS file: /src/ruby/eval.c,v
retrieving revision 1.847
diff -u -r1.847 eval.c
--- eval.c 30 Nov 2005 15:50:51 -0000 1.847
+++ eval.c 1 Dec 2005 03:43:04 -0000
@@ -7753,14 +7753,14 @@
void
Init_load(void)
{
- rb_load_path = rb_ary_new();
rb_define_readonly_variable("$:", &rb_load_path);
rb_define_readonly_variable("$-I", &rb_load_path);
rb_define_readonly_variable("$LOAD_PATH", &rb_load_path);
+ rb_load_path = rb_ary_new();
- rb_features = rb_ary_new();
rb_define_readonly_variable("$\"", &rb_features);
rb_define_readonly_variable("$LOADED_FEATURES", &rb_features);
+ rb_features = rb_ary_new();
rb_define_global_function("load", rb_f_load, -1);
rb_define_global_function("require", rb_f_require, 1);
@@ -7770,8 +7770,8 @@
rb_define_global_function("autoload?", rb_f_autoload_p, 1);
rb_global_variable(&ruby_wrapper);
- ruby_dln_librefs = rb_ary_new();
rb_global_variable(&ruby_dln_librefs);
+ ruby_dln_librefs = rb_ary_new();
}
static void
Index: io.c
===================================================================
RCS file: /src/ruby/io.c,v
retrieving revision 1.393
diff -u -r1.393 io.c
--- io.c 11 Nov 2005 11:08:17 -0000 1.393
+++ io.c 1 Dec 2005 03:43:04 -0000
@@ -5482,9 +5482,9 @@
rb_output_fs = Qnil;
rb_define_hooked_variable("$,", &rb_output_fs, 0, rb_str_setter);
+ rb_global_variable(&rb_default_rs);
rb_rs = rb_default_rs = rb_str_new2("\n");
rb_output_rs = Qnil;
- rb_global_variable(&rb_default_rs);
OBJ_FREEZE(rb_default_rs); /* avoid modifying RS_default */
rb_define_hooked_variable("$/", &rb_rs, 0, rb_str_setter);
rb_define_hooked_variable("$-0", &rb_rs, 0, rb_str_setter);
Index: ruby.c
===================================================================
RCS file: /src/ruby/ruby.c,v
retrieving revision 1.111
diff -u -r1.111 ruby.c
--- ruby.c 5 Nov 2005 04:43:44 -0000 1.111
+++ ruby.c 1 Dec 2005 03:43:04 -0000
@@ -1159,8 +1159,8 @@
rb_define_hooked_variable("$0", &rb_progname, 0, set_arg0);
rb_define_hooked_variable("$PROGRAM_NAME", &rb_progname, 0, set_arg0);
- rb_argv = rb_ary_new();
rb_define_readonly_variable("$*", &rb_argv);
+ rb_argv = rb_ary_new();
rb_define_global_const("ARGV", rb_argv);
rb_define_readonly_variable("$-a", &do_split);
rb_global_variable(&rb_argv0);
Index: signal.c
===================================================================
RCS file: /src/ruby/signal.c,v
retrieving revision 1.70
diff -u -r1.70 signal.c
--- signal.c 8 Nov 2005 08:49:45 -0000 1.70
+++ signal.c 1 Dec 2005 03:43:04 -0000
@@ -944,10 +944,10 @@
#endif
#ifdef SIGBUS
- install_sighandler(SIGBUS, sigbus);
+ //install_sighandler(SIGBUS, sigbus);
#endif
#ifdef SIGSEGV
- install_sighandler(SIGSEGV, sigsegv);
+ //install_sighandler(SIGSEGV, sigsegv);
#endif
#ifdef SIGPIPE
install_sighandler(SIGPIPE, sigpipe);
Index: variable.c
===================================================================
RCS file: /src/ruby/variable.c,v
retrieving revision 1.130
diff -u -r1.130 variable.c
--- variable.c 20 Oct 2005 02:56:22 -0000 1.130
+++ variable.c 1 Dec 2005 03:43:04 -0000
@@ -424,6 +424,7 @@
void
rb_gc_mark_global_tbl(void)
{
+ if (rb_global_tbl)
st_foreach_safe(rb_global_tbl, mark_global_entry, 0);
}
% RUBY_ALWAYS_GC= ./ruby test/runner.rb test/yaml
Loaded suite yaml
Started
zsh: segmentation fault (core dumped) RUBY_ALWAYS_GC= ./ruby test/runner.rb test/yaml
% gdb ruby core
GNU gdb 6.3-debian
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-linux"...Using host libthread_db library "/lib/tls/libthread_db.so.1".
Core was generated by `test/runner.rb test_akira(YAML_U'.
Program terminated with signal 11, Segmentation fault.
warning: current_sos: Can't read pathname for load map: Input/output error
Reading symbols from /lib/tls/libdl.so.2...Reading symbols from /usr/lib/debug/lib/tls/libdl-2.3.2.so...done.
done.
Loaded symbols for /lib/tls/libdl.so.2
Reading symbols from /lib/tls/libcrypt.so.1...Reading symbols from /usr/lib/debug/lib/tls/libcrypt-2.3.2.so...done.
done.
Loaded symbols for /lib/tls/libcrypt.so.1
Reading symbols from /lib/tls/libm.so.6...Reading symbols from /usr/lib/debug/lib/tls/libm-2.3.2.so...done.
done.
Loaded symbols for /lib/tls/libm.so.6
Reading symbols from /lib/tls/libc.so.6...Reading symbols from /usr/lib/debug/lib/tls/libc-2.3.2.so...done.
done.
Loaded symbols for /lib/tls/libc.so.6
Reading symbols from /lib/ld-linux.so.2...Reading symbols from /usr/lib/debug/lib/ld-2.3.2.so...done.
done.
Loaded symbols for /lib/ld-linux.so.2
Reading symbols from /tmp/19/lib/ruby/1.9/i686-linux/stringio.so...done.
Loaded symbols for /tmp/19/lib/ruby/1.9/i686-linux/stringio.so
Reading symbols from /tmp/19/lib/ruby/1.9/i686-linux/syck.so...done.
Loaded symbols for /tmp/19/lib/ruby/1.9/i686-linux/syck.so
#0 st_foreach (table=0x1129b3f, func=0x80727e0 <mark_entry>, arg=2) at st.c:465
465 for(i = 0; i < table->num_bins; i++) {
(gdb) bt
#0 st_foreach (table=0x1129b3f, func=0x80727e0 <mark_entry>, arg=2) at st.c:465
#1 0x08072825 in mark_tbl (tbl=0x1129b3f, lev=134686688) at gc.c:653
#2 0x08072bf2 in gc_mark_children (ptr=136079868, lev=1) at gc.c:967
#3 0x08072a57 in rb_gc_mark (ptr=134686688) at gc.c:722
#4 0xb7d8b16a in syck_mark_emitter (emitter=0x80727e0) at rubyext.c:1957
#5 0x08072c10 in gc_mark_children (ptr=3084236464, lev=1) at gc.c:924
#6 0x080727b3 in mark_locations_array (x=0xbffb45f4, n=16685) at gc.c:627
#7 0x080736d9 in garbage_collect () at gc.c:1316
#8 0x08072372 in rb_newobj () at gc.c:400
#9 0x08074afe in hash_alloc (klass=134686688) at hash.c:204
#10 0x08074b63 in rb_hash_new () at hash.c:216
#11 0xb7d8b2e1 in syck_emitter_reset (argc=134686688, argv=0x80727e0, self=3084236464) at rubyext.c:2014
#12 0x0806c6ea in call_cfunc (func=0xb7d8b280 <syck_emitter_reset>, recv=3084236464, len=17996607, argc=134686800,
argv=0xbffb4898) at eval.c:5406
#13 0x0805f5e9 in rb_call0 (klass=3084567440, recv=3084236464, id=15097, oid=134686688, argc=1, argv=0xbffb4898,
body=0xb7dac2b4, flags=0) at eval.c:5617
#14 0x0805f8b0 in rb_call (klass=3084567440, recv=3084236464, mid=15097, argc=1, argv=0xbffb4898, scope=0) at eval.c:5790
#15 0x0805a0ae in rb_eval (self=3084574100, n=0x80727e0) at ruby.h:659
#16 0x08059939 in rb_eval (self=3084574100, n=0x80727e0) at eval.c:3433
#17 0x0805f153 in rb_call0 (klass=3084549140, recv=3084574100, id=15073, oid=134686688, argc=2, argv=0xbffb5978,
body=0xb7daecf8, flags=0) at eval.c:5698
#18 0x0805f8b0 in rb_call (klass=3084549140, recv=3084574100, mid=15073, argc=2, argv=0xbffb5978, scope=0) at eval.c:5790
#19 0x0805a0ae in rb_eval (self=3084270164, n=0x80727e0) at ruby.h:659
#20 0x08059457 in rb_eval (self=3084270164, n=0x80727e0) at eval.c:2976
#21 0x0805f153 in rb_call0 (klass=3085006868, recv=3084270164, id=13985, oid=134686688, argc=0, argv=0x0, body=0xb7da49d8,
flags=0) at eval.c:5698
#22 0x0805f8b0 in rb_call (klass=3085006868, recv=3084270164, mid=13985, argc=0, argv=0x0, scope=0) at eval.c:5790
#23 0x0805a0ae in rb_eval (self=3084304324, n=0x80727e0) at ruby.h:659
#24 0x0805a185 in rb_eval (self=3084304324, n=0x80727e0) at ruby.h:683
#25 0x0805a3e8 in rb_eval (self=3084304324, n=0x80727e0) at ruby.h:683
#26 0x0805f153 in rb_call0 (klass=3084309204, recv=3084304324, id=13953, oid=134686688, argc=2, argv=0xbffb82d8,
body=0xb7dc3158, flags=8) at eval.c:5698
#27 0x0805f8b0 in rb_call (klass=3084309204, recv=3084304324, mid=13953, argc=2, argv=0xbffb82d8, scope=1) at eval.c:5790
#28 0x0805a0ae in rb_eval (self=3084304324, n=0x80727e0) at ruby.h:659
#29 0x0805f153 in rb_call0 (klass=3084309204, recv=3084304324, id=14697, oid=134686688, argc=0, argv=0xbffb8e8c,
body=0xb7db29fc, flags=8) at eval.c:5698
#30 0x0805f8b0 in rb_call (klass=3084309204, recv=3084304324, mid=14697, argc=0, argv=0xbffb8e8c, scope=1) at eval.c:5790
#31 0x0805fb32 in send_funcall (argc=0, argv=0xbffb8e8c, recv=3084304324, scope=134686688) at ruby.h:659
#32 0x0805fbf0 in rb_f_send (argc=134686688, argv=0x80727e0, recv=134686688) at eval.c:5848
#33 0x0806c6ea in call_cfunc (func=0x805fbc0 <rb_f_send>, recv=3084304324, len=17996607, argc=134686800, argv=0xbffb8e88)
---Type <return> to continue, or q <return> to quit---
at eval.c:5406
#34 0x0805f5e9 in rb_call0 (klass=3085040788, recv=3084304324, id=3945, oid=134686688, argc=1, argv=0xbffb8e88,
body=0xb7e1dd18, flags=8) at eval.c:5617
#35 0x0805f8b0 in rb_call (klass=3085040788, recv=3084304324, mid=3945, argc=1, argv=0xbffb8e88, scope=1) at eval.c:5790
#36 0x0805a0ae in rb_eval (self=3084304324, n=0x80727e0) at ruby.h:659
#37 0x0805973a in rb_eval (self=3084304324, n=0x80727e0) at eval.c:3067
#38 0x08059882 in rb_eval (self=3084304324, n=0x80727e0) at eval.c:3116
#39 0x0805f153 in rb_call0 (klass=3084836680, recv=3084304324, id=5209, oid=134686688, argc=1, argv=0xbffba6e8,
body=0xb7e04c14, flags=0) at eval.c:5698
#40 0x0805f8b0 in rb_call (klass=3084836680, recv=3084304324, mid=5209, argc=1, argv=0xbffba6e8, scope=0) at eval.c:5790
#41 0x0805a0ae in rb_eval (self=3084305584, n=0x80727e0) at ruby.h:659
#42 0x0806525a in call_block (arg=0x1129b3f) at eval.c:8584
#43 0x08065155 in rb_block_pass (func=0x8065240 <call_block>, arg=3220942864, proc=3084295664) at eval.c:8523
#44 0x0806529b in block_pass (self=134686800, node=0x1129b3f) at eval.c:8593
#45 0x0805ad5a in rb_eval (self=3084305584, n=0x80727e0) at eval.c:2949
#46 0x0805d33a in rb_yield_0 (val=3084304324, self=3084305584, klass=4, flags=0, avalue=0) at eval.c:4795
#47 0x0805d9e9 in rb_yield (val=134686688) at eval.c:4876
#48 0x080d57bf in rb_ary_each (ary=3084304464) at array.c:1140
#49 0x0806c6f1 in call_cfunc (func=0x80d5780 <rb_ary_each>, recv=3084304464, len=17996607, argc=134686800, argv=0x0)
at eval.c:5409
#50 0x0805f5e9 in rb_call0 (klass=3085009848, recv=3084304464, id=3889, oid=134686688, argc=0, argv=0x0, body=0xb7e17f94,
flags=0) at eval.c:5617
#51 0x0805f8b0 in rb_call (klass=3085009848, recv=3084304464, mid=3889, argc=0, argv=0x0, scope=0) at eval.c:5790
#52 0x0805a0ae in rb_eval (self=3084305584, n=0x80727e0) at ruby.h:659
#53 0x08059457 in rb_eval (self=3084305584, n=0x80727e0) at eval.c:2976
#54 0x0805f153 in rb_call0 (klass=3084798840, recv=3084305584, id=5209, oid=134686688, argc=1, argv=0xbffbccd8,
body=0xb7de54d8, flags=0) at eval.c:5698
#55 0x0805f8b0 in rb_call (klass=3084798840, recv=3084305584, mid=5209, argc=1, argv=0xbffbccd8, scope=0) at eval.c:5790
#56 0x0805a0ae in rb_eval (self=3084305784, n=0x80727e0) at ruby.h:659
#57 0x0806525a in call_block (arg=0x1129b3f) at eval.c:8584
#58 0x08065155 in rb_block_pass (func=0x8065240 <call_block>, arg=3220952576, proc=3084295664) at eval.c:8523
#59 0x0806529b in block_pass (self=134686800, node=0x1129b3f) at eval.c:8593
#60 0x0805ad5a in rb_eval (self=3084305784, n=0x80727e0) at eval.c:2949
#61 0x0805d33a in rb_yield_0 (val=3084305584, self=3084305784, klass=4, flags=0, avalue=0) at eval.c:4795
#62 0x0805d9e9 in rb_yield (val=134686688) at eval.c:4876
#63 0x080d57bf in rb_ary_each (ary=3084305804) at array.c:1140
#64 0x0806c6f1 in call_cfunc (func=0x80d5780 <rb_ary_each>, recv=3084305804, len=17996607, argc=134686800, argv=0x0)
at eval.c:5409
#65 0x0805f5e9 in rb_call0 (klass=3085009848, recv=3084305804, id=3889, oid=134686688, argc=0, argv=0x0, body=0xb7e17f94,
flags=0) at eval.c:5617
---Type <return> to continue, or q <return> to quit---
#66 0x0805f8b0 in rb_call (klass=3085009848, recv=3084305804, mid=3889, argc=0, argv=0x0, scope=0) at eval.c:5790
#67 0x0805a0ae in rb_eval (self=3084305784, n=0x80727e0) at ruby.h:659
#68 0x08059457 in rb_eval (self=3084305784, n=0x80727e0) at eval.c:2976
#69 0x0805f153 in rb_call0 (klass=3084798840, recv=3084305784, id=5209, oid=134686688, argc=1, argv=0xbffbf2c8,
body=0xb7de54d8, flags=0) at eval.c:5698
#70 0x0805f8b0 in rb_call (klass=3084798840, recv=3084305784, mid=5209, argc=1, argv=0xbffbf2c8, scope=0) at eval.c:5790
#71 0x0805a0ae in rb_eval (self=3084301764, n=0x80727e0) at ruby.h:659
#72 0x08059457 in rb_eval (self=3084301764, n=0x80727e0) at eval.c:2976
#73 0x0805f153 in rb_call0 (klass=3084165024, recv=3084301764, id=17881, oid=134686688, argc=0, argv=0x0, body=0xb7d4b814,
flags=0) at eval.c:5698
#74 0x0805f8b0 in rb_call (klass=3084165024, recv=3084301764, mid=17881, argc=0, argv=0x0, scope=0) at eval.c:5790
#75 0x0805a0ae in rb_eval (self=3084305724, n=0x80727e0) at ruby.h:659
#76 0x0805f153 in rb_call0 (klass=3084236304, recv=3084305724, id=17769, oid=134686688, argc=0, argv=0x0, body=0xb7d6a598,
flags=10) at eval.c:5698
#77 0x0805f8b0 in rb_call (klass=3084236304, recv=3084305724, mid=17769, argc=0, argv=0x0, scope=2) at eval.c:5790
#78 0x0805a0ae in rb_eval (self=3084305724, n=0x80727e0) at ruby.h:659
#79 0x0805f153 in rb_call0 (klass=3084236304, recv=3084305724, id=5129, oid=134686688, argc=0, argv=0x0, body=0xb7d6afac,
flags=0) at eval.c:5698
#80 0x0805f8b0 in rb_call (klass=3084236304, recv=3084305724, mid=5129, argc=0, argv=0x0, scope=0) at eval.c:5790
#81 0x0805a0ae in rb_eval (self=3084236304, n=0x80727e0) at ruby.h:659
#82 0x0805f153 in rb_call0 (klass=3084235864, recv=3084236304, id=5209, oid=134686688, argc=2, argv=0xbffc1f98,
body=0xb7ddfed4, flags=0) at eval.c:5698
#83 0x0805f8b0 in rb_call (klass=3084235864, recv=3084236304, mid=5209, argc=2, argv=0xbffc1f98, scope=0) at eval.c:5790
#84 0x0805a0ae in rb_eval (self=3084831280, n=0x80727e0) at ruby.h:659
#85 0x08059f82 in rb_eval (self=3084831280, n=0x80727e0) at eval.c:3246
#86 0x0805f153 in rb_call0 (klass=3084779900, recv=3084831280, id=5209, oid=134686688, argc=0, argv=0x0, body=0xb7de03c0,
flags=0) at eval.c:5698
#87 0x0805f8b0 in rb_call (klass=3084779900, recv=3084831280, mid=5209, argc=0, argv=0x0, scope=0) at eval.c:5790
#88 0x0805a0ae in rb_eval (self=3084779900, n=0x80727e0) at ruby.h:659
#89 0x0805f153 in rb_call0 (klass=3084779880, recv=3084779900, id=5209, oid=134686688, argc=2, argv=0xbffc39b8,
body=0xb7de472c, flags=0) at eval.c:5698
#90 0x0805f8b0 in rb_call (klass=3084779880, recv=3084779900, mid=5209, argc=2, argv=0xbffc39b8, scope=0) at eval.c:5790
#91 0x0805a0ae in rb_eval (self=3085036048, n=0x80727e0) at ruby.h:659
#92 0x0805a3e8 in rb_eval (self=3085036048, n=0x80727e0) at ruby.h:683
#93 0x08056446 in ruby_exec_internal () at eval.c:1492
#94 0x08056466 in ruby_exec () at eval.c:1508
#95 0x080564b0 in ruby_run () at eval.c:1524
#96 0x080543de in main (argc=134686688, argv=0x80727e0, envp=0xbffc4ac4) at main.c:38
(gdb)
--
[田中 哲][たなか あきら][Tanaka Akira]