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)
61 STRINGIZE(RUBY_VERSION_MAJOR) "." \
62 STRINGIZE(RUBY_VERSION_MINOR) "." \
63 STRINGIZE(RUBY_VERSION_TEENY) ""
64#ifndef RUBY_FULL_REVISION
65# define RUBY_FULL_REVISION RUBY_REVISION
68#define YJIT_DESCRIPTION " +YJIT " STRINGIZE(YJIT_SUPPORT)
70#define YJIT_DESCRIPTION " +YJIT"
73#define ZJIT_DESCRIPTION " +ZJIT " STRINGIZE(ZJIT_SUPPORT)
75#define ZJIT_DESCRIPTION " +ZJIT"
78#define GC_DESCRIPTION " +GC"
80#define GC_DESCRIPTION ""
83const char ruby_revision[] = RUBY_FULL_REVISION;
87const char ruby_api_version_name[] = RUBY_API_VERSION_NAME;
89 "ruby " RUBY_VERSION RUBY_PATCHLEVEL_STR
" "
90 "(" RUBY_RELEASE_DATETIME RUBY_REVISION_STR
") "
91 "[" RUBY_PLATFORM
"]";
92static const int ruby_description_opt_point =
93 (int)(
sizeof(ruby_description) -
sizeof(
" [" RUBY_PLATFORM
"]"));
96 RUBY_BIRTH_YEAR_STR
"-" RUBY_RELEASE_YEAR_STR
" "
104define_ruby_const(
VALUE mod,
const char *name,
VALUE value,
bool toplevel)
110 rb_define_const(mod, name, value);
114#define rb_define_const(mod, name, value) \
115 define_ruby_const(mod, (mod == mRuby ? "RUBY_" name : name), value, (mod == mRuby))
118Init_Ruby_module(
void)
137 VALUE version = MKSTR(version);
138 VALUE ruby_engine_name = MKSTR(engine);
144 rb_define_const(mRuby,
"VERSION", version);
148 rb_define_const(mRuby,
"RELEASE_DATE", MKSTR(release_date));
152 rb_define_const(mRuby,
"PLATFORM", MKSTR(platform));
157 rb_define_const(mRuby,
"PATCHLEVEL", MKINT(patchlevel));
161 rb_define_const(mRuby,
"REVISION", MKSTR(revision));
165 rb_define_const(mRuby,
"COPYRIGHT", MKSTR(copyright));
169 rb_define_const(mRuby,
"ENGINE", ruby_engine_name);
174 rb_define_const(mRuby,
"ENGINE_VERSION", version);
180#define YJIT_OPTS_ON opt->yjit
182#define YJIT_OPTS_ON 0
186#define ZJIT_OPTS_ON opt->zjit
188#define ZJIT_OPTS_ON 0
191int ruby_mn_threads_enabled;
193#ifndef RB_DEFAULT_PARSER
194#define RB_DEFAULT_PARSER RB_DEFAULT_PARSER_PRISM
196static ruby_default_parser_enum default_parser = RB_DEFAULT_PARSER;
198ruby_default_parser_enum
199rb_ruby_default_parser(
void)
201 return default_parser;
205rb_ruby_default_parser_set(ruby_default_parser_enum parser)
207 default_parser = parser;
211define_ruby_description(
const char *
const jit_opt)
213#define JIT_DESCRIPTION YJIT_DESCRIPTION ZJIT_DESCRIPTION
225 + RB_GC_MAX_NAME_LEN + 3
230 int n = ruby_description_opt_point;
231 memcpy(desc, ruby_description, n);
232# define append(s) (n += (int)strlcpy(desc + n, s, sizeof(desc) - n))
233 if (*jit_opt) append(jit_opt);
235 if (ruby_mn_threads_enabled) append(
" +MN");
236 if (rb_ruby_prism_p()) append(
" +PRISM");
238 append(GC_DESCRIPTION);
239 if (rb_gc_modular_gc_loaded_p()) {
241 append(rb_gc_active_gc_name());
245 append(ruby_description + ruby_description_opt_point);
250 rb_dynamic_description = desc;
255 rb_define_const(mRuby,
"DESCRIPTION", description);
256#undef JIT_DESCRIPTION
262 const char *
const jit_opt =
263 YJIT_OPTS_ON ? YJIT_DESCRIPTION :
264 ZJIT_OPTS_ON ? ZJIT_DESCRIPTION :
266 define_ruby_description(jit_opt);
270ruby_set_yjit_description(
void)
275 define_ruby_description(YJIT_DESCRIPTION);
279ruby_set_zjit_description(
void)
284 define_ruby_description(ZJIT_DESCRIPTION);
290 puts(rb_dynamic_description);
292#ifdef RUBY_LAST_COMMIT_TITLE
293 fputs(
"last_commit=" RUBY_LAST_COMMIT_TITLE, stdout);
295#ifdef HAVE_MALLOC_CONF
296 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.