From 8a475d15d6aec3618d075b66541b4bae663beac9 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Mon, 31 Mar 2025 12:48:56 +0200 Subject: [PATCH] Implement `dcompact` for Time objects --- time.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/time.c b/time.c index 811007a9d8..1b02cf4259 100644 --- a/time.c +++ b/time.c @@ -1890,23 +1890,38 @@ static void time_mark(void *ptr) { struct time_object *tobj = ptr; - if (!FIXWV_P(tobj->timew)) - rb_gc_mark(w2v(tobj->timew)); - rb_gc_mark(tobj->vtm.year); - rb_gc_mark(tobj->vtm.subsecx); - rb_gc_mark(tobj->vtm.utc_offset); - rb_gc_mark(tobj->vtm.zone); + if (!FIXWV_P(tobj->timew)) { + rb_gc_mark_movable(WIDEVAL_GET(tobj->timew)); + } + rb_gc_mark_movable(tobj->vtm.year); + rb_gc_mark_movable(tobj->vtm.subsecx); + rb_gc_mark_movable(tobj->vtm.utc_offset); + rb_gc_mark_movable(tobj->vtm.zone); +} + +static void +time_compact(void *ptr) +{ + struct time_object *tobj = ptr; + if (!FIXWV_P(tobj->timew)) { + WIDEVAL_GET(tobj->timew) = rb_gc_location(WIDEVAL_GET(tobj->timew)); + } + + tobj->vtm.year = rb_gc_location(tobj->vtm.year); + tobj->vtm.subsecx = rb_gc_location(tobj->vtm.subsecx); + tobj->vtm.utc_offset = rb_gc_location(tobj->vtm.utc_offset); + tobj->vtm.zone = rb_gc_location(tobj->vtm.zone); } static const rb_data_type_t time_data_type = { - "time", - { - time_mark, - RUBY_TYPED_DEFAULT_FREE, - NULL, // No external memory to report, + .wrap_struct_name = "time", + .function = { + .dmark = time_mark, + .dfree = RUBY_TYPED_DEFAULT_FREE, + .dsize = NULL, + .dcompact = time_compact, }, - 0, 0, - (RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_FROZEN_SHAREABLE | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE), + .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_FROZEN_SHAREABLE | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE, }; static VALUE