Skip to content

Commit

Permalink
Include the currently active GC in RUBY_DESCRIPTION
Browse files Browse the repository at this point in the history
This will add +MOD_GC to the version string and Ruby description when
Ruby is compiled with shared gc support.

When shared GC support is compiled in and a GC module has been loaded
using RUBY_GC_LIBRARY, the version string will include the name of
the currently active GC as reported by the rb_gc_active_gc_name function
in the form

+MOD_GC[gc_name]
  • Loading branch information
eightbitraptor committed Oct 9, 2024
1 parent 445d107 commit 9cb6931
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions gc/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions test/ruby/test_rubyoptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ def test_rjit_version
end
end

def test_enabled_gc
if RbConfig::CONFIG['shared_gc_dir'].length > 0
assert_match(/\+MOD_GC/, RUBY_DESCRIPTION)
else
assert_match(/^((?!\+MOD_GC).)*$/, 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"/, [])
Expand Down
15 changes: 15 additions & 0 deletions version.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "vm_core.h"
#include "rjit.h"
#include "yjit.h"
#include "gc/gc.h"
#include <stdio.h>

#ifndef EXIT_SUCCESS
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -167,6 +173,7 @@ define_ruby_description(const char *const jit_opt)
+ rb_strlen_lit(YJIT_DESCRIPTION)
+ rb_strlen_lit(" +MN")
+ rb_strlen_lit(" +PRISM")
+ rb_strlen_lit(GC_DESCRIPTION)
];

int n = ruby_description_opt_point;
Expand All @@ -176,6 +183,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");
#ifdef 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

Expand Down

0 comments on commit 9cb6931

Please sign in to comment.