diff --git a/common.mk b/common.mk index 3000a4931984c4..2849287676cadb 100644 --- a/common.mk +++ b/common.mk @@ -19516,6 +19516,7 @@ version.$(OBJEXT): $(CCAN_DIR)/str/str.h version.$(OBJEXT): $(hdrdir)/ruby.h version.$(OBJEXT): $(hdrdir)/ruby/ruby.h version.$(OBJEXT): $(hdrdir)/ruby/version.h +version.$(OBJEXT): $(top_srcdir)/gc/gc.h version.$(OBJEXT): $(top_srcdir)/internal/array.h version.$(OBJEXT): $(top_srcdir)/internal/basic_operators.h version.$(OBJEXT): $(top_srcdir)/internal/cmdlineopt.h diff --git a/gc/gc.h b/gc/gc.h index 8fbc6111c0b23c..91efdd59f52b55 100644 --- a/gc/gc.h +++ b/gc/gc.h @@ -42,6 +42,7 @@ uint32_t rb_gc_get_shape(VALUE obj); void rb_gc_set_shape(VALUE obj, uint32_t shape_id); uint32_t rb_gc_rebuild_shape(VALUE obj, size_t heap_id); size_t rb_obj_memsize_of(VALUE obj); +const char * rb_gc_active_gc_name(void); RUBY_SYMBOL_EXPORT_END void rb_ractor_finish_marking(void); diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb index f82861b8ced83b..9bbff0e5b66ac9 100644 --- a/test/ruby/test_rubyoptions.rb +++ b/test/ruby/test_rubyoptions.rb @@ -176,7 +176,7 @@ def test_debug VERSION_PATTERN_WITH_RJIT = case RUBY_ENGINE when 'ruby' - /^ruby #{q[RUBY_VERSION]}(?:[p ]|dev|rc).*? \+RJIT (\+MN )?(\+PRISM )?\[#{q[RUBY_PLATFORM]}\]$/ + /^ruby #{q[RUBY_VERSION]}(?:[p ]|dev|rc).*? \+RJIT (\+MN )?(\+PRISM )?(\+MOD_GC)?(\[\w+\]\s)?\[#{q[RUBY_PLATFORM]}\]$/ else VERSION_PATTERN end @@ -307,6 +307,16 @@ def test_rjit_version end end + def test_enabled_gc + omit unless /linux|darwin/ =~ RUBY_PLATFORM + + if RbConfig::CONFIG['shared_gc_dir'].length > 0 + assert_match(/\+MOD_GC/, RUBY_DESCRIPTION) + else + assert_match(/^((?!\+MOD_GC(\[\w+\])?).)*$/, RUBY_DESCRIPTION) + end + end + def test_parser_flag assert_in_out_err(%w(--parser=prism -e) + ["puts :hi"], "", %w(hi), []) assert_in_out_err(%w(--parser=prism --dump=parsetree -e _=:hi), "", /"hi"/, []) diff --git a/version.c b/version.c index 416688644ae662..0f5ae2bf123f8f 100644 --- a/version.c +++ b/version.c @@ -16,6 +16,7 @@ #include "vm_core.h" #include "rjit.h" #include "yjit.h" +#include "gc/gc.h" #include #ifndef EXIT_SUCCESS @@ -61,6 +62,11 @@ const int ruby_api_version[] = { #else #define YJIT_DESCRIPTION " +YJIT" #endif +#if USE_SHARED_GC +#define GC_DESCRIPTION " +MOD_GC" +#else +#define GC_DESCRIPTION "" +#endif const char ruby_version[] = RUBY_VERSION; const char ruby_revision[] = RUBY_FULL_REVISION; const char ruby_release_date[] = RUBY_RELEASE_DATE; @@ -167,6 +173,11 @@ define_ruby_description(const char *const jit_opt) + rb_strlen_lit(YJIT_DESCRIPTION) + rb_strlen_lit(" +MN") + rb_strlen_lit(" +PRISM") +#if USE_SHARED_GC + + rb_strlen_lit(GC_DESCRIPTION) + + rb_strlen_lit(rb_gc_active_gc_name()) + + 2 +#endif ]; int n = ruby_description_opt_point; @@ -176,6 +187,14 @@ define_ruby_description(const char *const jit_opt) RUBY_ASSERT(n <= ruby_description_opt_point + (int)rb_strlen_lit(YJIT_DESCRIPTION)); if (ruby_mn_threads_enabled) append(" +MN"); if (rb_ruby_prism_p()) append(" +PRISM"); +#if USE_SHARED_GC + append(GC_DESCRIPTION); + if (getenv("RUBY_GC_LIBRARY")) { + append("["); + append(rb_gc_active_gc_name()); + append("]"); + } +#endif append(ruby_description + ruby_description_opt_point); # undef append