Ruby  2.5.0dev(2017-10-22revision60238)
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
ruby.c File Reference
#include "internal.h"
#include "ruby/thread.h"
#include "eval_intern.h"
#include "dln.h"
#include <stdio.h>
#include <sys/types.h>
#include <ctype.h>
#include "ruby/util.h"

Go to the source code of this file.

Data Structures

struct  ruby_cmdline_options
 
struct  load_file_arg
 

Macros

#define MAXPATHLEN   1024
 
#define O_ACCMODE   (O_RDONLY | O_WRONLY | O_RDWR)
 
#define DISABLE_RUBYGEMS   0
 
#define DEFAULT_RUBYGEMS_ENABLED   "enabled"
 
#define COMMA   ,
 
#define FEATURE_BIT(bit)   (1U << feature_##bit)
 
#define EACH_FEATURES(X, SEP)
 
#define EACH_DEBUG_FEATURES(X, SEP)
 
#define AMBIGUOUS_FEATURE_NAMES   0 /* no ambiguous feature names now */
 
#define DEFINE_FEATURE(bit)   feature_##bit
 
#define DEFINE_DEBUG_FEATURE(bit)   feature_debug_##bit
 
#define DEBUG_BIT(bit)   (1U << feature_debug_##bit)
 
#define DUMP_BIT(bit)   (1U << dump_##bit)
 
#define DEFINE_DUMP(bit)   dump_##bit
 
#define EACH_DUMPS(X, SEP)
 
#define src_encoding_index   GET_VM()->src_encoding_index
 
#define forbid_setid(s)   forbid_setid((s), opt)
 
#define M(shortopt, longopt, desc)
 
#define SHOW(m)   show_usage_line((m).str, (m).namelen, (m).secondlen, help)
 
#define rubylib_path_new   rb_str_new
 
#define UTF8_PATH   0
 
#define IF_UTF8_PATH(t, f)   f
 
#define str_conv_enc(str, from, to)   (str)
 
#define INITIAL_LOAD_PATH_MARK   rb_intern_const("@gem_prelude_index")
 
#define RUBY_RELATIVE(path, len)   rubylib_path_new((path), (len))
 
#define PREFIX_PATH()   RUBY_RELATIVE(ruby_exec_prefix, exec_prefix_len)
 
#define NAME_MATCH_P(name, str, len)   ((len) < (int)sizeof(name) && name_match_p((name), (str), (len)))
 
#define UNSET_WHEN(name, bit, str, len)
 
#define SET_WHEN(name, bit, str, len)
 
#define LITERAL_NAME_ELEMENT(name)   #name
 
#define SET_FEATURE(bit)   if (NAME_MATCH_P(#bit, str, len)) {mask = FEATURE_BIT(bit); goto found;}
 
#define SET_WHEN_DEBUG(bit)   SET_WHEN(#bit, DEBUG_BIT(bit), str, len)
 
#define SET_WHEN_DUMP(bit)   SET_WHEN(#bit, DUMP_BIT(bit), str, len)
 
#define set_internal_encoding_once(opt, e, elen)   set_option_encoding_once("default_internal", &(opt)->intern.enc.name, (e), (elen))
 
#define set_external_encoding_once(opt, e, elen)   set_option_encoding_once("default_external", &(opt)->ext.enc.name, (e), (elen))
 
#define set_source_encoding_once(opt, e, elen)   set_option_encoding_once("source", &(opt)->src.enc.name, (e), (elen))
 
#define is_option_end(c, allow_hyphen)   (!(c) || ((allow_hyphen) && (c) == '-') || (c) == '=')
 
#define check_envopt(name, allow_envopt)
 
#define need_argument(name, s, needs_arg, next_arg)
 
#define is_option_with_arg(name, allow_hyphen, allow_envopt)   is_option_with_optarg(name, allow_hyphen, allow_envopt, Qtrue, Qtrue)
 
#define is_option_with_optarg(name, allow_hyphen, allow_envopt, needs_arg, next_arg)
 
#define set_encoding_part(type)
 
#define rb_progname   (GET_VM()->progname)
 
#define rb_orig_progname   (GET_VM()->orig_progname)
 
#define rb_define_readonly_boolean(name, val)   rb_define_virtual_variable((name), (val) ? true_value : false_value, 0)
 
#define SET_COMPILE_OPTION(h, o, name)
 
#define MODE_TO_LOAD   (O_RDONLY)
 

Typedefs

typedef struct ruby_cmdline_options ruby_cmdline_options_t
 

Enumerations

enum  feature_flag_bits {
  EACH_FEATURES =(DEFINE_FEATURE, COMMA), feature_debug_flag_first, feature_debug_flag_begin = feature_debug_flag_first - 1, EACH_DEBUG_FEATURES =(DEFINE_DEBUG_FEATURE, COMMA),
  feature_flag_count
}
 
enum  dump_flag_bits { dump_version_v, EACH_DUMPS =(DEFINE_DUMP, COMMA), dump_exit_bits }
 
enum  { COMPILATION_FEATURES, DEFAULT_FEATURES }
 

Functions

char * getenv ()
 
void ruby_push_include (const char *path, VALUE(*filter)(VALUE))
 
void ruby_incpush (const char *path)
 
void ruby_incpush_expand (const char *path)
 
void ruby_init_loadpath_safe (int safe_level)
 
void ruby_init_loadpath (void)
 
int ruby_env_debug_option (const char *str, int len, void *arg)
 
void * rb_load_file (const char *fname)
 
void * rb_load_file_str (VALUE fname_v)
 
void * rb_parser_load_file (VALUE parser, VALUE fname_v)
 
void ruby_script (const char *name)
 Sets the current script name to this value. More...
 
void ruby_set_script_name (VALUE name)
 Sets the current script name to this value. More...
 
void ruby_prog_init (void)
 Defines built-in variables. More...
 
void ruby_set_argv (int argc, char **argv)
 
void * ruby_process_options (int argc, char **argv)
 
void ruby_sysinit (int *argc, char ***argv)
 Initializes the process for libruby. More...
 

Variables

RUBY_EXTERN const int ruby_patchlevel
 
VALUE rb_argv0
 

Macro Definition Documentation

◆ AMBIGUOUS_FEATURE_NAMES

#define AMBIGUOUS_FEATURE_NAMES   0 /* no ambiguous feature names now */

Definition at line 80 of file ruby.c.

◆ check_envopt

#define check_envopt (   name,
  allow_envopt 
)
Value:
(((allow_envopt) || !envopt) ? (void)0 : \
rb_raise(rb_eRuntimeError, "invalid switch in RUBYOPT: --" name))
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2284
VALUE rb_eRuntimeError
Definition: error.c:800
const char * name
Definition: nkf.c:208

◆ COMMA

#define COMMA   ,

Definition at line 66 of file ruby.c.

◆ DEBUG_BIT

#define DEBUG_BIT (   bit)    (1U << feature_debug_##bit)

Definition at line 91 of file ruby.c.

◆ DEFAULT_RUBYGEMS_ENABLED

#define DEFAULT_RUBYGEMS_ENABLED   "enabled"

Definition at line 63 of file ruby.c.

◆ DEFINE_DEBUG_FEATURE

#define DEFINE_DEBUG_FEATURE (   bit)    feature_debug_##bit

Definition at line 82 of file ruby.c.

◆ DEFINE_DUMP

#define DEFINE_DUMP (   bit)    dump_##bit

Definition at line 94 of file ruby.c.

◆ DEFINE_FEATURE

#define DEFINE_FEATURE (   bit)    feature_##bit

Definition at line 81 of file ruby.c.

◆ DISABLE_RUBYGEMS

#define DISABLE_RUBYGEMS   0

Definition at line 58 of file ruby.c.

◆ DUMP_BIT

#define DUMP_BIT (   bit)    (1U << dump_##bit)

Definition at line 93 of file ruby.c.

◆ EACH_DEBUG_FEATURES

#define EACH_DEBUG_FEATURES (   X,
  SEP 
)
Value:
X(frozen_string_literal) \
/* END OF DEBUG FEATURES */

Definition at line 77 of file ruby.c.

◆ EACH_DUMPS

#define EACH_DUMPS (   X,
  SEP 
)
Value:
X(version) \
SEP \
X(copyright) \
SEP \
X(usage) \
SEP \
X(help) \
SEP \
X(yydebug) \
SEP \
X(syntax) \
SEP \
X(parsetree) \
SEP \
X(parsetree_with_comment) \
SEP \
X(insns) \
/* END OF DUMPS */
#define yydebug
Definition: ripper.c:607

Definition at line 95 of file ruby.c.

◆ EACH_FEATURES

#define EACH_FEATURES (   X,
  SEP 
)
Value:
X(gems) \
SEP \
X(did_you_mean) \
SEP \
X(rubyopt) \
SEP \
X(frozen_string_literal) \
/* END OF FEATURES */

Definition at line 68 of file ruby.c.

◆ FEATURE_BIT

#define FEATURE_BIT (   bit)    (1U << feature_##bit)

Definition at line 67 of file ruby.c.

◆ forbid_setid

#define forbid_setid (   s)    forbid_setid((s), opt)

Definition at line 184 of file ruby.c.

◆ IF_UTF8_PATH

#define IF_UTF8_PATH (   t,
  f 
)    f

Definition at line 430 of file ruby.c.

◆ INITIAL_LOAD_PATH_MARK

