[ruby/json] Use RB_TYPE_P
[ruby.git] / version.c
blobbb6c15fb7a66a2bb7cb16d5ddb10a50fcb83fc8b
1 /**********************************************************************
3 version.c -
5 $Author$
6 created at: Thu Sep 30 20:08:01 JST 1993
8 Copyright (C) 1993-2007 Yukihiro Matsumoto
10 **********************************************************************/
12 #include "internal/cmdlineopt.h"
13 #include "internal/parse.h"
14 #include "internal/gc.h"
15 #include "ruby/ruby.h"
16 #include "version.h"
17 #include "vm_core.h"
18 #include "yjit.h"
19 #include <stdio.h>
21 #ifndef EXIT_SUCCESS
22 #define EXIT_SUCCESS 0
23 #endif
25 #ifdef RUBY_REVISION
26 # if RUBY_PATCHLEVEL == -1
27 # ifndef RUBY_BRANCH_NAME
28 # define RUBY_BRANCH_NAME "master"
29 # endif
30 # define RUBY_REVISION_STR " "RUBY_BRANCH_NAME" "RUBY_REVISION
31 # else
32 # define RUBY_REVISION_STR " revision "RUBY_REVISION
33 # endif
34 #else
35 # define RUBY_REVISION "HEAD"
36 # define RUBY_REVISION_STR ""
37 #endif
38 #if !defined RUBY_RELEASE_DATETIME || RUBY_PATCHLEVEL != -1
39 # undef RUBY_RELEASE_DATETIME
40 # define RUBY_RELEASE_DATETIME RUBY_RELEASE_DATE
41 #endif
43 #define PRINT(type) puts(ruby_##type)
44 #define MKSTR(type) rb_obj_freeze(rb_usascii_str_new_static(ruby_##type, sizeof(ruby_##type)-1))
45 #define MKINT(name) INT2FIX(ruby_##name)
47 const int ruby_api_version[] = {
48 RUBY_API_VERSION_MAJOR,
49 RUBY_API_VERSION_MINOR,
50 RUBY_API_VERSION_TEENY,
52 #define RUBY_VERSION \
53 STRINGIZE(RUBY_VERSION_MAJOR) "." \
54 STRINGIZE(RUBY_VERSION_MINOR) "." \
55 STRINGIZE(RUBY_VERSION_TEENY) ""
56 #ifndef RUBY_FULL_REVISION
57 # define RUBY_FULL_REVISION RUBY_REVISION
58 #endif
59 #ifdef YJIT_SUPPORT
60 #define YJIT_DESCRIPTION " +YJIT " STRINGIZE(YJIT_SUPPORT)
61 #else
62 #define YJIT_DESCRIPTION " +YJIT"
63 #endif
64 #ifdef ZJIT_SUPPORT
65 #define ZJIT_DESCRIPTION " +ZJIT " STRINGIZE(ZJIT_SUPPORT)
66 #else
67 #define ZJIT_DESCRIPTION " +ZJIT"
68 #endif
69 #if USE_ZJIT
70 #define JIT_DESCRIPTION ZJIT_DESCRIPTION
71 #else
72 #define JIT_DESCRIPTION YJIT_DESCRIPTION
73 #endif
74 #if USE_MODULAR_GC
75 #define GC_DESCRIPTION " +GC"
76 #else
77 #define GC_DESCRIPTION ""
78 #endif
79 const char ruby_version[] = RUBY_VERSION;
80 const char ruby_revision[] = RUBY_FULL_REVISION;
81 const char ruby_release_date[] = RUBY_RELEASE_DATE;
82 const char ruby_platform[] = RUBY_PLATFORM;
83 const int ruby_patchlevel = RUBY_PATCHLEVEL;
84 const char ruby_description[] =
85 "ruby " RUBY_VERSION RUBY_PATCHLEVEL_STR " "
86 "(" RUBY_RELEASE_DATETIME RUBY_REVISION_STR ") "
87 "[" RUBY_PLATFORM "]";
88 static const int ruby_description_opt_point =
89 (int)(sizeof(ruby_description) - sizeof(" [" RUBY_PLATFORM "]"));
91 const char ruby_copyright[] = "ruby - Copyright (C) "
92 RUBY_BIRTH_YEAR_STR "-" RUBY_RELEASE_YEAR_STR " "
93 RUBY_AUTHOR;
94 const char ruby_engine[] = "ruby";
96 // Might change after initialization
97 const char *rb_dynamic_description = ruby_description;
99 static inline void
100 define_ruby_const(VALUE mod, const char *name, VALUE value, bool toplevel)
102 if (toplevel) {
103 rb_define_global_const(name, value);
104 name += rb_strlen_lit("RUBY_");
106 rb_define_const(mod, name, value);
109 /* RDoc needs rb_define_const */
110 #define rb_define_const(mod, name, value) \
111 define_ruby_const(mod, (mod == mRuby ? "RUBY_" name : name), value, (mod == mRuby))
113 /*! Defines platform-depended Ruby-level constants */
114 void
115 Init_version(void)
118 * The Ruby[rdoc-ref:Ruby] module that contains portable information among
119 * implementations.
121 * The constants defined here are aliased in the toplevel with
122 * +RUBY_+ prefix.
124 VALUE mRuby = rb_define_module("Ruby");
126 enum {ruby_patchlevel = RUBY_PATCHLEVEL};
127 VALUE version = MKSTR(version);
128 VALUE ruby_engine_name = MKSTR(engine);
129 // MKSTR macro is a marker for fake.rb
132 * The running version of ruby
134 rb_define_const(mRuby, "VERSION", /* MKSTR(version) */ version);
136 * The date this ruby was released
138 rb_define_const(mRuby, "RELEASE_DATE", MKSTR(release_date));
140 * The platform for this ruby
142 rb_define_const(mRuby, "PLATFORM", MKSTR(platform));
144 * The patchlevel for this ruby. If this is a development build of ruby
145 * the patchlevel will be -1
147 rb_define_const(mRuby, "PATCHLEVEL", MKINT(patchlevel));
149 * The GIT commit hash for this ruby.
151 rb_define_const(mRuby, "REVISION", MKSTR(revision));
153 * The copyright string for ruby
155 rb_define_const(mRuby, "COPYRIGHT", MKSTR(copyright));
157 * The engine or interpreter this ruby uses.
159 rb_define_const(mRuby, "ENGINE", /* MKSTR(engine) */ ruby_engine_name);
160 ruby_set_script_name(ruby_engine_name);
162 * The version of the engine or interpreter this ruby uses.
164 rb_define_const(mRuby, "ENGINE_VERSION", /* MKSTR(version) */ version);
166 rb_provide("ruby2_keywords.rb");
169 #if USE_YJIT
170 #define YJIT_OPTS_ON opt->yjit
171 #else
172 #define YJIT_OPTS_ON 0