Build rb_dynamic_description
at runtime
To avoid creating literals for all combinations.
This commit is contained in:
parent
55a0d2c63b
commit
f6e2f32a96
43
version.c
43
version.c
@ -39,11 +39,6 @@
|
|||||||
# define RUBY_RELEASE_DATETIME RUBY_RELEASE_DATE
|
# define RUBY_RELEASE_DATETIME RUBY_RELEASE_DATE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
# define RUBY_DESCRIPTION_WITH(opt) \
|
|
||||||
"ruby " RUBY_VERSION RUBY_PATCHLEVEL_STR " " \
|
|
||||||
"(" RUBY_RELEASE_DATETIME RUBY_REVISION_STR ")" opt " " \
|
|
||||||
"[" RUBY_PLATFORM "]"
|
|
||||||
|
|
||||||
#define PRINT(type) puts(ruby_##type)
|
#define PRINT(type) puts(ruby_##type)
|
||||||
#define MKSTR(type) rb_obj_freeze(rb_usascii_str_new_static(ruby_##type, sizeof(ruby_##type)-1))
|
#define MKSTR(type) rb_obj_freeze(rb_usascii_str_new_static(ruby_##type, sizeof(ruby_##type)-1))
|
||||||
#define MKINT(name) INT2FIX(ruby_##name)
|
#define MKINT(name) INT2FIX(ruby_##name)
|
||||||
@ -70,9 +65,13 @@ const char ruby_revision[] = RUBY_FULL_REVISION;
|
|||||||
const char ruby_release_date[] = RUBY_RELEASE_DATE;
|
const char ruby_release_date[] = RUBY_RELEASE_DATE;
|
||||||
const char ruby_platform[] = RUBY_PLATFORM;
|
const char ruby_platform[] = RUBY_PLATFORM;
|
||||||
const int ruby_patchlevel = RUBY_PATCHLEVEL;
|
const int ruby_patchlevel = RUBY_PATCHLEVEL;
|
||||||
const char ruby_description[] = RUBY_DESCRIPTION_WITH("");
|
const char ruby_description[] =
|
||||||
static const char ruby_description_with_rjit[] = RUBY_DESCRIPTION_WITH(" +RJIT");
|
"ruby " RUBY_VERSION RUBY_PATCHLEVEL_STR " "
|
||||||
static const char ruby_description_with_yjit[] = RUBY_DESCRIPTION_WITH(YJIT_DESCRIPTION);
|
"(" RUBY_RELEASE_DATETIME RUBY_REVISION_STR ") "
|
||||||
|
"[" RUBY_PLATFORM "]";
|
||||||
|
static const int ruby_description_opt_point =
|
||||||
|
(int)(sizeof(ruby_description) - sizeof(" [" RUBY_PLATFORM "]"));
|
||||||
|
|
||||||
const char ruby_copyright[] = "ruby - Copyright (C) "
|
const char ruby_copyright[] = "ruby - Copyright (C) "
|
||||||
RUBY_BIRTH_YEAR_STR "-" RUBY_RELEASE_YEAR_STR " "
|
RUBY_BIRTH_YEAR_STR "-" RUBY_RELEASE_YEAR_STR " "
|
||||||
RUBY_AUTHOR;
|
RUBY_AUTHOR;
|
||||||
@ -143,19 +142,23 @@ Init_version(void)
|
|||||||
void
|
void
|
||||||
Init_ruby_description(ruby_cmdline_options_t *opt)
|
Init_ruby_description(ruby_cmdline_options_t *opt)
|
||||||
{
|
{
|
||||||
VALUE description;
|
static char desc[
|
||||||
|
sizeof(ruby_description)
|
||||||
|
+ rb_strlen_lit(YJIT_DESCRIPTION)
|
||||||
|
];
|
||||||
|
|
||||||
if (RJIT_OPTS_ON) {
|
const char *const jit_opt =
|
||||||
rb_dynamic_description = ruby_description_with_rjit;
|
RJIT_OPTS_ON ? " +RJIT" :
|
||||||
description = MKSTR(description_with_rjit);
|
YJIT_OPTS_ON ? YJIT_DESCRIPTION :
|
||||||
}
|
"";
|
||||||
else if (YJIT_OPTS_ON) {
|
|
||||||
rb_dynamic_description = ruby_description_with_yjit;
|
int n = snprintf(desc, sizeof(desc), "%.*s" /* jit_opt */"%s" "%s",
|
||||||
description = MKSTR(description_with_yjit);
|
ruby_description_opt_point, ruby_description,
|
||||||
}
|
jit_opt,
|
||||||
else {
|
ruby_description + ruby_description_opt_point);
|
||||||
description = MKSTR(description);
|
|
||||||
}
|
VALUE description = rb_obj_freeze(rb_usascii_str_new_static(desc, n));
|
||||||
|
rb_dynamic_description = desc;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The full ruby version string, like <tt>ruby -v</tt> prints
|
* The full ruby version string, like <tt>ruby -v</tt> prints
|
||||||
|
Loading…
x
Reference in New Issue
Block a user