#define INITIAL_LOAD_PATH_MARK   rb_intern_const("@gem_prelude_index")

Definition at line 478 of file ruby.c.

◆ is_option_end

#define is_option_end (   c,
  allow_hyphen 
)    (!(c) || ((allow_hyphen) && (c) == '-') || (c) == '=')

◆ is_option_with_arg

#define is_option_with_arg (   name,
  allow_hyphen,
  allow_envopt 
)    is_option_with_optarg(name, allow_hyphen, allow_envopt, Qtrue, Qtrue)

◆ is_option_with_optarg

#define is_option_with_optarg (   name,
  allow_hyphen,
  allow_envopt,
  needs_arg,
  next_arg 
)
Value:
(strncmp((name), s, n = sizeof(name) - 1) == 0 && is_option_end(s[n], (allow_hyphen)) ? \
(check_envopt(name, (allow_envopt)), s += n, \
need_argument(name, s, needs_arg, next_arg), 1) : 0)
#define check_envopt(name, allow_envopt)
#define is_option_end(c, allow_hyphen)
const char * name
Definition: nkf.c:208

◆ LITERAL_NAME_ELEMENT

#define LITERAL_NAME_ELEMENT (   name)    #name

Definition at line 815 of file ruby.c.

◆ M

#define M (   shortopt,
  longopt,
  desc 
)
Value:
{ \
shortopt " " longopt " " desc, \
(unsigned short)sizeof(shortopt), \
(unsigned short)sizeof(longopt), \
}

◆ MAXPATHLEN

#define MAXPATHLEN   1024

Definition at line 45 of file ruby.c.

Referenced by ruby_init_loadpath_safe().

◆ MODE_TO_LOAD

#define MODE_TO_LOAD   (O_RDONLY)

◆ NAME_MATCH_P

#define NAME_MATCH_P (   name,
  str,
  len 
)    ((len) < (int)sizeof(name) && name_match_p((name), (str), (len)))

Definition at line 800 of file ruby.c.

◆ need_argument

#define need_argument (   name,
  s,
  needs_arg,
  next_arg 
)
Value:
((*(s) ? !*++(s) : (next_arg) && (!argc || !((s) = argv[1]) || (--argc, ++argv, 0))) && (needs_arg) ? \
rb_raise(rb_eRuntimeError, "missing argument for --" name) \
: (void)0)
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2284
int argc
Definition: ruby.c:187
VALUE rb_eRuntimeError
Definition: error.c:800
const char * name
Definition: nkf.c:208
char ** argv
Definition: ruby.c:188

◆ O_ACCMODE

#define O_ACCMODE   (O_RDONLY | O_WRONLY | O_RDWR)

Definition at line 48 of file ruby.c.

◆ PREFIX_PATH

#define PREFIX_PATH ( )    RUBY_RELATIVE(ruby_exec_prefix, exec_prefix_len)

◆ rb_define_readonly_boolean

#define rb_define_readonly_boolean (   name,
  val 
)    rb_define_virtual_variable((name), (val) ? true_value : false_value, 0)

Definition at line 1370 of file ruby.c.

◆ rb_orig_progname

#define rb_orig_progname   (GET_VM()->orig_progname)

Definition at line 1355 of file ruby.c.

Referenced by ruby_script(), and ruby_set_script_name().

◆ rb_progname

#define rb_progname   (GET_VM()->progname)

Definition at line 1354 of file ruby.c.

Referenced by ruby_script(), and ruby_set_script_name().

◆ RUBY_RELATIVE

#define RUBY_RELATIVE (   path,
  len 
)    rubylib_path_new((path), (len))

◆ rubylib_path_new

#define rubylib_path_new   rb_str_new

Definition at line 285 of file ruby.c.

◆ SET_COMPILE_OPTION

#define SET_COMPILE_OPTION (   h,
  o,
  name 
)
Value:
((o)->features & FEATURE_BIT(name) ? Qtrue : Qfalse));
#define Qtrue
Definition: ruby.h:437
#define FEATURE_BIT(bit)
Definition: ruby.c:67
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
Definition: hash.c:1616
#define Qfalse
Definition: ruby.h:436
const char * name
Definition: nkf.c:208
#define ID2SYM(x)
Definition: ruby.h:383
#define rb_intern_const(str)
Definition: ruby.h:1777

◆ set_encoding_part

#define set_encoding_part (   type)
Value:
if (!(p = strchr(s, ':'))) { \
set_##type##_encoding_once(opt, s, 0); \
break; \
} \
else if (p > s) { \
set_##type##_encoding_once(opt, s, p-s); \
}
char * strchr(char *, char)

◆ set_external_encoding_once

#define set_external_encoding_once (   opt,
  e,
  elen 
)    set_option_encoding_once("default_external", &(opt)->ext.enc.name, (e), (elen))

