[Feature: trunk] rb_objspace_each_objects

[email protected]$G$9!%e(B

e$B!!e(BC e$B%l%Y%k$Ge(B ObjectSpace.each_object
e$BAjEv$N=hM}$r$9$k$?$a$Ne(B C API e$B$r:n$ke(B
e$B$N$O$I$&$G$7$g$&$+!%F05!$O!$e(B[ruby-dev:38584]
e$B$GDs0F$7$?5!G=$r!$e(Bgc.c e$B$K<je(B
e$B$rF~$l$:$K:n$k$?$a$G$9!%e(B

e$B!!%$%s%?!<%U%’%90F$G$9!%e(B

void rb_objspace_each_objects(
int (*func)(VALUE *start, VALUE *end, void *data),
void *data)

e$B!!e(BObjectSpace.each_object
e$B$H0c$$!$e(B1e$B$D$:$D%3!<%k%P%C%/4X?t$KEO$9$N$G$O$Je(B
e$B$/!$$"$k$^$H$^$C$?C10L$4$H$K2?EY$+%3!<%k%P%C%/4X?t$KEO$5$l$^$9!%HO0O$Oe(B
start e$B$+$ie(B end e$B$^$G!%EO$5$l$k%*%V%8%’%/%H$O!$e(Bfree
e$B$5$l$?e(B cell e$B$r4^$s$G$$e(B
[email protected]$,$"$j$^$9!%$3$N>l9g!$e(Bflags
e$B$r%A%’%C%/$9$kI,MW$,$"$j$^$9!%e(B

e$B!v$^[email protected]=>e$NM}M3$G$9!%e(B
e$B!!e(B1e$B$De([email protected]=Dc2<$,8+$i$l$^$7$?!%e(B

e$B!!<BAu$r0l1~$D$1$F$*$-$^$9!%$D$$$G$K!$e(Bos_obj_of()
e$B$r$3$l$G=q$-49$($F$_$^e(B
e$B$7$?!%e(B

e$B!ve(BST_CONTINUE e$B$_$?$$$J$N$r;H$C$F$7$^$C$?$s$G$9$,!$e(B
e$B!!$3$l$O9T57$,0-$$5$$,$9$k!%$I$&$9$k$Y$-!)e(B

e$B!!$$$+$,$G$7$g$&$+!%e(B

Index: gc.c

— gc.c (e$B%j%S%8%g%se(B 23682)
+++ gc.c (e$B:n6H%3%T!<e(B)
@@ -2383,13 +2523,13 @@ Init_heap(void)
init_heap(&rb_objspace);
}

-static VALUE
-os_obj_of(rb_objspace_t *objspace, VALUE of)
+void
+rb_objspace_each_objects(int (*func)(VALUE *start, VALUE *end, void *),
void *data)
{
size_t i;

  • size_t n = 0;
    RVALUE *membase = 0;
  • RVALUE *p, *pend;
  • RVALUE *pstart, *pend;

  • rb_objspace_t *objspace = &rb_objspace;
    volatile VALUE v;

    i = 0;
    @@ -2402,30 +2542,70 @@ os_obj_of(rb_objspace_t *objspace, VALUE
    break;
    membase = heaps[i].membase;

  • p = heaps[i].slot; pend = p + heaps[i].limit;
  • for (;p < pend; p++) {
  • pstart = heaps[i].slot;
  • pend = pstart + heaps[i].limit;
  • for (; pstart != pend; pstart++) {
  •  if (pstart->as.basic.flags) {
    
  • v = (VALUE )pstart; / acquire to save this object */
  • break;
  •  }
    
  • }
  • if (pstart != pend) {
  •  if ((*func)((VALUE *)pstart, (VALUE *)pend, data) != ST_CONTINUE) 
    

{

  • return;
  •  }
    
  • }
  • }
  • return;
    +}

+struct os_each_struct {

  • size_t num;
  • VALUE of;
    +};

+static int
+os_obj_of_i(VALUE *vstart, VALUE *vend, void *data)
+{

  • struct os_each_struct *oes = (struct os_each_struct *)data;
  • RVALUE *p, *pend;
  • VALUE v;
  • for (p = (RVALUE *)vstart, pend = (RVALUE *)vend; p != pend; p++) {
    if (p->as.basic.flags) {
    switch (BUILTIN_TYPE§) {
    case T_NONE:
    case T_ICLASS:
    case T_NODE:
    case T_ZOMBIE:
  •    continue;
    
  • break;
    case T_CLASS:
  •    if (FL_TEST(p, FL_SINGLETON)) continue;
    
  • if (FL_TEST(p, FL_SINGLETON))
  •  break;
     default:
    
  •    if (!p->as.basic.klass) continue;
    
  • if (!p->as.basic.klass) break;
    v = (VALUE)p;
  •    if (!of || rb_obj_is_kind_of(v, of)) {
    
  • if (!oes->of || rb_obj_is_kind_of(v, oes->of)) {
    rb_yield(v);
  •  n++;
    
  •    oes->num++;
       }
    
    }
    }
    }
  • return ST_CONTINUE;
    }
  • return SIZET2NUM(n);
    +static VALUE
    +os_obj_of(VALUE of)
    +{
  • struct os_each_struct oes;
  • oes.num = 0;
  • oes.of = of;
  • rb_objspace_each_objects(os_obj_of_i, &oes);
  • return SIZET2NUM(oes.num);
    }

/*
@@ -2474,7 +2654,7 @@ os_each_obj(int argc, VALUE *argv, VALUE
rb_scan_args(argc, argv, “01”, &of);
}
RETURN_ENUMERATOR(os, 1, &of);

  • return os_obj_of(&rb_objspace, of);
  • return os_obj_of(of);
    }

/*

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:38602] [Feature: trunk]
rb_objspace_each_objects”
on Sun, 14 Jun 2009 01:53:21 +0900, SASADA Koichi [email protected]
writes:

|e$B!!e(BC e$B%l%Y%k$Ge(B ObjectSpace.each_object e$BAjEv$N=hM}$r$9$k$?$a$Ne(B C API e$B$r:n$ke(B
|e$B$N$O$I$&$G$7$g$&$+!%F05!$O!$e(B[ruby-dev:38584] e$B$GDs0F$7$?5!G=$r!$e(Bgc.c e$B$K<je(B
|e$B$rF~$l$:$K:n$k$?$a$G$9!%e(B
|
|e$B!!%$%s%?!<%U%’%90F$G$9!%e(B
|
|void rb_objspace_each_objects(
| int (*func)(VALUE *start, VALUE *end, void *data),
| void data)
|
|e$B!!e(BObjectSpace.each_object e$B$H0c$$!$e(B1e$B$D$:$D%3!<%k%P%C%/4X?t$KEO$9$N$G$O$Je(B
|e$B$/!$$"$k$^$H$^$C$?C10L$4$H$K2?EY$+%3!<%k%P%C%/4X?t$KEO$5$l$^$9!%HO0O$Oe(B
|start e$B$+$ie(B end e$B$^$G!%EO$5$l$k%
%V%8%’%/%H$O!$e(Bfree e$B$5$l$?e(B cell e$B$r4^$s$G$$e(B
|[email protected]$,$"$j$^$9!%$3$N>l9g!$e(Bflags e$B$r%A%’%C%/$9$kI,MW$,$"$j$^$9!%e(B

e$B$H$$$&7|G0$,$"$j$^$9$,!"86B’E*$K$O;[email protected]$G$9!#e(B

|e$B!ve(BST_CONTINUE e$B$_$?$$$J$N$r;H$C$F$7$^$C$?$s$G$9$,!$e(B
|e$B!!$3$l$O9T57$,0-$$5$$,$9$k!%$I$&$9$k$Y$-!)e(B

ST_CONTINUEe$B$Oe(Bst_tablee$BMQ$G$9$+$i!"K\Mh$Oe(Bobject_eache$BMQ$NDj?t$re(B
e$BMQ0U$9$Y$-$G$7$g$&$M!#e(B

[email protected]$G$9!%e(B

Yukihiro M. wrote::

e$B!!$J$s$FL>A0$,$$$$$G$7$g$&$+$M!%e(B

e$B!!$=$&$G$7$?!%$G!$e(BVALUE
[email protected]$HB-$7$F$b<!$NNN0h$K$O9T$+$J$$$+$i!$3HD%%i%$%Ve(B
e$B%i%j8~$1$K$Oe(B struct RObject *
e$B$K$G$b$9$k$H$$$$$N$+$J$!!%e(BRVALUE e$B$re(B gc.c
e$B$+$ie(B ruby.h e$B$K;}$C$F9T$/$N$b0l0F$G$9$,e(B…e$B!%e(B

|e$B!ve(BST_CONTINUE e$B$_$?$$$J$N$r;H$C$F$7$^$C$?$s$G$9$,!$e(B
|e$B!!$3$l$O9T57$,0-$$5$$,$9$k!%$I$&$9$k$Y$-!)e(B

ST_CONTINUEe$B$Oe(Bst_tablee$BMQ$G$9$+$i!"K\Mh$Oe(Bobject_eache$BMQ$NDj?t$re(B
e$BMQ0U$9$Y$-$G$7$g$&$M!#e(B

e$B!!$o$+$j$^$7$?!%e(B

[email protected]$G$9!%e(B

SASADA Koichi wrote::

e$B!!$J$s$FL>A0$,$$$$$G$7$g$&$+$M!%e(B

e$B!!$A$g$C$H9M$($?$N$G$9$,!$$3$s$J$N$O$I$&$G$7$g$&$+!%e(B

void rb_objspace_walk_heaps(
enum objspace_walk_retval (*callback)(VALUE start, VALUE end,
size_t stride, void *data),
void *data);

e$B!!Nc$($P!$e(Bcallback e$BFb$G$Oe(B

for (v = start; v != end; v+= stride) {
if (RBASIC(v)->flags) {
// e$B$J$s$+$9$ke(B
}
}

e$B!!$3$s$J46$8$Ge(B
[email protected]$-$F$$$k%%V%8%’%/%H$rA4It2s$k$3$H$,$G$-$k!$$H$$$&%$%se(B
e$B%?!<%U%’!<%9$G$9!%$J$
!$e(Bfree cell
[email protected]$,$"$j$^$9!%e(B
walk_heaps [email protected]$H!$e(Bfree cell e$B4^$a$FEO$i$J$$$H$^$:$$$+$J$!!%e(B

[email protected]$G$9!%e(B

Yukihiro M. wrote::

(*callback)(VALUE values, size_t run, void data)

e$B$G$h$$$s$G$J$$$G$9$+$M!#!Ve(BVALUEe$B$Ke(Bstridee$B$rB-$9!W$H$$$&A`:n$,e(B
e$BIT0B$G$9!#e(B

e$B!!$3$l$O!$e(BRVALUE e$B$NG[Ns$G$"$ke(B heaps_slot
e$B$rD>@\EO$9$s$8$c$J$/$F!$0l2se(B
VALUE e$B$NG[Ns$Ke(B live object
e$B$r%3%T!<$7$FEO$9!$$H$$$&%$%s%?!<%U%’!<%9$Ge(B
e$B$7$g$&$+!%:#$N$H$3$m!$e(BRVALUE e$B$N%5%$%:$O!$e(Bgc.c
e$B0J30$+$i$O8+$l$J$$$h$&$Ke(B
e$B$J$C$F$$$^$9!%$=$l$r1#JC$9$k$?$a$Ne(B stride
e$B$H$$$&0z?t$K$J$C$F$$$^$9!%e(B

e$B!!$G!$$3$l$O%3%T!<$N%*!<%P%X%C%I$r9M$([email protected]$J$!!$$H;W$$$^$9!%$3$Ne(B
API
e$B$O!$B.$$$1$IFq$7$$%$%s%?!<%U%’!<%9$G<h$j07$$Cm0U!$$H$$$&[email protected]$H<e$$$Ge(B
e$B$7$g$&$+!%e(B

|e$B!!$3$s$J46$8$Ge(B [email protected]$-$F$$$k%%V%8%’%/%H$rA4It2s$k$3$H$,$G$-$k!$$H$$$&%$%se(B
|e$B%?!<%U%’!<%9$G$9!%$J$
!$e(Bfree cell [email protected]$,$"$j$^$9!%e(B
|walk_heaps [email protected]$H!$e(Bfree cell e$B4^$a$FEO$i$J$$$H$^$:$$$+$J$!!%e(B

free celle$B$OMW$i$J$$$s$8$c$J$$$G$9$+$M!#$"$H!“e(Bheape$B$H$$$&$N$Oe(B
Ruby GCe$B$N30$G$O0c$&0UL#$G$”$k$H$$$&e(Bakre$B$5$s$N;XE&$b$"$j$^$9$M!#e(B
objspace_walk_objectse$B$GNI$$$h$&$J5$$b$7$^$9!#e(B

e$B!!$3$A$i$O$=$l$G!%$A$J$_$K!$e(BRVALUE
e$B$NG[Ns$rD>@\EO$9$3$H$r9M$($F$$$?$Ne(B
e$B$G!$e(Bfree cell e$B$,F~$k!$$H$$$&[email protected]$C$?$s$G$9$,!%e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:38605] Re: [Feature: trunk]
rb_objspace_each_objects”
on Sun, 14 Jun 2009 12:30:55 +0900, SASADA Koichi [email protected]
writes:

|> e$B!!$J$s$FL>A0$,$$$$$G$7$g$&$+$M!%e(B
|
|e$B!!$A$g$C$H9M$($?$N$G$9$,!$$3$s$J$N$O$I$&$G$7$g$&$+!%e(B
|
|void rb_objspace_walk_heaps(
| enum objspace_walk_retval (*callback)(VALUE start, VALUE end,
| size_t stride, void *data),
| void *data);

e$B$3$Ne(Bcallbacke$B$G$9$,e(B

(*callback)(VALUE values, size_t run, void data)

e$B$G$h$$$s$G$J$$$G$9$+$M!#!Ve(BVALUEe$B$Ke(Bstridee$B$rB-$9!W$H$$$&A`:n$,e(B
e$BIT0B$G$9!#e(B

|e$B!!$3$s$J46$8$Ge(B [email protected]$-$F$$$k%%V%8%’%/%H$rA4It2s$k$3$H$,$G$-$k!$$H$$$&%$%se(B
|e$B%?!<%U%’!<%9$G$9!%$J$
!$e(Bfree cell [email protected]$,$"$j$^$9!%e(B
|walk_heaps [email protected]$H!$e(Bfree cell e$B4^$a$FEO$i$J$$$H$^$:$$$+$J$!!%e(B

free celle$B$OMW$i$J$$$s$8$c$J$$$G$9$+$M!#$"$H!“e(Bheape$B$H$$$&$N$Oe(B
Ruby
GCe$B$N30$G$O0c$&0UL#$G$”$k$H$$$&e(Bakre$B$5$s$N;XE&$b$"$j$^$9$M!#e(B
objspace_walk_objectse$B$GNI$$$h$&$J5$$b$7$^$9!#e(B

[email protected]$G$9!#e(B

At Tue, 16 Jun 2009 11:05:58 +0900,
SASADA Koichi wrote in [ruby-dev:38650]:

void
rb_objspace_each_objects(
enum objspace_walk_retval (*callback)(VALUE *start, VALUE *end,
size_t stride, void *data),
void *data0

e$B!!$3$s$J46$8!%e(B

VALUE*e$B$rEO$9$H$$$&$3$H$O0lEYe(BVALUEe$B$NG[Ns$r:n$k$o$1$G$9$+$i!"e(B
stridee$B$OITMW$G$7$g$&!#$b$C$H$b!"e(Bend-starte$B$,Bg$-$/$J$k$H!"0l;~G[e(B
e$BNs$r:n$k%3%9%H$H0l$D$:$De(Bcallbacke$B$9$k%3%9%H$H$I$A$i$,Bg$-$$$+$OHye(B
e$BL/$J5$$b$7$^$9$,!#e(B

[email protected]$G$9!%e(B

SASADA Koichi wrote::

e$B$J$C$F$$$^$9!%$=$l$r1#JC$9$k$?$a$Ne(B stride e$B$H$$$&0z?t$K$J$C$F$$$^$9!%e(B

e$B!!$G!$$3$l$O%3%T!<$N%*!<%P%X%C%I$r9M$([email protected]$J$!!$$H;W$$$^$9!%$3$Ne(B
API e$B$O!$B.$$$1$IFq$7$$%$%s%?!<%U%’!<%9$G<h$j07$$Cm0U!$$H$$$&[email protected]$H<e$$$Ge(B
e$B$7$g$&$+!%e(B

e$B!!K\7o!$$^$D$b$H$5$s$H%A%c%C%[email protected]$5$;$F$b$i$C$?$s$G$9$,!$e(B

e$B!&B.EYE*$JLdBj$,$"$k$N$OG’$a$k$N$Ge(B stride e$B$G$b$h$$e(B
e$B!&e(Bstart, end e$B$N7?$Oe(B VALUE e$B$h$j$Oe(B VALUE * e$B$Ke(B

e$B$H$$$&OC$K$J$j$^$7$?!%e(B

void
rb_objspace_each_objects(
enum objspace_walk_retval (*callback)(VALUE *start, VALUE *end,
size_t stride, void *data),
void *data0

e$B!!$3$s$J46$8!%e(B

e$B!!$H$j$"$($:!$Fq$7$$$N$OFq$7$$$N$G!$%3%a%s%H$K!$;H$&$J!$$H=q$$$F$*$-$^$9e(B
e$B!J>[email protected]@$H!K!%e(B

[email protected]$G$9!%e(B

Nobuyoshi N. wrote::

VALUE*e$B$rEO$9$H$$$&$3$H$O0lEYe(BVALUEe$B$NG[Ns$r:n$k$o$1$G$9$+$i!"e(B
stridee$B$OITMW$G$7$g$&!#$b$C$H$b!"e(Bend-starte$B$,Bg$-$/$J$k$H!"0l;~G[e(B
e$BNs$r:n$k%3%9%H$H0l$D$:$De(Bcallbacke$B$9$k%3%9%H$H$I$A$i$,Bg$-$$$+$OHye(B
e$BL/$J5$$b$7$^$9$,!#e(B

e$B!!4V0c$($?!$e(BVALUE * e$B$8$c$J$/$Fe(B void * e$B$G$7$?!%e(BVALUE
e$B$re(B void * e$B$KJQ$([email protected](B
e$B$1!%%3%T!<$OH/@8$7$^$;$s!%e(B

e$B%A%1%C%He(B #1623 e$B$,99?7$5$l$^$7$?!#e(B (by Yuki S.)

e$B%9%F!<%?%9e(B Opene$B$+$ie(BClosede$B$KJQ99e(B

applied in r23708.

http://redmine.ruby-lang.org/issues/show/1623

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs