PageRenderTime 46ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/version.c

https://github.com/wanabe/ruby
C | 140 lines | 89 code | 12 blank | 39 comment | 5 complexity | acb278c50bf817d2ba0daab0b961395c MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0, 0BSD, Unlicense, GPL-2.0, BSD-3-Clause
  1. /**********************************************************************
  2. version.c -
  3. $Author$
  4. created at: Thu Sep 30 20:08:01 JST 1993
  5. Copyright (C) 1993-2007 Yukihiro Matsumoto
  6. **********************************************************************/
  7. #include "ruby/ruby.h"
  8. #include "version.h"
  9. #include "vm_core.h"
  10. #include "mjit.h"
  11. #include <stdio.h>
  12. #ifndef EXIT_SUCCESS
  13. #define EXIT_SUCCESS 0
  14. #endif
  15. #define PRINT(type) puts(ruby_##type)
  16. #define MKSTR(type) rb_obj_freeze(rb_usascii_str_new_static(ruby_##type, sizeof(ruby_##type)-1))
  17. #define MKINT(name) INT2FIX(ruby_##name)
  18. const int ruby_api_version[] = {
  19. RUBY_API_VERSION_MAJOR,
  20. RUBY_API_VERSION_MINOR,
  21. RUBY_API_VERSION_TEENY,
  22. };
  23. #define RUBY_VERSION \
  24. STRINGIZE(RUBY_VERSION_MAJOR) "." \
  25. STRINGIZE(RUBY_VERSION_MINOR) "." \
  26. STRINGIZE(RUBY_VERSION_TEENY) ""
  27. #ifndef RUBY_FULL_REVISION
  28. # define RUBY_FULL_REVISION RUBY_REVISION
  29. #endif
  30. const char ruby_version[] = RUBY_VERSION;
  31. const char ruby_revision[] = RUBY_FULL_REVISION;
  32. const char ruby_release_date[] = RUBY_RELEASE_DATE;
  33. const char ruby_platform[] = RUBY_PLATFORM;
  34. const int ruby_patchlevel = RUBY_PATCHLEVEL;
  35. const char ruby_description[] = RUBY_DESCRIPTION_WITH("");
  36. static const char ruby_description_with_jit[] = RUBY_DESCRIPTION_WITH(" +JIT");
  37. const char ruby_copyright[] = RUBY_COPYRIGHT;
  38. const char ruby_engine[] = "ruby";
  39. /*! Defines platform-depended Ruby-level constants */
  40. void
  41. Init_version(void)
  42. {
  43. enum {ruby_patchlevel = RUBY_PATCHLEVEL};
  44. VALUE version;
  45. VALUE ruby_engine_name;
  46. /*
  47. * The running version of ruby
  48. */
  49. rb_define_global_const("RUBY_VERSION", (version = MKSTR(version)));
  50. /*
  51. * The date this ruby was released
  52. */
  53. rb_define_global_const("RUBY_RELEASE_DATE", MKSTR(release_date));
  54. /*
  55. * The platform for this ruby
  56. */
  57. rb_define_global_const("RUBY_PLATFORM", MKSTR(platform));
  58. /*
  59. * The patchlevel for this ruby. If this is a development build of ruby
  60. * the patchlevel will be -1
  61. */
  62. rb_define_global_const("RUBY_PATCHLEVEL", MKINT(patchlevel));
  63. /*
  64. * The GIT commit hash for this ruby.
  65. */
  66. rb_define_global_const("RUBY_REVISION", MKSTR(revision));
  67. /*
  68. * The copyright string for ruby
  69. */
  70. rb_define_global_const("RUBY_COPYRIGHT", MKSTR(copyright));
  71. /*
  72. * The engine or interpreter this ruby uses.
  73. */
  74. rb_define_global_const("RUBY_ENGINE", ruby_engine_name = MKSTR(engine));
  75. ruby_set_script_name(ruby_engine_name);
  76. /*
  77. * The version of the engine or interpreter this ruby uses.
  78. */
  79. rb_define_global_const("RUBY_ENGINE_VERSION", (1 ? version : MKSTR(version)));
  80. rb_provide("ruby2_keywords.rb");
  81. }
  82. #if USE_MJIT
  83. #define MJIT_OPTS_ON mjit_opts.on
  84. #else
  85. #define MJIT_OPTS_ON 0
  86. #endif
  87. void
  88. Init_ruby_description(void)
  89. {
  90. VALUE description;
  91. if (MJIT_OPTS_ON) {
  92. description = MKSTR(description_with_jit);
  93. }
  94. else {
  95. description = MKSTR(description);
  96. }
  97. /*
  98. * The full ruby version string, like <tt>ruby -v</tt> prints
  99. */
  100. rb_define_global_const("RUBY_DESCRIPTION", /* MKSTR(description) */ description);
  101. }
  102. void
  103. ruby_show_version(void)
  104. {
  105. if (MJIT_OPTS_ON) {
  106. PRINT(description_with_jit);
  107. }
  108. else {
  109. PRINT(description);
  110. }
  111. #ifdef RUBY_LAST_COMMIT_TITLE
  112. fputs("last_commit=" RUBY_LAST_COMMIT_TITLE, stdout);
  113. #endif
  114. #ifdef HAVE_MALLOC_CONF
  115. if (malloc_conf) printf("malloc_conf=%s\n", malloc_conf);
  116. #endif
  117. fflush(stdout);
  118. }
  119. void
  120. ruby_show_copyright(void)
  121. {
  122. PRINT(copyright);
  123. fflush(stdout);
  124. }