diff options
author | Matt Valentine-House <[email protected]> | 2024-10-08 21:30:06 +0100 |
---|---|---|
committer | Matt Valentine-House <[email protected]> | 2024-11-14 10:46:36 +0000 |
commit | ee290c94a3dd0327f3407edb02272d37470edc95 (patch) | |
tree | 941b26392942b9c927876079826f7c4a7ea0e776 /gc.c | |
parent | fa10441981c89deec914ba243360b40c5aede6ed (diff) |
Include the currently active GC in RUBY_DESCRIPTION
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]
[Feature #20794]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/11872
Diffstat (limited to 'gc.c')
-rw-r--r-- | gc.c | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -562,6 +562,8 @@ rb_gc_guarded_ptr_val(volatile VALUE *ptr, VALUE val) static const char *obj_type_name(VALUE obj); #define RB_AMALGAMATED_DEFAULT_GC #include "gc/default.c" +static int external_gc_loaded = FALSE; + #if USE_SHARED_GC && !defined(HAVE_DLOPEN) # error "Shared GC requires dlopen" @@ -696,6 +698,7 @@ ruby_external_gc_init(void) fprintf(stderr, "ruby_external_gc_init: Shared library %s cannot be opened: %s\n", gc_so_path, dlerror()); exit(1); } + external_gc_loaded = TRUE; } rb_gc_function_map_t gc_functions; @@ -2767,10 +2770,26 @@ rb_gc_copy_attributes(VALUE dest, VALUE obj) rb_gc_impl_copy_attributes(rb_gc_get_objspace(), dest, obj); } +int +rb_gc_external_gc_loaded_p(void) { + return external_gc_loaded; +} + const char * rb_gc_active_gc_name(void) { - return rb_gc_impl_active_gc_name(); + const char *gc_name = rb_gc_impl_active_gc_name(); + if (strlen(gc_name) > RB_GC_MAX_NAME_LEN) { + char *truncated_gc_name = ruby_xmalloc(RB_GC_MAX_NAME_LEN + 1); + + rb_warn("GC module %s has a name larger than %d chars, it will be truncated\n", + gc_name, RB_GC_MAX_NAME_LEN); + + strncpy(truncated_gc_name, gc_name, RB_GC_MAX_NAME_LEN); + return (const char *)truncated_gc_name; + } + return gc_name; + } // TODO: rearchitect this function to work for a generic GC |