Ruby 3.3.5p100 (2024-09-03 revision ef084cc8f4958c1b6e4ead99136631bef6d8ddba)
version.c
1/**********************************************************************
2
3 version.c -
4
5 $Author$
6 created at: Thu Sep 30 20:08:01 JST 1993
7
8 Copyright (C) 1993-2007 Yukihiro Matsumoto
9
10**********************************************************************/
11
12#include "internal/cmdlineopt.h"
13#include "ruby/ruby.h"
14#include "version.h"
15#include "vm_core.h"
16#include "rjit.h"
17#include "yjit.h"
18#include <stdio.h>
19
20#ifndef EXIT_SUCCESS
21#define EXIT_SUCCESS 0
22#endif
23
24#ifdef RUBY_REVISION
25# if RUBY_PATCHLEVEL == -1
26# ifndef RUBY_BRANCH_NAME
27# define RUBY_BRANCH_NAME "master"
28# endif
29# define RUBY_REVISION_STR " "RUBY_BRANCH_NAME" "RUBY_REVISION
30# else
31# define RUBY_REVISION_STR " revision "RUBY_REVISION
32# endif
33#else
34# define RUBY_REVISION "HEAD"
35# define RUBY_REVISION_STR ""
36#endif
37#if !defined RUBY_RELEASE_DATETIME || RUBY_PATCHLEVEL != -1
38# undef RUBY_RELEASE_DATETIME
39# define RUBY_RELEASE_DATETIME RUBY_RELEASE_DATE
40#endif
41
42#define PRINT(type) puts(ruby_##type)
43#define MKSTR(type) rb_obj_freeze(rb_usascii_str_new_static(ruby_##type, sizeof(ruby_##type)-1))
44#define MKINT(name) INT2FIX(ruby_##name)
45
51#define RUBY_VERSION \
52 STRINGIZE(RUBY_VERSION_MAJOR) "." \
53 STRINGIZE(RUBY_VERSION_MINOR) "." \
54 STRINGIZE(RUBY_VERSION_TEENY) ""
55#ifndef RUBY_FULL_REVISION
56# define RUBY_FULL_REVISION RUBY_REVISION
57#endif
58#ifdef YJIT_SUPPORT
59#define YJIT_DESCRIPTION " +YJIT " STRINGIZE(YJIT_SUPPORT)
60#else
61#define YJIT_DESCRIPTION " +YJIT"
62#endif
63const char ruby_version[] = RUBY_VERSION;
64const char ruby_revision[] = RUBY_FULL_REVISION;
65const char ruby_release_date[] = RUBY_RELEASE_DATE;
66const char ruby_platform[] = RUBY_PLATFORM;
67const int ruby_patchlevel = RUBY_PATCHLEVEL;
68const char ruby_description[] =
69 "ruby " RUBY_VERSION RUBY_PATCHLEVEL_STR " "
70 "(" RUBY_RELEASE_DATETIME RUBY_REVISION_STR ") "
71 "[" RUBY_PLATFORM "]";
72static const int ruby_description_opt_point =
73 (int)(sizeof(ruby_description) - sizeof(" [" RUBY_PLATFORM "]"));
74
75const char ruby_copyright[] = "ruby - Copyright (C) "
76 RUBY_BIRTH_YEAR_STR "-" RUBY_RELEASE_YEAR_STR " "
78const char ruby_engine[] = "ruby";
79
80// Might change after initialization
81const char *rb_dynamic_description = ruby_description;
82
84void
85Init_version(void)
86{
87 enum {ruby_patchlevel = RUBY_PATCHLEVEL};
88 VALUE version = MKSTR(version);
89 VALUE ruby_engine_name = MKSTR(engine);
90 // MKSTR macro is a marker for fake.rb
91
92 /*
93 * The running version of ruby
94 */
95 rb_define_global_const("RUBY_VERSION", /* MKSTR(version) */ version);
96 /*
97 * The date this ruby was released
98 */
99 rb_define_global_const("RUBY_RELEASE_DATE", MKSTR(release_date));
100 /*
101 * The platform for this ruby
102 */
103 rb_define_global_const("RUBY_PLATFORM", MKSTR(platform));
104 /*
105 * The patchlevel for this ruby. If this is a development build of ruby
106 * the patchlevel will be -1
107 */
108 rb_define_global_const("RUBY_PATCHLEVEL", MKINT(patchlevel));
109 /*
110 * The GIT commit hash for this ruby.
111 */
112 rb_define_global_const("RUBY_REVISION", MKSTR(revision));
113 /*
114 * The copyright string for ruby
115 */
116 rb_define_global_const("RUBY_COPYRIGHT", MKSTR(copyright));
117 /*
118 * The engine or interpreter this ruby uses.
119 */
120 rb_define_global_const("RUBY_ENGINE", /* MKSTR(engine) */ ruby_engine_name);
121 ruby_set_script_name(ruby_engine_name);
122 /*
123 * The version of the engine or interpreter this ruby uses.
124 */
125 rb_define_global_const("RUBY_ENGINE_VERSION", /* MKSTR(version) */ version);
126
127 rb_provide("ruby2_keywords.rb");
128}
129
130#if USE_RJIT
131#define RJIT_OPTS_ON opt->rjit.on
132#else
133#define RJIT_OPTS_ON 0
134#endif
135
136#if USE_YJIT
137#define YJIT_OPTS_ON opt->yjit
138#else
139#define YJIT_OPTS_ON 0
140#endif
141
142int ruby_mn_threads_enabled;
143
144bool * rb_ruby_prism_ptr(void);
145
146static void
147define_ruby_description(const char *const jit_opt)
148{
149 static char desc[
150 sizeof(ruby_description)
151 + rb_strlen_lit(YJIT_DESCRIPTION)
152 + rb_strlen_lit(" +MN")
153 ];
154
155 const char *const threads_opt = ruby_mn_threads_enabled ? " +MN" : "";
156 const char *const parser_opt = (*rb_ruby_prism_ptr()) ? " +PRISM" : "";
157
158 int n = snprintf(desc, sizeof(desc),
159 "%.*s"
160 "%s" // jit_opt
161 "%s" // threads_opts
162 "%s" // parser_opt
163 "%s",
164 ruby_description_opt_point, ruby_description,
165 jit_opt,
166 threads_opt,
167 parser_opt,
168 ruby_description + ruby_description_opt_point);
169
170 VALUE description = rb_obj_freeze(rb_usascii_str_new_static(desc, n));
171 rb_dynamic_description = desc;
172
173 /*
174 * The full ruby version string, like <tt>ruby -v</tt> prints
175 */
176 rb_define_global_const("RUBY_DESCRIPTION", /* MKSTR(description) */ description);
177}
178
179void
180Init_ruby_description(ruby_cmdline_options_t *opt)
181{
182 const char *const jit_opt =
183 RJIT_OPTS_ON ? " +RJIT" :
184 YJIT_OPTS_ON ? YJIT_DESCRIPTION :
185 "";
186 define_ruby_description(jit_opt);
187}
188
189void
190ruby_set_yjit_description(void)
191{
192 rb_const_remove(rb_cObject, rb_intern("RUBY_DESCRIPTION"));
193 define_ruby_description(YJIT_DESCRIPTION);
194}
195
196void
198{
199 puts(rb_dynamic_description);
200
201#ifdef RUBY_LAST_COMMIT_TITLE
202 fputs("last_commit=" RUBY_LAST_COMMIT_TITLE, stdout);
203#endif
204#ifdef HAVE_MALLOC_CONF
205 if (malloc_conf) printf("malloc_conf=%s\n", malloc_conf);
206#endif
207 fflush(stdout);
208}
209
210void
212{
213 PRINT(copyright);
214 fflush(stdout);
215}
void ruby_set_script_name(VALUE name)
Identical to ruby_script(), except it takes the name as a Ruby String instance.
Definition ruby.c:2881
void ruby_show_copyright(void)
Prints the copyright notice of the CRuby interpreter to stdout.
Definition version.c:211
void ruby_show_version(void)
Prints the version information of the CRuby interpreter to stdout.
Definition version.c:197
void rb_provide(const char *feature)
Declares that the given feature is already provided by someone else.
Definition load.c:714
#define rb_strlen_lit(str)
Length of a string literal.
Definition string.h:1692
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...
Definition string.c:1003
VALUE rb_const_remove(VALUE space, ID name)
Identical to rb_mod_remove_const(), except it takes the name as ID instead of VALUE.
Definition variable.c:3244
void rb_define_global_const(const char *name, VALUE val)
Identical to rb_define_const(), except it defines that of "global", i.e.
Definition variable.c:3702
const int ruby_api_version[3]
API versions, in { major, minor, teeny } order.
Definition version.c:46
const char ruby_engine[]
This is just "ruby" for us.
Definition version.c:78
#define RUBY_API_VERSION_TEENY
Teeny version.
Definition version.h:76
const char ruby_platform[]
Target platform identifier, in a C string.
Definition version.c:66
const char ruby_version[]
Stringised version.
Definition version.c:63
#define RUBY_API_VERSION_MAJOR
Major version.
Definition version.h:64
#define RUBY_API_VERSION_MINOR
Minor version.
Definition version.h:70
#define RUBY_AUTHOR
Author of this project.
Definition version.h:32
const char ruby_copyright[]
Copyright notice.
Definition version.c:75
const char ruby_release_date[]
Date of release, in a C string.
Definition version.c:65
const int ruby_patchlevel
This is a monotonic increasing integer that describes specific "patch" level.
Definition version.c:67
const char ruby_description[]
This is what ruby -v prints to the standard error.
Definition version.c:68
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40