diff options
author | Jean Boussier <[email protected]> | 2025-05-15 12:14:53 +0200 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2025-05-15 16:06:52 +0200 |
commit | 60ffb714d251878753ebf66e68149311c728cac6 (patch) | |
tree | d9cb46a81af9313ad6faa6faa559fd1c4c7c2c66 | |
parent | ed632cd0bacc710b03809c903a978d3fa2cfedfe (diff) |
Ensure shape_id is never used on T_IMEMO
It doesn't make sense to set ivars or anything shape
related on a T_IMEMO.
Co-Authored-By: John Hawthorn <[email protected]>
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/13347
-rw-r--r-- | eval.c | 6 | ||||
-rw-r--r-- | ext/objspace/objspace_dump.c | 8 | ||||
-rw-r--r-- | gc.c | 11 | ||||
-rw-r--r-- | iseq.c | 1 | ||||
-rw-r--r-- | shape.h | 3 |
5 files changed, 23 insertions, 6 deletions
@@ -529,10 +529,14 @@ exc_setup_message(const rb_execution_context_t *ec, VALUE mesg, VALUE *cause) rb_exc_check_circular_cause(*cause); #else VALUE c = *cause; - while (!NIL_P(c = rb_attr_get(c, id_cause))) { + while (!NIL_P(c)) { if (c == mesg) { rb_raise(rb_eArgError, "circular causes"); } + if (THROW_DATA_P(c)) { + break; + } + c = rb_attr_get(c, id_cause); } #endif } diff --git a/ext/objspace/objspace_dump.c b/ext/objspace/objspace_dump.c index ec7a21417e..814b939995 100644 --- a/ext/objspace/objspace_dump.c +++ b/ext/objspace/objspace_dump.c @@ -414,9 +414,11 @@ dump_object(VALUE obj, struct dump_config *dc) dump_append(dc, obj_type(obj)); dump_append(dc, "\""); - size_t shape_id = rb_obj_shape_id(obj); - dump_append(dc, ", \"shape_id\":"); - dump_append_sizet(dc, shape_id); + if (BUILTIN_TYPE(obj) != T_IMEMO) { + size_t shape_id = rb_obj_shape_id(obj); + dump_append(dc, ", \"shape_id\":"); + dump_append_sizet(dc, shape_id); + } dump_append(dc, ", \"slot_size\":"); dump_append_sizet(dc, dc->cur_page_slot_size); @@ -1934,6 +1934,9 @@ object_id(VALUE obj) // in different namespaces, so we cannot store the object id // in fields. return class_object_id(obj); + case T_IMEMO: + rb_bug("T_IMEMO can't have an object_id"); + break; default: break; } @@ -1960,6 +1963,8 @@ build_id2ref_i(VALUE obj, void *data) st_insert(id2ref_tbl, RCLASS(obj)->object_id, obj); } break; + case T_IMEMO: + break; default: if (rb_shape_obj_has_id(obj)) { st_insert(id2ref_tbl, rb_obj_id(obj), obj); @@ -2007,6 +2012,10 @@ object_id_to_ref(void *objspace_ptr, VALUE object_id) static inline void obj_free_object_id(VALUE obj) { + if (RB_BUILTIN_TYPE(obj) == T_IMEMO) { + return; + } + VALUE obj_id = 0; if (RB_UNLIKELY(id2ref_tbl)) { switch (BUILTIN_TYPE(obj)) { @@ -2210,7 +2219,7 @@ rb_obj_id(VALUE obj) bool rb_obj_id_p(VALUE obj) { - return rb_shape_obj_has_id(obj); + return !RB_TYPE_P(obj, T_IMEMO) && rb_shape_obj_has_id(obj); } static enum rb_id_table_iterator_result @@ -1530,7 +1530,6 @@ iseqw_new(const rb_iseq_t *iseq) /* cache a wrapper object */ RB_OBJ_WRITE((VALUE)iseq, &iseq->wrapper, obj); - RB_OBJ_FREEZE((VALUE)iseq); return obj; } @@ -94,12 +94,15 @@ static inline shape_id_t get_shape_id_from_flags(VALUE obj) { RUBY_ASSERT(!RB_SPECIAL_CONST_P(obj)); + RUBY_ASSERT(!RB_TYPE_P(obj, T_IMEMO)); return (shape_id_t)((RBASIC(obj)->flags) >> SHAPE_FLAG_SHIFT); } static inline void set_shape_id_in_flags(VALUE obj, shape_id_t shape_id) { + RUBY_ASSERT(!RB_SPECIAL_CONST_P(obj)); + RUBY_ASSERT(!RB_TYPE_P(obj, T_IMEMO)); // Ractors are occupying the upper 32 bits of flags, but only in debug mode // Object shapes are occupying top bits RBASIC(obj)->flags &= SHAPE_FLAG_MASK; |