>>>>> "z" == zdennis  <zdennis / mktec.com> writes:

z> Attempting to apply patch to array.c from 1.8.4 I get:

 Well here a debugging session if you want to try to understand what it do

 I put my comments in /* ... */

(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /i/home/msys/decoux/ruby/ruby-1.8.4/ruby b.rb
187
before

Breakpoint 2, rb_eval (self=3085161320, n=0xb7e3dcdc) at eval.c:3711
3711		result = rb_ary_new();
(gdb)

 /* first breakpoint in rb_eval() (NODE_ZARRAY) */

(gdb) p &result
$97 = (volatile VALUE *) 0xbffff220
(gdb) c
Continuing.

Breakpoint 9, rb_ary_push (ary=3085161280, item=3085161220) at array.c:403
403	    rb_ary_store(ary, RARRAY(ary)->len, item);

 /* second breakpoint in rb_ary_push() */

(gdb) printf "%p\n", 0xbffff220-2452
0xbfffe88c
(gdb) printf "%p\n", *(0xbffff220-2452)
(nil)

 /* don't ask me why I use the magic value 2452 :-) */
 /* ruby has nothing at this address */

(gdb) s
rb_ary_store (ary=3085161280, idx=0, val=0) at array.c:352
352	    if (idx < 0) {
(gdb) printf "%p\n", *(0xbffff220-2452)
0xb7e3d340
(gdb) p *(struct RArray *)0xb7e3d340
$98 = {basic = {flags = 9, klass = 3085202720}, len = 0, aux = {capa = 16, shared = 16}, ptr = 0x812af28}
(gdb) 

 /* now the address (0xbffff220-2452) make reference to the Array */

 /* now I remove the breakpoint to wait it in garbage_collect() */

(gdb) c
Continuing.
check now
853640
Breakpoint 4, gc_mark_children (ptr=3085161280, lev=1) at gc.c:920
920		    VALUE *ptr = obj->as.array.ptr;
(gdb) up
#1  0x0806f02b in mark_locations_array (x=0xbfffe88c, n=1432) at gc.c:626
626		    gc_mark(v, 0);
(gdb) printf "%p\n", 0xbffff220-2452
0xbfffe88c
(gdb) 

 /* 
    ruby is marking the stack and in the stack it has found something
    at (0xbffff220-2452) == 0xbfffe88c : this is the location where the array
    was stored when it was in rb_ary_store() and this location was never
    cleaned nor replaced by another value and ruby logically mark the
    array. This is why it can't remove it
 */



Guy Decoux