mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* gc.c (is_id_value, is_live_object): extract from id2ref().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b2658a7604
commit
71d1102525
2 changed files with 23 additions and 5 deletions
|
@ -1,4 +1,6 @@
|
|||
Thu Sep 29 20:09:42 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
Thu Sep 29 20:10:42 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* gc.c (is_id_value, is_live_object): extract from id2ref().
|
||||
|
||||
* gc.c (run_finalizer): use object instead of object id.
|
||||
|
||||
|
|
24
gc.c
24
gc.c
|
@ -3093,6 +3093,15 @@ rb_gc(void)
|
|||
free_unused_heaps(objspace);
|
||||
}
|
||||
|
||||
static inline int
|
||||
is_id_value(rb_objspace_t *objspace, VALUE ptr)
|
||||
{
|
||||
if (!is_pointer_to_heap(objspace, (void *)ptr)) return FALSE;
|
||||
if (BUILTIN_TYPE(ptr) > T_FIXNUM) return FALSE;
|
||||
if (BUILTIN_TYPE(ptr) == T_ICLASS) return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static inline int
|
||||
is_dead_object(rb_objspace_t *objspace, VALUE ptr)
|
||||
{
|
||||
|
@ -3107,6 +3116,15 @@ is_dead_object(rb_objspace_t *objspace, VALUE ptr)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static inline int
|
||||
is_live_object(rb_objspace_t *objspace, VALUE ptr)
|
||||
{
|
||||
if (BUILTIN_TYPE(ptr) == 0) return FALSE;
|
||||
if (RBASIC(ptr)->klass == 0) return FALSE;
|
||||
if (is_dead_object(objspace, ptr)) return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* ObjectSpace._id2ref(object_id) -> an_object
|
||||
|
@ -3149,12 +3167,10 @@ id2ref(VALUE obj, VALUE objid)
|
|||
return ID2SYM(symid);
|
||||
}
|
||||
|
||||
if (!is_pointer_to_heap(objspace, (void *)ptr) ||
|
||||
BUILTIN_TYPE(ptr) > T_FIXNUM || BUILTIN_TYPE(ptr) == T_ICLASS) {
|
||||
if (!is_id_value(objspace, ptr)) {
|
||||
rb_raise(rb_eRangeError, "%p is not id value", p0);
|
||||
}
|
||||
if (BUILTIN_TYPE(ptr) == 0 || RBASIC(ptr)->klass == 0 ||
|
||||
is_dead_object(objspace, ptr)) {
|
||||
if (!is_live_object(objspace, ptr)) {
|
||||
rb_raise(rb_eRangeError, "%p is recycled object", p0);
|
||||
}
|
||||
return (VALUE)ptr;
|
||||
|
|
Loading…
Add table
Reference in a new issue