12#include "internal/cmdlineopt.h"
13#include "internal/parse.h"
14#include "internal/gc.h"
27# if RUBY_PATCHLEVEL == -1
28# define RUBY_API_VERSION_NAME "master"
29# ifndef RUBY_BRANCH_NAME
30# define RUBY_BRANCH_NAME RUBY_API_VERSION_NAME
32# define RUBY_REVISION_STR " "RUBY_BRANCH_NAME" "RUBY_REVISION
34# define RUBY_REVISION_STR " revision "RUBY_REVISION
37# define RUBY_REVISION "HEAD"
38# define RUBY_REVISION_STR ""
40#ifndef RUBY_API_VERSION_NAME
41# define RUBY_API_VERSION_NAME RUBY_API_VERSION_STR
43#if !defined RUBY_RELEASE_DATETIME || RUBY_PATCHLEVEL != -1
44# undef RUBY_RELEASE_DATETIME
45# define RUBY_RELEASE_DATETIME RUBY_RELEASE_DATE
48#define PRINT(type) puts(ruby_##type)
49#define MKSTR(type) rb_obj_freeze(rb_usascii_str_new_static(ruby_##type, sizeof(ruby_##type)-1))
50#define MKINT(name) INT2FIX(ruby_##name)
52#define RUBY_API_VERSION_STR \
53 STRINGIZE(RUBY_API_VERSION_MAJOR) "." \
54 STRINGIZE(RUBY_API_VERSION_MINOR) "." \
62 STRINGIZE(RUBY_VERSION_MAJOR) "." \
63 STRINGIZE(RUBY_VERSION_MINOR) "." \
64 STRINGIZE(RUBY_VERSION_TEENY) ""
65#ifndef RUBY_FULL_REVISION
66# define RUBY_FULL_REVISION RUBY_REVISION
69#define YJIT_DESCRIPTION " +YJIT " STRINGIZE(YJIT_SUPPORT)
71#define YJIT_DESCRIPTION " +YJIT"
74#define ZJIT_DESCRIPTION " +ZJIT " STRINGIZE(ZJIT_SUPPORT)
76#define ZJIT_DESCRIPTION " +ZJIT"
79#define GC_DESCRIPTION " +GC"
81#define GC_DESCRIPTION ""
84const char ruby_revision[] = RUBY_FULL_REVISION;
88const char ruby_api_version_name[] = RUBY_API_VERSION_NAME;
90 "ruby " RUBY_VERSION RUBY_PATCHLEVEL_STR
" "
91 "(" RUBY_RELEASE_DATETIME RUBY_REVISION_STR
") "
92 "[" RUBY_PLATFORM
"]";
93static const int ruby_description_opt_point =
94 (int)(
sizeof(ruby_description) -
sizeof(
" [" RUBY_PLATFORM
"]"));
97 RUBY_BIRTH_YEAR_STR
"-" RUBY_RELEASE_YEAR_STR
" "
105define_ruby_const(
VALUE mod,
const char *name,
VALUE value,
bool toplevel)
111 rb_define_const(mod, name, value);
115#define rb_define_const(mod, name, value) \
116 define_ruby_const(mod, (mod == mRuby ? "RUBY_" name : name), value, (mod == mRuby))
119Init_Ruby_module(
void)
138 VALUE version = MKSTR(version);
139 VALUE ruby_engine_name = MKSTR(engine);
145 rb_define_const(mRuby,
"VERSION", version);
149 rb_define_const(mRuby,
"RELEASE_DATE", MKSTR(release_date));
153 rb_define_const(mRuby,
"PLATFORM", MKSTR(platform));
158 rb_define_const(mRuby,
"PATCHLEVEL", MKINT(patchlevel));
162 rb_define_const(mRuby,
"REVISION", MKSTR(revision));
166 rb_define_const(mRuby,
"COPYRIGHT", MKSTR(copyright));
170 rb_define_const(mRuby,
"ENGINE", ruby_engine_name);
175 rb_define_const(mRuby,
"ENGINE_VERSION", version);
181#define YJIT_OPTS_ON opt->yjit
183#define YJIT_OPTS_ON 0
187#define ZJIT_OPTS_ON opt->zjit
189#define ZJIT_OPTS_ON 0
192int ruby_mn_threads_enabled;
194#ifndef RB_DEFAULT_PARSER
195#define RB_DEFAULT_PARSER RB_DEFAULT_PARSER_PRISM
197static ruby_default_parser_enum default_parser = RB_DEFAULT_PARSER;
199ruby_default_parser_enum
200rb_ruby_default_parser(
void)
202 return default_parser;
206rb_ruby_default_parser_set(ruby_default_parser_enum parser)
208 default_parser = parser;
212define_ruby_description(
const char *
const jit_opt)
214#define JIT_DESCRIPTION YJIT_DESCRIPTION ZJIT_DESCRIPTION
226 + RB_GC_MAX_NAME_LEN + 3
231 int n = ruby_description_opt_point;
232 memcpy(desc, ruby_description, n);
233# define append(s) (n += (int)strlcpy(desc + n, s, sizeof(desc) - n))
234 if (*jit_opt) append(jit_opt);
236 if (ruby_mn_threads_enabled) append(
" +MN");
237 if (rb_ruby_prism_p()) append(
" +PRISM");
239 append(GC_DESCRIPTION);
240 if (rb_gc_modular_gc_loaded_p()) {
242 append(rb_gc_active_gc_name());
246 append(ruby_description + ruby_description_opt_point);
251 rb_dynamic_description = desc;
256 rb_define_const(mRuby,
"DESCRIPTION", description);
257#undef JIT_DESCRIPTION
263 const char *
const jit_opt =
264 YJIT_OPTS_ON ? YJIT_DESCRIPTION :
265 ZJIT_OPTS_ON ? ZJIT_DESCRIPTION :
267 define_ruby_description(jit_opt);
271ruby_set_yjit_description(
void)
276 define_ruby_description(YJIT_DESCRIPTION);
280ruby_set_zjit_description(
void)
285 define_ruby_description(ZJIT_DESCRIPTION);
291 puts(rb_dynamic_description);
293#ifdef RUBY_LAST_COMMIT_TITLE
294 fputs(
"last_commit=" RUBY_LAST_COMMIT_TITLE, stdout);
296#ifdef HAVE_MALLOC_CONF
297 if (malloc_conf) printf(
"malloc_conf=%s\n", malloc_conf);
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
Ruby-level global variables / constants, visible from C.
VALUE rb_define_module(const char *name)
Defines a top-level module.
void ruby_set_script_name(VALUE name)
Identical to ruby_script(), except it takes the name as a Ruby String instance.
VALUE rb_obj_freeze(VALUE obj)
Just calls rb_obj_freeze_inline() inside.
void ruby_show_copyright(void)
Prints the copyright notice of the CRuby interpreter to stdout.
void ruby_show_version(void)
Prints the version information of the CRuby interpreter to stdout.
void rb_provide(const char *feature)
Declares that the given feature is already provided by someone else.
#define rb_strlen_lit(str)
Length of a string literal.
VALUE rb_usascii_str_new_static(const char *ptr, long len)
Identical to rb_str_new_static(), except it generates a string of "US ASCII" encoding instead of "bin...
VALUE rb_path2class(const char *path)
Resolves a Q::W::E::R-style path string to the actual class it points.
VALUE rb_const_remove(VALUE space, ID name)
Identical to rb_mod_remove_const(), except it takes the name as ID instead of VALUE.
void rb_define_global_const(const char *name, VALUE val)
Identical to rb_define_const(), except it defines that of "global", i.e.
const int ruby_api_version[3]
API versions, in { major, minor, teeny } order.
const char ruby_engine[]
This is just "ruby" for us.
#define RUBY_API_VERSION_TEENY
Teeny version.
const char ruby_platform[]
Target platform identifier, in a C string.
const char ruby_version[]
Stringised version.
#define RUBY_API_VERSION_MAJOR
Major version.
#define RUBY_API_VERSION_MINOR
Minor version.
#define RUBY_AUTHOR
Author of this project.
const char ruby_copyright[]
Copyright notice.
const char ruby_release_date[]
Date of release, in a C string.
const int ruby_patchlevel
This is a monotonic increasing integer that describes specific "patch" level.
const char ruby_description[]
This is what ruby -v prints to the standard error.
uintptr_t VALUE
Type that represents a Ruby object.