Ruby
2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)
|
Go to the documentation of this file.
16 #include <sys/cygwin.h>
25 #include <sys/types.h>
29 #include <sys/pstat.h>
31 #if defined(LOAD_RELATIVE) && defined(HAVE_DLADDR)
38 #if defined(HAVE_FCNTL_H)
40 #elif defined(HAVE_SYS_FCNTL_H)
41 #include <sys/fcntl.h>
43 #ifdef HAVE_SYS_PARAM_H
44 # include <sys/param.h>
47 # define MAXPATHLEN 1024
50 # define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
63 #ifndef DISABLE_RUBYGEMS
64 # define DISABLE_RUBYGEMS 0
67 #define DEFAULT_RUBYGEMS_ENABLED "disabled"
69 #define DEFAULT_RUBYGEMS_ENABLED "enabled"
75 #define FEATURE_BIT(bit) (1U << feature_##bit)
76 #define EACH_FEATURES(X, SEP) \
83 X(frozen_string_literal) \
87 #define EACH_DEBUG_FEATURES(X, SEP) \
88 X(frozen_string_literal) \
90 #define AMBIGUOUS_FEATURE_NAMES 0
91 #define DEFINE_FEATURE(bit) feature_##bit
92 #define DEFINE_DEBUG_FEATURE(bit) feature_debug_##bit
101 #define DEBUG_BIT(bit) (1U << feature_debug_##bit)
103 #define DUMP_BIT(bit) (1U << dump_##bit)
104 #define DEFINE_DUMP(bit) dump_##bit
105 #define EACH_DUMPS(X, SEP) \
120 X(parsetree_with_comment) \
140 rb_feature_set_to(
ruby_features_t *feat,
unsigned int bit_mask,
unsigned int bit_set)
142 feat->
mask |= bit_mask;
143 feat->
set = (feat->
set & ~bit_mask) | bit_set;
146 #define FEATURE_SET_TO(feat, bit_mask, bit_set) \
147 rb_feature_set_to(&(feat), bit_mask, bit_set)
148 #define FEATURE_SET(feat, bits) FEATURE_SET_TO(feat, bits, bits)
149 #define FEATURE_SET_RESTORE(feat, save) FEATURE_SET_TO(feat, (save).mask, (save).set & (save).mask)
150 #define FEATURE_SET_P(feat, bits) ((feat).set & (bits))
182 #define src_encoding_index GET_VM()->src_encoding_index
209 #ifdef MJIT_FORCE_ENABLE
217 static VALUE open_load_file(
VALUE fname_v,
int *xflag);
219 #define forbid_setid(s) forbid_setid((s), opt)
227 show_usage_line(
const char *
str,
unsigned int namelen,
unsigned int secondlen,
int help)
229 const unsigned int w = 16;
230 const int wrap = help && namelen + secondlen - 1 > w;
231 printf(
" %.*s%-*.*s%-*s%s\n", namelen-1,
str,
232 (wrap ? 0 : w - namelen + 1),
233 (help ? secondlen-1 : 0),
str + namelen,
234 (wrap ? w + 3 : 0), (wrap ?
"\n" :
""),
235 str + namelen + secondlen);
239 usage(
const char *
name,
int help)
246 unsigned short namelen, secondlen;
248 #define M(shortopt, longopt, desc) { \
249 shortopt " " longopt " " desc, \
250 (unsigned short)sizeof(shortopt), \
251 (unsigned short)sizeof(longopt), \
253 static const struct message usage_msg[] = {
254 M(
"-0[octal]",
"",
"specify record separator (\\0, if no argument)"),
255 M(
"-a",
"",
"autosplit mode with -n or -p (splits $_ into $F)"),
256 M(
"-c",
"",
"check syntax only"),
257 M(
"-Cdirectory",
"",
"cd to directory before executing your script"),
258 M(
"-d",
", --debug",
"set debugging flags (set $DEBUG to true)"),
259 M(
"-e 'command'",
"",
"one line of script. Several -e's allowed. Omit [programfile]"),
260 M(
"-Eex[:in]",
", --encoding=ex[:in]",
"specify the default external and internal character encodings"),
261 M(
"-Fpattern",
"",
"split() pattern for autosplit (-a)"),
262 M(
"-i[extension]",
"",
"edit ARGV files in place (make backup if extension supplied)"),
263 M(
"-Idirectory",
"",
"specify $LOAD_PATH directory (may be used more than once)"),
264 M(
"-l",
"",
"enable line ending processing"),
265 M(
"-n",
"",
"assume 'while gets(); ... end' loop around your script"),
266 M(
"-p",
"",
"assume loop like -n but print line also like sed"),
267 M(
"-rlibrary",
"",
"require the library before executing your script"),
268 M(
"-s",
"",
"enable some switch parsing for switches after script name"),
269 M(
"-S",
"",
"look for the script using PATH environment variable"),
270 M(
"-v",
"",
"print the version number, then turn on verbose mode"),
271 M(
"-w",
"",
"turn warnings on for your script"),
272 M(
"-W[level=2|:category]",
"",
"set warning level; 0=silence, 1=medium, 2=verbose"),
273 M(
"-x[directory]",
"",
"strip off text before #!ruby line and perhaps cd to directory"),
274 M(
"--jit",
"",
"enable JIT with default options (experimental)"),
275 M(
"--jit-[option]",
"",
"enable JIT with an option (experimental)"),
276 M(
"-h",
"",
"show this message, --help for more info"),
278 static const struct message help_msg[] = {
279 M(
"--copyright",
"",
"print the copyright"),
280 M(
"--dump={insns|parsetree|...}[,...]",
"",
281 "dump debug information. see below for available dump list"),
282 M(
"--enable={gems|rubyopt|...}[,...]",
", --disable={gems|rubyopt|...}[,...]",
283 "enable or disable features. see below for available features"),
284 M(
"--external-encoding=encoding",
", --internal-encoding=encoding",
285 "specify the default external or internal character encoding"),
286 M(
"--verbose",
"",
"turn on verbose mode and disable script from stdin"),
287 M(
"--version",
"",
"print the version number, then exit"),
288 M(
"--help",
"",
"show this message, -h for short message"),
290 static const struct message dumps[] = {
291 M(
"insns",
"",
"instruction sequences"),
292 M(
"yydebug",
"",
"yydebug of yacc parser generator"),
293 M(
"parsetree",
"",
"AST"),
294 M(
"parsetree_with_comment",
"",
"AST with comments"),
296 static const struct message features[] = {
299 M(
"rubyopt",
"",
"RUBYOPT environment variable (default: enabled)"),
300 M(
"frozen-string-literal",
"",
"freeze all string literals (default: disabled)"),
301 M(
"jit",
"",
"JIT compiler (default: disabled)"),
303 static const struct message warn_categories[] = {
304 M(
"deprecated",
"",
"deprecated features"),
305 M(
"experimental",
"",
"experimental features"),
308 M(
"--jit-warnings",
"",
"Enable printing JIT warnings"),
309 M(
"--jit-debug",
"",
"Enable JIT debugging (very slow), or add cflags if specified"),
310 M(
"--jit-wait",
"",
"Wait until JIT compilation finishes every time (for testing)"),
311 M(
"--jit-save-temps",
"",
"Save JIT temporary files in $TMP or /tmp (for testing)"),
312 M(
"--jit-verbose=num",
"",
"Print JIT logs of level num or less to stderr (default: 0)"),
313 M(
"--jit-max-cache=num",
"",
"Max number of methods to be JIT-ed in a cache (default: 100)"),
314 M(
"--jit-min-calls=num",
"",
"Number of calls to trigger JIT (for testing, default: 10000)"),
317 const int num =
numberof(usage_msg) - (help ? 1 : 0);
318 #define SHOW(m) show_usage_line((m).str, (m).namelen, (m).secondlen, help)
320 printf(
"Usage: %s [switches] [--] [programfile] [arguments]\n",
name);
321 for (
i = 0;
i < num; ++
i)
334 puts(
"Warning categories:");
336 SHOW(warn_categories[
i]);
337 puts(
"JIT options (experimental):");
342 #define rubylib_path_new rb_str_new
356 for (s = p; *s && *s != sep; s =
CharNext(s));
376 for (s = p; *s && *s !=
';'; s =
CharNext(s));
388 #ifdef HAVE_CYGWIN_CONV_PATH
389 #define CONV_TO_POSIX_PATH(p, lib) \
390 cygwin_conv_path(CCP_WIN_A_TO_POSIX|CCP_RELATIVE, (p), (lib), sizeof(lib))
392 # error no cygwin_conv_path
394 if (CONV_TO_POSIX_PATH(p, rubylib) == 0)
396 push_include(p, filter);
402 #define push_include push_include_cygwin
410 push_include(
path, filter);
437 if (*p ==
'.' && p[1] ==
'/')
449 #if defined _WIN32 || defined __CYGWIN__
450 static HMODULE libruby;
453 DllMain(HINSTANCE dll,
DWORD reason, LPVOID reserved)
455 if (reason == DLL_PROCESS_ATTACH)
461 rb_libruby_handle(
void)
467 translit_char_bin(
char *p,
int from,
int to)
470 if ((
unsigned char)*p == from)
485 # define IF_UTF8_PATH(t, f) t
487 # define IF_UTF8_PATH(t, f) f
499 # define str_conv_enc(str, from, to) (str)
504 #if defined(LOAD_RELATIVE)
506 runtime_libruby_path(
void)
508 #if defined _WIN32 || defined __CYGWIN__
516 ret = GetModuleFileNameW(libruby, wlibpath,
len),
522 if (!ret || ret >
len)
rb_fatal(
"failed to get module file name");
523 #if defined __CYGWIN__
525 const int win_to_posix = CCP_WIN_W_TO_POSIX | CCP_RELATIVE;
526 size_t newsize = cygwin_conv_path(win_to_posix, wlibpath, 0, 0);
527 if (!newsize)
rb_fatal(
"failed to convert module path to cygwin");
530 if (cygwin_conv_path(win_to_posix, wlibpath, libpath, newsize)) {
538 if (wlibpath[
i] ==
L'\\') {
544 len = WideCharToMultiByte(CP_UTF8, 0, wlibpath, ret,
NULL, 0,
NULL,
NULL);
547 WideCharToMultiByte(CP_UTF8, 0, wlibpath, ret, libpath,
len,
NULL,
NULL);
551 #elif defined(HAVE_DLADDR)
554 const void* addr = (
void *)(
VALUE)expand_include_path;
556 if (!dladdr((
void *)addr, &dli)) {
560 else if (origarg.argc > 0 && origarg.argv && dli.dli_fname == origarg.argv[0]) {
572 # error relative load path is not supported on this platform.
577 #define INITIAL_LOAD_PATH_MARK rb_intern_const("@gem_prelude_index")
584 VALUE load_path, archlibdir = 0;
585 ID id_initial_load_path_mark;
587 #if defined LOAD_RELATIVE
588 #if !defined ENABLE_MULTIARCH
589 # define RUBY_ARCH_PATH ""
590 #elif defined RUBY_ARCH
591 # define RUBY_ARCH_PATH "/"RUBY_ARCH
593 # define RUBY_ARCH_PATH "/"RUBY_PLATFORM
600 sopath = runtime_libruby_path();
605 static const char libdir[] =
"/"
606 #ifdef LIBDIR_BASENAME
614 static const char bindir[] =
"/bin";
617 const char *p2 =
NULL;
619 #ifdef ENABLE_MULTIARCH
622 if (p - libpath >= bindir_len && !
STRNCASECMP(p - bindir_len, bindir, bindir_len)) {
628 else if (p - libpath >= libdir_len && !
strncmp(p - libdir_len, libdir, libdir_len)) {
629 archlibdir =
rb_str_subseq(sopath, 0, (p2 ? p2 : p) - libpath);
633 #ifdef ENABLE_MULTIARCH
640 if (p)
goto multiarch;
645 baselen = p - libpath;
648 #define PREFIX_PATH() sopath
649 #define BASEPATH() rb_str_buf_cat(rb_str_buf_new(baselen+len), libpath, baselen)
650 #define RUBY_RELATIVE(path, len) rb_str_buf_cat(BASEPATH(), (path), (len))
653 #define RUBY_RELATIVE(path, len) rubylib_path_new((path), (len))
654 #define PREFIX_PATH() RUBY_RELATIVE(ruby_exec_prefix, exec_prefix_len)
663 load_path =
GET_VM()->load_path;
681 add_modules(
VALUE *req_list,
const char *
mod)
694 require_libraries(
VALUE *req_list)
719 process_sflag(
int *sflag)
737 if (s[1] ==
'-' && s[2] ==
'\0')
742 for (p = s + 1; *p; p++) {
751 else if (*p !=
'_' && !
ISALNUM(*p)) {
754 rb_str_new2(
"invalid name for global variable - ");
755 if (!(p =
strchr(p,
'='))) {
761 name_error[1] = args[-1];
767 for (p = s + 1; *p; ++p) {
790 VALUE argstr, argary;
799 if (envopt) *p++ =
' ';
806 while (*p && !
ISSPACE(*p)) ++p;
817 while ((
i = proc_options(
argc,
argv, opt, envopt)) > 1 && envopt && (
argc -=
i) > 0) {
835 name_match_p(
const char *
name,
const char *
str,
size_t len)
837 if (
len == 0)
return 0;
840 if (!--
len || !*++
str)
return 1;
843 if (*
str !=
'-' && *
str !=
'_')
return 0;
845 if (*
name !=
'-' && *
name !=
'_')
return 0;
851 #define NAME_MATCH_P(name, str, len) \
852 ((len) < (int)sizeof(name) && name_match_p((name), (str), (len)))
854 #define UNSET_WHEN(name, bit, str, len) \
855 if (NAME_MATCH_P((name), (str), (len))) { \
856 *(unsigned int *)arg &= ~(bit); \
860 #define SET_WHEN(name, bit, str, len) \
861 if (NAME_MATCH_P((name), (str), (len))) { \
862 *(unsigned int *)arg |= (bit); \
866 #define LITERAL_NAME_ELEMENT(name) #name
869 feature_option(
const char *
str,
int len,
void *
arg,
const unsigned int enable)
873 unsigned int mask = ~0
U;
874 unsigned int set = 0
U;
875 #if AMBIGUOUS_FEATURE_NAMES
877 # define FEATURE_FOUND ++matched
879 # define FEATURE_FOUND goto found
881 #define SET_FEATURE(bit) \
882 if (NAME_MATCH_P(#bit, str, len)) {set |= mask = FEATURE_BIT(bit); FEATURE_FOUND;}
889 #if AMBIGUOUS_FEATURE_NAMES
890 if (matched == 1)
goto found;
893 #define ADD_FEATURE_NAME(bit) \
894 if (FEATURE_BIT(bit) & set) { \
895 rb_str_cat_cstr(mesg, #bit); \
896 if (--matched) rb_str_cat_cstr(mesg, ", "); \
901 #undef ADD_FEATURE_NAME
904 rb_warn(
"unknown argument for --%s: `%.*s'",
905 enable ?
"enable" :
"disable",
len,
str);
910 enable_option(
const char *
str,
int len,
void *
arg)
916 disable_option(
const char *
str,
int len,
void *
arg)
925 debug_option(
const char *
str,
int len,
void *
arg)
929 #define SET_WHEN_DEBUG(bit) \
930 if (NAME_MATCH_P(#bit, str, len)) { \
931 FEATURE_SET(*argp, DEBUG_BIT(bit)); \
943 dump_option(
const char *
str,
int len,
void *
arg)
946 #define SET_WHEN_DUMP(bit) SET_WHEN(#bit, DUMP_BIT(bit), str, len)
953 set_option_encoding_once(
const char *
type,
VALUE *
name,
const char *e,
long elen)
957 if (!elen) elen =
strlen(e);
968 #define set_internal_encoding_once(opt, e, elen) \
969 set_option_encoding_once("default_internal", &(opt)->intern.enc.name, (e), (elen))
970 #define set_external_encoding_once(opt, e, elen) \
971 set_option_encoding_once("default_external", &(opt)->ext.enc.name, (e), (elen))
972 #define set_source_encoding_once(opt, e, elen) \
973 set_option_encoding_once("source", &(opt)->src.enc.name, (e), (elen))
977 setup_mjit_options(
const char *s,
struct mjit_options *mjit_opt)
980 else if (
strcmp(s,
"-warnings") == 0) {
983 else if (
strncmp(s,
"-debug=", 7) == 0) {
986 else if (
strcmp(s,
"-debug") == 0) {
989 else if (
strcmp(s,
"-wait") == 0) {
992 else if (
strcmp(s,
"-save-temps") == 0) {
995 else if (
strncmp(s,
"-verbose=", 9) == 0) {
998 else if (
strncmp(s,
"-max-cache=", 11) == 0) {
1001 else if (
strncmp(s,
"-min-calls=", 11) == 0) {
1006 "invalid MJIT option `%s' (--help will show valid MJIT options)", s + 1);
1014 long n, argc0 =
argc;
1022 const char *
const arg =
argv[0];
1030 if (envopt)
goto noenvopt;
1036 if (envopt)
goto noenvopt;
1040 if (envopt)
goto noenvopt;
1052 if (envopt)
goto noenvopt;
1074 unsigned int bits = 0;
1075 static const char no_prefix[] =
"no-";
1076 int enable =
strncmp(s += 2, no_prefix,
sizeof(no_prefix)-1) != 0;
1077 if (!enable) s +=
sizeof(no_prefix)-1;
1086 rb_warn(
"unknown warning category: `%s'", s);
1119 if (envopt)
goto noenvopt;
1125 if (envopt)
goto noenvopt;
1132 if (envopt)
goto noenvopt;
1137 if (envopt)
goto noenvopt;
1144 if (envopt)
goto noenvopt;
1151 if (envopt)
goto noenvopt;
1172 else if (
argc > 1) {
1179 if (envopt)
goto noenvopt;
1185 if (envopt)
goto noenvopt;
1189 if (*s &&
chdir(s) < 0) {
1196 if (envopt)
goto noenvopt;
1197 if (!*++s && (!--
argc || !(s = *++
argv) || !*s)) {
1206 if (envopt)
goto noenvopt;
1213 if (!*++s && (!--
argc || !(s = *++
argv))) {
1225 const char *enc_name = 0;
1228 enc_name =
"EUC-JP";
1231 enc_name =
"Windows-31J";
1236 case 'N':
case 'n':
case 'A':
case 'a':
1237 enc_name =
"ASCII-8BIT";
1258 rb_warn(
"ruby -T will be removed in Ruby 3.0");
1265 else if (
argc > 1) {
1272 if (envopt)
goto noenvopt;
1282 else if (
v == 0 && numlen >= 2) {
1293 if (!s[1] || (s[1] ==
'\r' && !s[2])) {
1299 # define is_option_end(c, allow_hyphen) \
1300 (!(c) || ((allow_hyphen) && (c) == '-') || (c) == '=')
1301 # define check_envopt(name, allow_envopt) \
1302 (((allow_envopt) || !envopt) ? (void)0 : \
1303 rb_raise(rb_eRuntimeError, "invalid switch in RUBYOPT: --" name))
1304 # define need_argument(name, s, needs_arg, next_arg) \
1305 ((*(s) ? !*++(s) : (next_arg) && (!argc || !((s) = argv[1]) || (--argc, ++argv, 0))) && (needs_arg) ? \
1306 rb_raise(rb_eRuntimeError, "missing argument for --" name) \
1308 # define is_option_with_arg(name, allow_hyphen, allow_envopt) \
1309 is_option_with_optarg(name, allow_hyphen, allow_envopt, Qtrue, Qtrue)
1310 # define is_option_with_optarg(name, allow_hyphen, allow_envopt, needs_arg, next_arg) \
1311 (strncmp((name), s, n = sizeof(name) - 1) == 0 && is_option_end(s[n], (allow_hyphen)) ? \
1312 (check_envopt(name, (allow_envopt)), s += n, \
1313 need_argument(name, s, needs_arg, next_arg), 1) : 0)
1315 if (
strcmp(
"copyright", s) == 0) {
1316 if (envopt)
goto noenvopt_long;
1338 # define set_encoding_part(type) \
1339 if (!(p = strchr(s, ':'))) { \
1340 set_##type##_encoding_once(opt, s, 0); \
1344 set_##type##_encoding_once(opt, s, p-s); \
1347 if (!*(s = ++p))
break;
1349 if (!*(s = ++p))
break;
1350 #if defined ALLOW_DEFAULT_SOURCE_ENCODING && ALLOW_DEFAULT_SOURCE_ENCODING
1352 if (!*(s = ++p))
break;
1355 (
arg[1] ==
'-' ?
"--encoding" :
"-E"), s);
1356 # undef set_encoding_part
1365 #if defined ALLOW_DEFAULT_SOURCE_ENCODING && ALLOW_DEFAULT_SOURCE_ENCODING
1370 else if (
strcmp(
"version", s) == 0) {
1371 if (envopt)
goto noenvopt_long;
1374 else if (
strcmp(
"verbose", s) == 0) {
1378 else if (
strncmp(
"jit", s, 3) == 0) {
1381 setup_mjit_options(s + 3, &opt->mjit);
1383 rb_warn(
"MJIT support is disabled.");
1386 else if (
strcmp(
"yydebug", s) == 0) {
1387 if (envopt)
goto noenvopt_long;
1393 else if (
strcmp(
"help", s) == 0) {
1394 if (envopt)
goto noenvopt_long;
1400 "invalid option --%s (-h will show valid options)", s);
1411 "invalid option -%c (-h will show valid options)",
1412 (
int)(
unsigned char)*s);
1427 # undef is_option_end
1428 # undef check_envopt
1429 # undef need_argument
1430 # undef is_option_with_arg
1431 # undef is_option_with_optarg
1436 if (warning) opt->
warning = warning;
1437 return argc0 -
argc;
1443 ruby_init_prelude(
void)
1450 opt_enc_index(
VALUE enc_name)
1464 #define rb_progname (GET_VM()->progname)
1465 #define rb_orig_progname (GET_VM()->orig_progname)
1481 #define rb_define_readonly_boolean(name, val) \
1482 rb_define_virtual_variable((name), (val) ? true_value : false_value, 0)
1589 const char *
const progname =
1591 origarg.argc > 0 && origarg.argv && origarg.argv[0] ? origarg.argv[0] :
1608 moreswitches(s, opt, 1);
1610 opt->
src.
enc.name = src_enc_name;
1612 opt->
ext.
enc.name = ext_enc_name;
1620 rb_warning(
"-K is specified; it is for 1.8 compatibility and may cause odd behavior");
1624 opt->mjit.on =
TRUE;
1676 #elif defined DOSISH
1698 if (opt->
ext.
enc.name != 0) {
1704 if (opt->
src.
enc.name != 0) {
1708 if (opt->
ext.
enc.index >= 0) {
1738 int modifiable =
FALSE;
1746 if (newpath ==
path)
continue;
1769 ruby_init_prelude();
1772 #define SET_COMPILE_OPTION(h, o, name) \
1773 rb_hash_aset((h), ID2SYM(rb_intern_const(#name)), \
1774 (FEATURE_SET_P(o->features, FEATURE_BIT(name)) ? Qtrue : Qfalse));
1778 #undef SET_COMPILE_OPTION
1781 process_sflag(&opt->
sflag);
1788 if (opt->
src.
enc.index >= 0) {
1794 if (ienc) eenc = ienc;
1815 f = open_load_file(script_name, &opt->
xflag);
1821 if (!dump)
return Qtrue;
1824 if (opt->
ext.
enc.index >= 0) {
1846 process_sflag(&opt->
sflag);
1852 if (!dump)
return Qtrue;
1889 const struct rb_block *base_block = toplevel_context(toplevel_binding);
1898 if (!dump)
return Qtrue;
1915 rb_exec_event_hook_script_compiled(ec,
iseq, opt->
e_script);
1919 rb_exec_event_hook_script_compiled(ec,
iseq,
Qnil);
1927 warn_cr_in_shebang(
const char *
str,
long len)
1930 rb_warn(
"shebang line ending with \\r may cause problems");
1934 #define warn_cr_in_shebang(str, len) (void)0
1946 load_file_internal(
VALUE argp_v)
1959 CONST_ID(set_encoding,
"set_encoding");
1978 if (
len > 2 &&
str[0] ==
'#' &&
str[1] ==
'!') {
1979 if (line_start == 1) warn_cr_in_shebang(
str,
len);
1993 warn_cr_in_shebang(
str,
len);
1996 goto search_shebang;
2001 if (*
str ==
'\n') *
str-- =
'\0';
2002 if (*
str ==
'\r') *
str-- =
'\0';
2004 if ((p =
strstr(p,
" -")) != 0) {
2006 moreswitches(p + 1,
opt, 0);
2012 else if (!
NIL_P(c)) {
2027 else if (!
NIL_P(c)) {
2078 open_load_file(
VALUE fname_v,
int *xflag)
2086 if (flen == 1 &&
fname[0] ==
'-') {
2093 #if defined O_NONBLOCK && HAVE_FCNTL && !(O_NONBLOCK & O_ACCMODE)
2095 # define MODE_TO_LOAD (O_RDONLY | O_NONBLOCK)
2096 #elif defined O_NDELAY && HAVE_FCNTL && !(O_NDELAY & O_ACCMODE)
2097 # define MODE_TO_LOAD (O_RDONLY | O_NDELAY)
2099 # define MODE_TO_LOAD (O_RDONLY)
2102 #if defined DOSISH || defined __CYGWIN__
2103 # define isdirsep(x) ((x) == '/' || (x) == '\\')
2105 static const char exeext[] =
".exe";
2106 enum {extlen =
sizeof(exeext)-1};
2126 #if defined HAVE_FCNTL && MODE_TO_LOAD != O_RDONLY
2196 VALUE f = open_load_file(fname_v, &cmdline_options_init(&
opt)->xflag);
2197 return load_file(
parser, fname_v,
f, 0, &
opt);
2212 proc_argv0(
VALUE process)
2237 proc_setproctitle(
VALUE process,
VALUE title)
2239 return ruby_setproctitle(title);
2243 ruby_setproctitle(
VALUE title)
2253 if (origarg.argv == 0)
2260 external_str_new_cstr(
const char *p)
2325 opt_W_getter(
ID id,
VALUE *variable)
2327 switch (*variable) {
2371 #if defined(USE_DLN_A_OUT)
2372 if (origarg.argc > 0 && origarg.argv)
2373 dln_argv0 = origarg.argv[0];
2375 dln_argv0 =
argv[0];
2393 if (!origarg.argv || origarg.argc <= 0) {
2394 origarg.argc =
argc;
2395 origarg.argv =
argv;
2402 #ifndef HAVE_SETPROCTITLE
2410 fill_standard_fds(
void)
2412 int f0, f1, f2, fds[2];
2418 if (
pipe(fds) == 0) {
2427 if (
pipe(fds) == 0) {
2429 if (f1 && fds[1] != 1)
2431 if (f2 && fds[1] != 2)
2433 if (fds[1] != 1 && fds[1] != 2)
2453 origarg.argc = *
argc;
2454 origarg.argv = *
argv;
2455 #if defined(USE_DLN_A_OUT)
2456 dln_argv0 = origarg.argv[0];
2459 fill_standard_fds();
VALUE rb_readlink(VALUE path, rb_encoding *resultenc)
VALUE rb_gv_set(const char *, VALUE)
VALUE rb_parser_new(void)
#define SET_COMPILE_OPTION(h, o, name)
#define RSTRING_GETMEM(str, ptrvar, lenvar)
RUBY_EXTERN char * strstr(const char *, const char *)
int rb_gc_for_fd(int err)
ruby_cmdline_options_t * opt
VALUE rb_exc_new_str(VALUE etype, VALUE str)
void rb_warning_category_update(unsigned int mask, unsigned int bits)
#define set_internal_encoding_once(opt, e, elen)
#define M(shortopt, longopt, desc)
void rb_gc_register_mark_object(VALUE obj)
#define IF_UTF8_PATH(t, f)
void ruby_show_version(void)
Prints the version information of the CRuby interpreter to stdout.
#define rb_define_readonly_boolean(name, val)
void rb_warn(const char *fmt,...)
void rb_warning(const char *fmt,...)
VALUE rb_iseq_disasm(const rb_iseq_t *iseq)
void rb_ast_dispose(rb_ast_t *ast)
void * rb_load_file_str(VALUE fname_v)
char * strchr(char *, char)
struct ruby_cmdline_options::@153 intern
VALUE rb_attr_get(VALUE, ID)
rb_encoding * rb_locale_encoding(void)
rb_encoding * rb_default_external_encoding(void)
void rb_gvar_readonly_setter(VALUE v, ID id, VALUE *_)
VALUE rb_ary_replace(VALUE copy, VALUE orig)
#define RB_TYPE_P(obj, type)
#define rb_intern_const(str)
#define ECONV_UNDEF_REPLACE
#define RSTRING_LENINT(str)
VALUE rb_define_module(const char *name)
RUBY_EXTERN VALUE rb_output_rs
void rb_enc_set_default_internal(VALUE encoding)
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
int ruby_env_debug_option(const char *str, int len, void *arg)
void rb_lastline_set(VALUE)
#define scan_oct(s, l, e)
rb_ast_t * rb_parser_compile_file_path(VALUE vparser, VALUE fname, VALUE file, int start)
RUBY_EXTERN VALUE rb_stdin
char * rb_enc_path_last_separator(const char *path, const char *end, rb_encoding *enc)
void * rb_parser_load_file(VALUE parser, VALUE fname_v)
void rb_const_set(VALUE, ID, VALUE)
#define FEATURE_SET(feat, bits)
int rb_enc_dummy_p(rb_encoding *enc)
VALUE rb_ary_shift(VALUE ary)
#define DEFINE_FEATURE(bit)
void rb_loaderror(const char *fmt,...)
struct ruby_cmdline_options::@153 src
RUBY_EXTERN VALUE rb_stdout
#define RARRAY_ASET(a, i, v)
VALUE rb_const_remove(VALUE, ID)
VALUE rb_reg_new(const char *, long, int)
VALUE rb_enc_from_encoding(rb_encoding *encoding)
int ruby_is_fd_loadable(int fd)
void rb_fatal(const char *fmt,...)
size_t strlen(const char *)
const char ruby_initial_load_paths[]
@ RB_WARN_CATEGORY_EXPERIMENTAL
#define set_encoding_part(type)
#define EACH_DUMPS(X, SEP)
VALUE ruby_archlibdir_path
VALUE rb_funcall_passing_block(VALUE, ID, int, const VALUE *)
VALUE rb_get_expanded_load_path(void)
void ruby_push_include(const char *path, VALUE(*filter)(VALUE))
VALUE rb_str_resize(VALUE, long)
#define ruby_show_copyright()
#define FEATURE_SET_RESTORE(feat, save)
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags, VALUE ecopts)
void ruby_prog_init(void)
Defines built-in variables.
void rb_load_fail(VALUE path, const char *err)
void ruby_incpush(const char *path)
VALUE rb_parser_dump_tree(const NODE *node, int comment)
rb_encoding * rb_ascii8bit_encoding(void)
#define str_conv_enc(str, from, to)
RUBY_EXTERN char * strerror(int)
rb_iseq_t * rb_iseq_new_main(const rb_ast_body_t *ast, VALUE path, VALUE realpath, const rb_iseq_t *parent)
void * ruby_process_options(int argc, char **argv)
void Init_ruby_description(void)
const typedef OnigEncodingType rb_encoding
#define src_encoding_index
void rb_thread_wait_fd(int)
#define DEFINE_DEBUG_FEATURE(bit)
rb_encoding * rb_enc_from_index(int index)
VALUE rb_ary_tmp_new(long capa)
@ feature_debug_flag_begin
#define FEATURE_SET_TO(feat, bit_mask, bit_set)
struct ruby_cmdline_options::@153::@154 enc
VALUE rb_vm_top_self(void)
@ feature_debug_flag_first
VALUE rb_parser_set_yydebug(VALUE self, VALUE flag)
#define EACH_FEATURES(X, SEP)
void rb_vm_set_progname(VALUE filename)
VALUE rb_realpath_internal(VALUE basedir, VALUE path, int strict)
void rb_parser_set_options(VALUE vparser, int print, int loop, int chomp, int split)
void rb_w32_sysinit(int *, char ***)
VALUE rb_ary_push(VALUE ary, VALUE item)
void rb_update_max_fd(int fd)
VALUE rb_obj_freeze(VALUE)
Make the object unmodifiable.
const struct rb_block block
void ruby_script(const char *name)
Sets the current script name to this value.
#define SET_WHEN_DEBUG(bit)
#define is_option_with_arg(name, allow_hyphen, allow_envopt)
#define RARRAY_AREF(a, i)
#define STRNCASECMP(s1, s2, n)
#define RUBY_RELATIVE(path, len)
#define StringValuePtr(v)
void rb_enc_copy(VALUE obj1, VALUE obj2)
void rb_str_set_len(VALUE, long)
void ruby_set_argv(int argc, char **argv)
rb_ast_t * rb_parser_compile_string_path(VALUE vparser, VALUE f, VALUE s, int line)
struct rb_encoding_entry * list
#define MEMZERO(p, type, n)
VALUE rb_str_new_frozen(VALUE)
void rb_gc_register_address(VALUE *addr)
VALUE rb_parser_end_seen_p(VALUE vparser)
RUBY_EXTERN void setproctitle(const char *fmt,...)
void rb_define_variable(const char *, VALUE *)
void ruby_init_loadpath(void)
rb_encoding * rb_default_internal_encoding(void)
#define set_external_encoding_once(opt, e, elen)
#define CONST_ID(var, str)
#define StringValueCStr(v)
void ruby_set_script_name(VALUE name)
Sets the current script name to this value.
#define RARRAY_CONST_PTR(a)
VALUE rb_lastline_get(void)
VALUE rb_ary_clear(VALUE ary)
RUBY_EXTERN int dup2(int, int)
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for module.
RUBY_EXTERN VALUE rb_cObject
int rb_cloexec_open(const char *pathname, int flags, mode_t mode)
unsigned char buf[MIME_BUF_SIZE]
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
RUBY_EXTERN VALUE rb_mProcess
#define SET_WHEN_DUMP(bit)
#define LITERAL_NAME_ELEMENT(name)
rb_ast_t * rb_parser_compile_string(VALUE vparser, const char *f, VALUE s, int line)
VALUE rb_parser_encoding(VALUE vparser)
void rb_define_global_const(const char *, VALUE)
void rb_enc_set_default_external(VALUE encoding)
#define ENCODING_GET(obj)
VALUE rb_sprintf(const char *format,...)
const RUBY_EXTERN int ruby_patchlevel
VALUE rb_str_subseq(VALUE, long, long)
rb_encoding * rb_utf8_encoding(void)
char * strrchr(const char *, const char)
char str[HTML_ESCAPE_MAX_LEN+1]
struct mjit_options mjit_opts
struct ruby_cmdline_options::@153 ext
#define INITIAL_LOAD_PATH_MARK
#define is_option_with_optarg(name, allow_hyphen, allow_envopt, needs_arg, next_arg)
int rb_enc_find_index(const char *name)
VALUE rb_parser_set_context(VALUE vparser, const struct rb_iseq_struct *base, int main)
RUBY_EXTERN VALUE rb_cString
#define DEFAULT_RUBYGEMS_ENABLED
VALUE rb_str_encode_ospath(VALUE path)
VALUE rb_io_getbyte(VALUE)
#define OBJ_FREEZE_RAW(x)
void ruby_init_setproctitle(int argc, char *argv[])
void rb_str_modify_expand(VALUE, long)
#define GetBindingPtr(obj, ptr)
const char ruby_exec_prefix[]
const char * rb_obj_classname(VALUE)
VALUE rb_io_write(VALUE, VALUE)
void ruby_sysinit(int *argc, char ***argv)
Initializes the process for libruby.
VALUE rb_io_ungetbyte(VALUE, VALUE)
void * rb_load_file(const char *fname)
void ruby_incpush_expand(const char *path)
VALUE rb_class_new_instance(int, const VALUE *, VALUE)
Allocates and initializes an instance of klass.
#define MEMMOVE(p1, p2, type, n)
VALUE rb_ivar_set(VALUE, ID, VALUE)
#define RBASIC_SET_CLASS_RAW(obj, cls)
#define EACH_DEBUG_FEATURES(X, SEP)
#define set_source_encoding_once(opt, e, elen)
void rb_define_hooked_variable(const char *q, VALUE *w, type *e, void_type *r)
Define a function-backended global variable.
VALUE rb_ensure(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*e_proc)(VALUE), VALUE data2)
An equivalent to ensure clause.
#define ECONV_INVALID_REPLACE
@ RB_WARN_CATEGORY_DEPRECATED
VALUE rb_file_expand_path(VALUE fname, VALUE dname)
void rb_stdio_set_default_encoding(void)
#define rb_strlen_lit(str)
VALUE rb_str_tmp_new(long)
#define NAME_MATCH_P(name, str, len)
void ruby_set_inplace_mode(const char *)
VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to)
void Init_builtin_features(void)
VALUE rb_str_cat(VALUE, const char *, long)
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
void ruby_gc_set_params(void)
void ruby_each_words(const char *, void(*)(const char *, int, void *), void *)
VALUE type(ANYARGS)
ANYARGS-ed function type.
VALUE rb_io_fdopen(int, int, const char *)
void rb_ary_modify(VALUE ary)
VALUE rb_const_get(VALUE, ID)