Refactor rb_shape_depth to take an ID rather than a pointer.

As well as `rb_shape_edges_count` and `rb_shape_memsize`.
This commit is contained in:
Jean Boussier 2025-05-08 18:20:35 +02:00
parent f8b3fc520f
commit e4f97ce387
Notes: git 2025-05-09 08:23:13 +00:00
4 changed files with 19 additions and 18 deletions

View file

@ -718,15 +718,13 @@ w_ivar_each(VALUE obj, st_index_t num, struct dump_call_arg *arg)
if (!num) return;
rb_ivar_foreach(obj, w_obj_each, (st_data_t)&ivarg);
if (shape_id != rb_shape_get_shape_id(arg->obj)) {
rb_shape_t * expected_shape = rb_shape_get_shape_by_id(shape_id);
rb_shape_t * actual_shape = rb_shape_get_shape(arg->obj);
shape_id_t actual_shape_id = rb_shape_get_shape_id(arg->obj);
if (shape_id != actual_shape_id) {
// If the shape tree got _shorter_ then we probably removed an IV
// If the shape tree got longer, then we probably added an IV.
// The exception message might not be accurate when someone adds and
// removes the same number of IVs, but they will still get an exception
if (rb_shape_depth(expected_shape) > rb_shape_depth(actual_shape)) {
if (rb_shape_depth(shape_id) > rb_shape_depth(rb_shape_get_shape_id(arg->obj))) {
rb_raise(rb_eRuntimeError, "instance variable removed from %"PRIsVALUE" instance",
CLASS_OF(arg->obj));
}