Prevent objects from moving while iterating the heap
This iterator uses an st_table, but if objects move the references in the st table won't be updated. This patch just changes the st table to an identity hash.
This commit is contained in:
parent
c839168b11
commit
cdc4084b0a
Notes:
git
2020-10-07 08:22:26 +09:00
@ -25,6 +25,10 @@
|
|||||||
#include "ruby/st.h"
|
#include "ruby/st.h"
|
||||||
#include "symbol.h"
|
#include "symbol.h"
|
||||||
|
|
||||||
|
#undef rb_funcall
|
||||||
|
|
||||||
|
#include "ruby/ruby.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* ObjectSpace.memsize_of(obj) -> Integer
|
* ObjectSpace.memsize_of(obj) -> Integer
|
||||||
@ -707,7 +711,7 @@ iow_internal_object_id(VALUE self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct rof_data {
|
struct rof_data {
|
||||||
st_table *refs;
|
VALUE refs;
|
||||||
VALUE internals;
|
VALUE internals;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -723,7 +727,7 @@ reachable_object_from_i(VALUE obj, void *data_ptr)
|
|||||||
val = iow_newobj(obj);
|
val = iow_newobj(obj);
|
||||||
rb_ary_push(data->internals, val);
|
rb_ary_push(data->internals, val);
|
||||||
}
|
}
|
||||||
st_insert(data->refs, key, val);
|
rb_hash_aset(data->refs, key, val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -781,20 +785,18 @@ static VALUE
|
|||||||
reachable_objects_from(VALUE self, VALUE obj)
|
reachable_objects_from(VALUE self, VALUE obj)
|
||||||
{
|
{
|
||||||
if (rb_objspace_markable_object_p(obj)) {
|
if (rb_objspace_markable_object_p(obj)) {
|
||||||
VALUE ret = rb_ary_new();
|
|
||||||
struct rof_data data;
|
struct rof_data data;
|
||||||
|
|
||||||
if (rb_typeddata_is_kind_of(obj, &iow_data_type)) {
|
if (rb_typeddata_is_kind_of(obj, &iow_data_type)) {
|
||||||
obj = (VALUE)DATA_PTR(obj);
|
obj = (VALUE)DATA_PTR(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.refs = st_init_numtable();
|
data.refs = rb_ident_hash_new();
|
||||||
data.internals = rb_ary_new();
|
data.internals = rb_ary_new();
|
||||||
|
|
||||||
rb_objspace_reachable_objects_from(obj, reachable_object_from_i, &data);
|
rb_objspace_reachable_objects_from(obj, reachable_object_from_i, &data);
|
||||||
|
|
||||||
st_foreach(data.refs, collect_values, (st_data_t)ret);
|
return rb_funcall(data.refs, rb_intern("values"), 0);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return Qnil;
|
return Qnil;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user