diff options
author | Jean Boussier <[email protected]> | 2025-03-31 12:48:56 +0200 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2025-03-31 16:56:29 +0200 |
commit | 8a475d15d6aec3618d075b66541b4bae663beac9 (patch) | |
tree | c8b6a89f422ffd853f9cfeeb7d82e3a5482a0541 /time.c | |
parent | 7db0e07134c9ff9e1da090053041b670f3206de4 (diff) |
Implement `dcompact` for Time objects
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/13019
Diffstat (limited to 'time.c')
-rw-r--r-- | time.c | 41 |
1 files changed, 28 insertions, 13 deletions
@@ -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 |