Ruby  3.1.4p223 (2023-03-30 revision HEAD)
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 "ruby/ruby.h"
13 #include "version.h"
14 #include "vm_core.h"
15 #include "mjit.h"
16 #include "yjit.h"
17 #include <stdio.h>
18 
19 #ifndef EXIT_SUCCESS
20 #define EXIT_SUCCESS 0
21 #endif
22 
23 #define PRINT(type) puts(ruby_##type)
24 #define MKSTR(type) rb_obj_freeze(rb_usascii_str_new_static(ruby_##type, sizeof(ruby_##type)-1))
25 #define MKINT(name) INT2FIX(ruby_##name)
26 
27 const int ruby_api_version[] = {
31 };
32 #define RUBY_VERSION \
33  STRINGIZE(RUBY_VERSION_MAJOR) "." \
34  STRINGIZE(RUBY_VERSION_MINOR) "." \
35  STRINGIZE(RUBY_VERSION_TEENY) ""
36 #ifndef RUBY_FULL_REVISION
37 # define RUBY_FULL_REVISION RUBY_REVISION
38 #endif
39 const char ruby_version[] = RUBY_VERSION;
40 const char ruby_revision[] = RUBY_FULL_REVISION;
41 const char ruby_release_date[] = RUBY_RELEASE_DATE;
42 const char ruby_platform[] = RUBY_PLATFORM;
43 const int ruby_patchlevel = RUBY_PATCHLEVEL;
44 const char ruby_description[] = RUBY_DESCRIPTION_WITH("");
45 static const char ruby_description_with_mjit[] = RUBY_DESCRIPTION_WITH(" +MJIT");
46 static const char ruby_description_with_yjit[] = RUBY_DESCRIPTION_WITH(" +YJIT");
47 const char ruby_copyright[] = RUBY_COPYRIGHT;
48 const char ruby_engine[] = "ruby";
49 
51 void
52 Init_version(void)
53 {
54  enum {ruby_patchlevel = RUBY_PATCHLEVEL};
55  VALUE version;
56  VALUE ruby_engine_name;
57  /*
58  * The running version of ruby
59  */
60  rb_define_global_const("RUBY_VERSION", (version = MKSTR(version)));
61  /*
62  * The date this ruby was released
63  */
64  rb_define_global_const("RUBY_RELEASE_DATE", MKSTR(release_date));
65  /*
66  * The platform for this ruby
67  */
68  rb_define_global_const("RUBY_PLATFORM", MKSTR(platform));
69  /*
70  * The patchlevel for this ruby. If this is a development build of ruby
71  * the patchlevel will be -1
72  */
73  rb_define_global_const("RUBY_PATCHLEVEL", MKINT(patchlevel));
74  /*
75  * The GIT commit hash for this ruby.
76  */
77  rb_define_global_const("RUBY_REVISION", MKSTR(revision));
78  /*
79  * The copyright string for ruby
80  */
81  rb_define_global_const("RUBY_COPYRIGHT", MKSTR(copyright));
82  /*
83  * The engine or interpreter this ruby uses.
84  */
85  rb_define_global_const("RUBY_ENGINE", ruby_engine_name = MKSTR(engine));
86  ruby_set_script_name(ruby_engine_name);
87  /*
88  * The version of the engine or interpreter this ruby uses.
89  */
90  rb_define_global_const("RUBY_ENGINE_VERSION", (1 ? version : MKSTR(version)));
91 
92  rb_provide("ruby2_keywords.rb");
93 }
94 
95 #if USE_MJIT
96 #define MJIT_OPTS_ON mjit_opts.on
97 #else
98 #define MJIT_OPTS_ON 0
99 #endif
100 
101 void
102 Init_ruby_description(void)
103 {
104  VALUE description;
105 
106  if (MJIT_OPTS_ON) {
107  description = MKSTR(description_with_mjit);
108  }
109  else if (rb_yjit_enabled_p()) {
110  description = MKSTR(description_with_yjit);
111  }
112  else {
113  description = MKSTR(description);
114  }
115 
116  /*
117  * The full ruby version string, like <tt>ruby -v</tt> prints
118  */
119  rb_define_global_const("RUBY_DESCRIPTION", /* MKSTR(description) */ description);
120 }
121 
122 void
124 {
125  if (MJIT_OPTS_ON) {
126  PRINT(description_with_mjit);
127  }
128  else if (rb_yjit_enabled_p()) {
129  PRINT(description_with_yjit);
130  }
131  else {
132  PRINT(description);
133  }
134 
135 #ifdef RUBY_LAST_COMMIT_TITLE
136  fputs("last_commit=" RUBY_LAST_COMMIT_TITLE, stdout);
137 #endif
138 #ifdef HAVE_MALLOC_CONF
139  if (malloc_conf) printf("malloc_conf=%s\n", malloc_conf);
140 #endif
141  fflush(stdout);
142 }
143 
144 void
146 {
147  PRINT(copyright);
148  fflush(stdout);
149 }
void ruby_set_script_name(VALUE name)
Identical to ruby_script(), except it takes the name as a Ruby String instance.
Definition: ruby.c:2613
const char ruby_description[]
This is what ruby -v prints to the standard error.
Definition: version.c:44
void ruby_show_copyright(void)
Prints the copyright notice of the CRuby interpreter to stdout.
Definition: version.c:145
void ruby_show_version(void)
Prints the version information of the CRuby interpreter to stdout.
Definition: version.c:123
void rb_provide(const char *feature)
Declares that the given feature is already provided by someone else.
Definition: load.c:638
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:3265
const int ruby_api_version[3]
API versions, in { major, minor, teeny } order.
Definition: version.c:27
const char ruby_engine[]
This is just "ruby" for us.
Definition: version.c:48
#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:42
const char ruby_version[]
Stringised version.
Definition: version.c:39
#define RUBY_API_VERSION_MAJOR
Major version.
Definition: version.h:64
#define RUBY_API_VERSION_MINOR
Minor version.
Definition: version.h:70
const char ruby_copyright[]
Copyright notice.
Definition: version.c:47
const char ruby_release_date[]
Date of release, in a C string.
Definition: version.c:41
const int ruby_patchlevel
This is a monotonic increasing integer that describes specific "patch" level.
Definition: version.c:43
uintptr_t VALUE
Type that represents a Ruby object.
Definition: value.h:40