diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-09-29 11:10:46 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-09-29 11:10:46 +0000 |
commit | 71d110252507b2f720743b930628c971c3201198 (patch) | |
tree | 253a7ff21430d5fa50ae501dbe564b060ac7d6c7 /gc.c | |
parent | b2658a7604bf7dc9602b9ed4182247d0ef6cfe8f (diff) | |
download | ruby-71d110252507b2f720743b930628c971c3201198.tar.gz |
* 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
Diffstat (limited to 'gc.c')
-rw-r--r-- | gc.c | 24 |
1 files changed, 20 insertions, 4 deletions
@@ -3094,6 +3094,15 @@ rb_gc(void) } 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) { struct heaps_slot *slot = objspace->heap.sweep_slots; @@ -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; |