Ruby  2.7.1p83(2020-03-31revisiona0c7c23c9cec0d0ffcba012279cd652d28ad5bf3)
version.c
Go to the documentation of this file.
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 <stdio.h>
17 
18 #ifndef EXIT_SUCCESS
19 #define EXIT_SUCCESS 0
20 #endif
21 
22 #define PRINT(type) puts(ruby_##type)
23 #define MKSTR(type) rb_obj_freeze(rb_usascii_str_new_static(ruby_##type, sizeof(ruby_##type)-1))
24 #define MKINT(name) INT2FIX(ruby_##name)
25 
26 const int ruby_api_version[] = {
30 };
31 #define RUBY_VERSION \
32  STRINGIZE(RUBY_VERSION_MAJOR) "." \
33  STRINGIZE(RUBY_VERSION_MINOR) "." \
34  STRINGIZE(RUBY_VERSION_TEENY) ""
35 #ifndef RUBY_FULL_REVISION
36 # define RUBY_FULL_REVISION RUBY_REVISION
37 #endif
38 const char ruby_version[] = RUBY_VERSION;
44 static const char ruby_description_with_jit[] = RUBY_DESCRIPTION_WITH(" +JIT");
46 const char ruby_engine[] = "ruby";
47 
49 void
51 {
53  VALUE version;
54  VALUE ruby_engine_name;
55  /*
56  * The running version of ruby
57  */
58  rb_define_global_const("RUBY_VERSION", (version = MKSTR(version)));
59  /*
60  * The date this ruby was released
61  */
62  rb_define_global_const("RUBY_RELEASE_DATE", MKSTR(release_date));
63  /*
64  * The platform for this ruby
65  */
66  rb_define_global_const("RUBY_PLATFORM", MKSTR(platform));
67  /*
68  * The patchlevel for this ruby. If this is a development build of ruby
69  * the patchlevel will be -1
70  */
71  rb_define_global_const("RUBY_PATCHLEVEL", MKINT(patchlevel));
72  /*
73  * The GIT commit hash for this ruby.
74  */
75  rb_define_global_const("RUBY_REVISION", MKSTR(revision));
76  /*
77  * The copyright string for ruby
78  */
79  rb_define_global_const("RUBY_COPYRIGHT", MKSTR(copyright));
80  /*
81  * The engine or interpreter this ruby uses.
82  */
83  rb_define_global_const("RUBY_ENGINE", ruby_engine_name = MKSTR(engine));
84  ruby_set_script_name(ruby_engine_name);
85  /*
86  * The version of the engine or interpreter this ruby uses.
87  */
88  rb_define_global_const("RUBY_ENGINE_VERSION", (1 ? version : MKSTR(version)));
89 
90  rb_provide("ruby2_keywords.rb");
91 }
92 
93 #if USE_MJIT
94 #define MJIT_OPTS_ON mjit_opts.on
95 #else
96 #define MJIT_OPTS_ON 0
97 #endif
98 
99 void
101 {
102  VALUE description;
103 
104  if (MJIT_OPTS_ON) {
105  description = MKSTR(description_with_jit);
106  }
107  else {
108  description = MKSTR(description);
109  }
110 
111  /*
112  * The full ruby version string, like <tt>ruby -v</tt> prints
113  */
114  rb_define_global_const("RUBY_DESCRIPTION", /* MKSTR(description) */ description);
115 }
116 
118 void
120 {
121  if (MJIT_OPTS_ON) {
122  PRINT(description_with_jit);
123  }
124  else {
125  PRINT(description);
126  }
127 #ifdef RUBY_LAST_COMMIT_TITLE
128  fputs("last_commit=" RUBY_LAST_COMMIT_TITLE, stdout);
129 #endif
130 #ifdef HAVE_MALLOC_CONF
131  if (malloc_conf) printf("malloc_conf=%s\n", malloc_conf);
132 #endif
133  fflush(stdout);
134 }
135 
137 void
139 {
140  PRINT(copyright);
141  fflush(stdout);
142 }
RUBY_VERSION
#define RUBY_VERSION
Definition: version.c:31
stdout
#define stdout
Definition: rb_mjit_min_header-2.7.1.h:1484
RUBY_API_VERSION_MAJOR
#define RUBY_API_VERSION_MAJOR
Definition: version.h:33
ruby_engine
const char ruby_engine[]
Definition: version.c:46
ruby_show_version
void ruby_show_version(void)
Prints the version information of the CRuby interpreter to stdout.
Definition: version.c:119
ruby_version
const char ruby_version[]
Definition: version.c:38
PRINT
#define PRINT(type)
Definition: version.c:22
MKINT
#define MKINT(name)
Definition: version.c:24
ruby_api_version
const int ruby_api_version[]
Definition: version.c:26
VALUE
unsigned long VALUE
Definition: ruby.h:102
RUBY_FULL_REVISION
#define RUBY_FULL_REVISION
Definition: version.c:36
RUBY_DESCRIPTION_WITH
#define RUBY_DESCRIPTION_WITH(opt)
Definition: version.h:67
MKSTR
#define MKSTR(type)
Definition: version.c:23
fputs
int fputs(const char *__restrict, FILE *__restrict)
RUBY_RELEASE_DATE
#define RUBY_RELEASE_DATE
Definition: version.h:4
version.h
ruby.h
RUBY_API_VERSION_TEENY
#define RUBY_API_VERSION_TEENY
Definition: version.h:35
RUBY_COPYRIGHT
#define RUBY_COPYRIGHT
Definition: version.h:73
RUBY_API_VERSION_MINOR
#define RUBY_API_VERSION_MINOR
Definition: version.h:34
Init_ruby_description
void Init_ruby_description(void)
Definition: version.c:100
mjit.h
ruby_show_copyright
void ruby_show_copyright(void)
Prints the copyright notice of the CRuby interpreter to stdout.
Definition: version.c:138
vm_core.h
ruby_set_script_name
void ruby_set_script_name(VALUE name)
Sets the current script name to this value.
Definition: ruby.c:2290
MJIT_OPTS_ON
#define MJIT_OPTS_ON
Definition: version.c:96
RUBY_PLATFORM
#define RUBY_PLATFORM
Definition: defines.h:460
rb_provide
void rb_provide(const char *)
Definition: load.c:563
rb_define_global_const
void rb_define_global_const(const char *, VALUE)
Definition: variable.c:2892
Init_version
void Init_version(void)
Defines platform-depended Ruby-level constants.
Definition: version.c:50
ruby_copyright
const char ruby_copyright[]
Definition: version.c:45
RUBY_PATCHLEVEL
#define RUBY_PATCHLEVEL
Definition: version.h:5
ruby_description
const char ruby_description[]
Definition: version.c:43
printf
int int int printf(const char *__restrict,...) __attribute__((__format__(__printf__
ruby_patchlevel
const int ruby_patchlevel
Definition: version.c:42
ruby_release_date
const char ruby_release_date[]
Definition: version.c:40
ruby_revision
const char ruby_revision[]
Definition: version.c:39
fflush
int fflush(FILE *)
ruby_platform
const char ruby_platform[]
Definition: version.c:41