Ruby 3.5.0dev (2025-01-10 revision 5fab31b15e32622c4b71d1d347a41937e9f9c212)
main.c (5fab31b15e32622c4b71d1d347a41937e9f9c212)
1/**********************************************************************
2
3 main.c -
4
5 $Author$
6 created at: Fri Aug 19 13:19:58 JST 1994
7
8 Copyright (C) 1993-2007 Yukihiro Matsumoto
9
10**********************************************************************/
11
20#undef RUBY_EXPORT
21#include "ruby.h"
22#include "vm_debug.h"
23#include "internal/sanitizers.h"
24#ifdef HAVE_LOCALE_H
25#include <locale.h>
26#endif
27#if USE_MODULAR_GC
28#include "internal/gc.h"
29#endif
30
31#if defined RUBY_DEVEL && !defined RUBY_DEBUG_ENV
32# define RUBY_DEBUG_ENV 1
33#endif
34#if defined RUBY_DEBUG_ENV && !RUBY_DEBUG_ENV
35# undef RUBY_DEBUG_ENV
36#endif
37
38static int
39rb_main(int argc, char **argv)
40{
42 ruby_init();
43 return ruby_run_node(ruby_options(argc, argv));
44}
45
46#if defined(__wasm__) && !defined(__EMSCRIPTEN__)
47int rb_wasm_rt_start(int (main)(int argc, char **argv), int argc, char **argv);
48#define rb_main(argc, argv) rb_wasm_rt_start(rb_main, argc, argv)
49#endif
50
51#ifdef _WIN32
52#define main(argc, argv) w32_main(argc, argv)
53static int main(int argc, char **argv);
54int wmain(void) {return main(0, NULL);}
55#endif
56
57int
58main(int argc, char **argv)
59{
60#if defined(RUBY_DEBUG_ENV) || USE_RUBY_DEBUG_LOG
61 ruby_set_debug_option(getenv("RUBY_DEBUG"));
62#endif
63#ifdef HAVE_LOCALE_H
64 setlocale(LC_CTYPE, "");
65#endif
66
67 ruby_sysinit(&argc, &argv);
68 return rb_main(argc, argv);
69}
70
71#ifdef RUBY_ASAN_ENABLED
72/* Compile in the ASAN options Ruby needs, rather than relying on environment variables, so
73 * that even tests which fork ruby with a clean environment will run ASAN with the right
74 * settings */
75RUBY_SYMBOL_EXPORT_BEGIN
76const char *
77__asan_default_options(void)
78{
79 return "use_sigaltstack=0:detect_leaks=0";
80}
81RUBY_SYMBOL_EXPORT_END
82#endif
#define RUBY_INIT_STACK
A convenience macro to call ruby_init_stack().
void ruby_init(void)
Calls ruby_setup() and check error.
Definition eval.c:96
void ruby_sysinit(int *argc, char ***argv)
Initializes the process for libruby.
Definition ruby.c:3231