Definition at line 914 of file ruby.c.

◆ SET_FEATURE

#define SET_FEATURE (   bit)    if (NAME_MATCH_P(#bit, str, len)) {mask = FEATURE_BIT(bit); goto found;}

◆ set_internal_encoding_once

#define set_internal_encoding_once (   opt,
  e,
  elen 
)    set_option_encoding_once("default_internal", &(opt)->intern.enc.name, (e), (elen))

Definition at line 912 of file ruby.c.

◆ set_source_encoding_once

#define set_source_encoding_once (   opt,
  e,
  elen 
)    set_option_encoding_once("source", &(opt)->src.enc.name, (e), (elen))

Definition at line 916 of file ruby.c.

◆ SET_WHEN

#define SET_WHEN (   name,
  bit,
  str,
  len 
)
Value:
if (NAME_MATCH_P((name), (str), (len))) { \
*(unsigned int *)arg |= (bit); \
return; \
}
#define NAME_MATCH_P(name, str, len)
Definition: ruby.c:800
register unsigned int len
Definition: zonetab.h:51
const char * name
Definition: nkf.c:208

Definition at line 809 of file ruby.c.

◆ SET_WHEN_DEBUG

#define SET_WHEN_DEBUG (   bit)    SET_WHEN(#bit, DEBUG_BIT(bit), str, len)

◆ SET_WHEN_DUMP

#define SET_WHEN_DUMP (   bit)    SET_WHEN(#bit, DUMP_BIT(bit), str, len)

◆ SHOW

#define SHOW (   m)    show_usage_line((m).str, (m).namelen, (m).secondlen, help)

◆ src_encoding_index

#define src_encoding_index   GET_VM()->src_encoding_index

Definition at line 151 of file ruby.c.

◆ str_conv_enc

#define str_conv_enc (   str,
  from,
  to 
)    (str)

Definition at line 442 of file ruby.c.

◆ UNSET_WHEN

#define UNSET_WHEN (   name,
  bit,
  str,
  len 
)
Value:
if (NAME_MATCH_P((name), (str), (len))) { \
*(unsigned int *)arg &= ~(bit); \
return; \
}
#define NAME_MATCH_P(name, str, len)
Definition: ruby.c:800
register unsigned int len
Definition: zonetab.h:51
const char * name
Definition: nkf.c:208

Definition at line 803 of file ruby.c.

◆ UTF8_PATH

#define UTF8_PATH   0

Definition at line 425 of file ruby.c.

Typedef Documentation

◆ ruby_cmdline_options_t

Definition at line 122 of file ruby.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
COMPILATION_FEATURES 
DEFAULT_FEATURES 

Definition at line 153 of file ruby.c.

◆ dump_flag_bits

Enumerator
dump_version_v 
EACH_DUMPS 
dump_exit_bits 

Definition at line 114 of file ruby.c.

◆ feature_flag_bits

Enumerator
EACH_FEATURES 
feature_debug_flag_first 
feature_debug_flag_begin 
EACH_DEBUG_FEATURES 
feature_flag_count 

Definition at line 83 of file ruby.c.

Function Documentation

◆ getenv()

char* getenv ( )

◆ rb_load_file()

void* rb_load_file ( const char *  fname)

Definition at line 2023 of file ruby.c.

References rb_load_file_str(), and rb_str_new_cstr().

◆ rb_load_file_str()

void* rb_load_file_str ( VALUE  fname_v)

Definition at line 2030 of file ruby.c.

References rb_parser_load_file(), and rb_parser_new().

Referenced by rb_load_file().

◆ rb_parser_load_file()

void* rb_parser_load_file ( VALUE  parser,
VALUE  fname_v 
)

Definition at line 2036 of file ruby.c.

References load_file_arg::opt.

Referenced by rb_load_file_str().

◆ ruby_env_debug_option()

int ruby_env_debug_option ( const char *  str,
int  len,
void *  arg 
)

◆ ruby_incpush_expand()

void ruby_incpush_expand ( const char *  path)

Definition at line 386 of file ruby.c.

References ruby_push_include().

◆ ruby_init_loadpath_safe()

void ruby_init_loadpath_safe ( int  safe_level)

◆ ruby_push_include()

void ruby_push_include ( const char *  path,
VALUE(*)(VALUE filter 
)

Definition at line 349 of file ruby.c.

Referenced by ruby_incpush(), and ruby_incpush_expand().

Variable Documentation

◆ argc

int argc

◆ argv

char** argv

◆ rb_argv0

VALUE rb_argv0

Definition at line 1356 of file ruby.c.

◆ ruby_patchlevel

RUBY_EXTERN const int ruby_patchlevel

Definition at line 870 of file ruby.c.