Data Structures | Defines | Enumerations | Functions | Variables

ruby.c File Reference

#include "ruby/ruby.h"
#include "ruby/encoding.h"
#include "eval_intern.h"
#include "dln.h"
#include <stdio.h>
#include <sys/types.h>
#include <ctype.h>
#include "ruby/util.h"
Include dependency graph for ruby.c:

Go to the source code of this file.

Data Structures

struct  cmdline_options
struct  load_file_arg

Defines

#define DISABLE_BIT(bit)   (1U << disable_##bit)
#define DUMP_BIT(bit)   (1U << dump_##bit)
#define src_encoding_index   GET_VM()->src_encoding_index
#define forbid_setid(s)   forbid_setid(s, opt)
#define rubylib_mangled_path   rb_str_new
#define RUBY_RELATIVE(path, len)   rubylib_mangled_path(path, len)
#define PREFIX_PATH()   RUBY_RELATIVE(exec_prefix, sizeof(exec_prefix)-1)
#define NAME_MATCH_P(name, str, len)   ((len) < (int)sizeof(name) && strncmp((str), name, (len)) == 0)
#define UNSET_WHEN(name, bit, str, len)
#define SET_WHEN(name, bit, str, len)
#define UNSET_WHEN_DISABLE(bit)   UNSET_WHEN(#bit, DISABLE_BIT(bit), str, len)
#define SET_WHEN_DISABLE(bit)   SET_WHEN(#bit, DISABLE_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)
#define is_option_with_arg(name, allow_hyphen, allow_envopt)
#define set_encoding_part(type)
#define rb_progname   (GET_VM()->progname)
#define rb_define_readonly_boolean(name, val)   rb_define_virtual_variable((name), (val) ? true_value : false_value, 0)
#define PREPARE_PARSE_MAIN(expr)
#define USE_ENVSPACE_FOR_ARG0

Enumerations

enum  disable_flag_bits { disable_gems, disable_rubyopt, disable_flag_count }
enum  dump_flag_bits {
  dump_version, dump_copyright, dump_usage, dump_yydebug,
  dump_syntax, dump_parsetree, dump_parsetree_with_comment, dump_insns,
  dump_flag_count
}

Functions

char * getenv ()
VALUE rb_parser_get_yydebug (VALUE)
VALUE rb_parser_set_yydebug (VALUE, VALUE)
const char * ruby_get_inplace_mode (void)
void ruby_set_inplace_mode (const char *)
static void init_ids (struct cmdline_options *)
static struct cmdline_optionscmdline_options_init (struct cmdline_options *opt)
static NODEload_file (VALUE, const char *, int, struct cmdline_options *)
static void forbid_setid (const char *, struct cmdline_options *)
static void usage (const char *name)
VALUE rb_get_load_path (void)
static void push_include (const char *path, VALUE(*filter)(VALUE))
void ruby_push_include (const char *path, VALUE(*filter)(VALUE))
static VALUE identical_path (VALUE path)
static VALUE locale_path (VALUE path)
void ruby_incpush (const char *path)
static VALUE expand_include_path (VALUE path)
void ruby_incpush_expand (const char *path)
void ruby_init_loadpath_safe (int safe_level)
void ruby_init_loadpath (void)
static void add_modules (VALUE *req_list, const char *mod)
void Init_ext (void)
VALUE rb_vm_top_self (void)
static void require_libraries (VALUE *req_list)
static void process_sflag (int *sflag)
NODErb_parser_append_print (VALUE, NODE *)
NODErb_parser_while_loop (VALUE, NODE *, int, int)
static long proc_options (long argc, char **argv, struct cmdline_options *opt, int envopt)
static void moreswitches (const char *s, struct cmdline_options *opt, int envopt)
static void enable_option (const char *str, int len, void *arg)
static void disable_option (const char *str, int len, void *arg)
static void dump_option (const char *str, int len, void *arg)
static void set_option_encoding_once (const char *type, VALUE *name, const char *e, long elen)
void Init_prelude (void)
static void ruby_init_gems (int enable)
static int opt_enc_index (VALUE enc_name)
static VALUE false_value (void)
static VALUE true_value (void)
static VALUE uscore_get (void)
static VALUE rb_f_sub (int argc, VALUE *argv)
static VALUE rb_f_gsub (int argc, VALUE *argv)
static VALUE rb_f_chop (void)
static VALUE rb_f_chomp (int argc, VALUE *argv)
void rb_stdio_set_default_encoding (void)
VALUE rb_parser_dump_tree (NODE *node, int comment)
static VALUE process_options (int argc, char **argv, struct cmdline_options *opt)
static VALUE load_file_internal (VALUE arg)
static VALUE restore_lineno (VALUE lineno)
void * rb_load_file (const char *fname)
static size_t get_arglen (int argc, char **argv)
static void set_arg0 (VALUE val, ID id)
void ruby_script (const char *name)
static void verbose_setter (VALUE val, ID id, void *data)
static VALUE opt_W_getter (ID id, void *data)
void ruby_prog_init (void)
void ruby_set_argv (int argc, char **argv)
void * ruby_process_options (int argc, char **argv)
void ruby_sysinit (int *argc, char ***argv)

Variables

struct {
   int   argc
   char **   argv
   size_t   len
origarg
VALUE rb_argv0
char ** environ

Define Documentation

#define check_envopt (   name,
  allow_envopt 
)
Value:
((allow_envopt || !envopt) ? (void)0 : \
             rb_raise(rb_eRuntimeError, "invalid switch in RUBYOPT: --" name))
#define DISABLE_BIT (   bit  )     (1U << disable_##bit)

Definition at line 60 of file ruby.c.

Referenced by process_options().

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

Definition at line 67 of file ruby.c.

Referenced by proc_options(), and process_options().

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

Definition at line 119 of file ruby.c.

Referenced by load_file_internal(), proc_options(), and process_options().

#define is_option_end (   c,
  allow_hyphen 
)    (!(c) || (allow_hyphen && (c) == '-') || (c) == '=')
#define is_option_with_arg (   name,
  allow_hyphen,
  allow_envopt 
)
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), 1) : 0)

Referenced by proc_options().

#define NAME_MATCH_P (   name,
  str,
  len 
)    ((len) < (int)sizeof(name) && strncmp((str), name, (len)) == 0)

Definition at line 611 of file ruby.c.

Referenced by disable_option(), and enable_option().

#define need_argument (   name,
  s 
)
Value:
((*s++ ? !*s : (!--argc || !(s = *++argv))) ?           \
             rb_raise(rb_eRuntimeError, "missing argument for --" name) \
             : (void)0)
#define PREFIX_PATH (  )     RUBY_RELATIVE(exec_prefix, sizeof(exec_prefix)-1)

Referenced by ruby_init_loadpath_safe().

#define PREPARE_PARSE_MAIN (   expr  ) 
Value:
do { \
    th->parse_in_eval--; \
    th->base_block = &env->block; \
    expr; \
    th->parse_in_eval++; \
    th->base_block = 0; \
} while (0)

Referenced by process_options().

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

Definition at line 1133 of file ruby.c.

Referenced by process_options().

#define rb_progname   (GET_VM()->progname)
#define RUBY_RELATIVE (   path,
  len 
)    rubylib_mangled_path(path, len)

Referenced by ruby_init_loadpath_safe().

#define rubylib_mangled_path   rb_str_new

Definition at line 211 of file ruby.c.

Referenced by push_include().

#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); \
                    }

Referenced by proc_options().

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

Definition at line 686 of file ruby.c.

Referenced by proc_options().

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

Definition at line 684 of file ruby.c.

Referenced by proc_options().

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

Definition at line 688 of file ruby.c.

Referenced by proc_options().

#define SET_WHEN (   name,
  bit,
  str,
  len 
)
Value:
if (NAME_MATCH_P(name, str, len)) { \
        *(unsigned int *)arg |= (bit);  \
        return;                         \
    }

Definition at line 620 of file ruby.c.

#define SET_WHEN_DISABLE (   bit  )     SET_WHEN(#bit, DISABLE_BIT(bit), str, len)

Referenced by disable_option().

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

Referenced by dump_option().

#define src_encoding_index   GET_VM()->src_encoding_index

Definition at line 104 of file ruby.c.

Referenced by load_file_internal(), and process_options().

#define UNSET_WHEN (   name,
  bit,
  str,
  len 
)
Value:
if (NAME_MATCH_P(name, str, len)) { \
        *(unsigned int *)arg &= ~(bit); \
        return;                         \
    }

Definition at line 614 of file ruby.c.

#define UNSET_WHEN_DISABLE (   bit  )     UNSET_WHEN(#bit, DISABLE_BIT(bit), str, len)

Referenced by enable_option().

#define USE_ENVSPACE_FOR_ARG0

Definition at line 1658 of file ruby.c.


Enumeration Type Documentation

Enumerator:
disable_gems 
disable_rubyopt 
disable_flag_count 

Definition at line 61 of file ruby.c.

Enumerator:
dump_version 
dump_copyright 
dump_usage 
dump_yydebug 
dump_syntax 
dump_parsetree 
dump_parsetree_with_comment 
dump_insns 
dump_flag_count 

Definition at line 68 of file ruby.c.


Function Documentation

static void add_modules ( VALUE req_list,
const char *  mod 
) [static]

Definition at line 459 of file ruby.c.

References list, rb_ary_new(), rb_ary_push(), rb_obj_freeze(), rb_str_new2(), and RBASIC.

Referenced by proc_options().

static struct cmdline_options* cmdline_options_init ( struct cmdline_options opt  )  [static, read]
static void disable_option ( const char *  str,
int  len,
void *  arg 
) [static]

Definition at line 640 of file ruby.c.

References NAME_MATCH_P, rb_warn(), and SET_WHEN_DISABLE.

Referenced by proc_options().

static void dump_option ( const char *  str,
int  len,
void *  arg 
) [static]

Definition at line 653 of file ruby.c.

References rb_warn(), SET_WHEN_DUMP, usage(), version(), and yydebug.

Referenced by proc_options().

static void enable_option ( const char *  str,
int  len,
void *  arg 
) [static]

Definition at line 627 of file ruby.c.

References NAME_MATCH_P, rb_warn(), and UNSET_WHEN_DISABLE.

Referenced by proc_options().

static VALUE expand_include_path ( VALUE  path  )  [static]

Definition at line 296 of file ruby.c.

References Qnil, rb_file_expand_path(), and RSTRING_PTR.

Referenced by ruby_incpush_expand(), and ruby_init_loadpath_safe().

static VALUE false_value ( void   )  [static]

Definition at line 1122 of file ruby.c.

static void forbid_setid ( const char *  s,
struct cmdline_options opt 
) [static]
static size_t get_arglen ( int  argc,
char **  argv 
) [static]

Definition at line 1666 of file ruby.c.

References malloc, NULL, and ruby_setenv().

Referenced by ruby_sysinit().

char* getenv (  ) 
static VALUE identical_path ( VALUE  path  )  [static]

Definition at line 278 of file ruby.c.

Referenced by ruby_init_loadpath_safe().

void Init_ext ( void   ) 

Definition at line 2 of file dmyext.c.

Referenced by require_libraries().

static void init_ids ( struct cmdline_options opt  )  [static]
void Init_prelude ( void   ) 
static NODE * load_file ( VALUE  parser,
const char *  fname,
int  script,
struct cmdline_options opt 
) [static]
static VALUE load_file_internal ( VALUE  arg  )  [static]
static VALUE locale_path ( VALUE  path  )  [static]

Definition at line 283 of file ruby.c.

References rb_enc_associate(), and rb_locale_encoding().

Referenced by ruby_incpush().

static void moreswitches ( const char *  s,
struct cmdline_options opt,
int  envopt 
) [static]
static int opt_enc_index ( VALUE  enc_name  )  [static]
static VALUE opt_W_getter ( ID  id,
void *  data 
) [static]

Definition at line 1806 of file ruby.c.

References INT2FIX, Qfalse, Qnil, and Qtrue.

Referenced by ruby_prog_init().

static long proc_options ( long  argc,
char **  argv,
struct cmdline_options opt,
int  envopt 
) [static]
static VALUE process_options ( int  argc,
char **  argv,
struct cmdline_options opt 
) [static]

Definition at line 1234 of file ruby.c.

References cmdline_options::disable, DISABLE_BIT, dln_find_file_r(), cmdline_options::do_line, cmdline_options::do_loop, cmdline_options::do_print, cmdline_options::do_search, cmdline_options::do_split, cmdline_options::dump, DUMP_BIT, cmdline_options::e_script, cmdline_options::enc, rb_binding_t::env, env, cmdline_options::ext, fbuf, FL_TAINT, FL_UNSET, forbid_setid, GET_THREAD, GET_VM, GetBindingPtr, getenv(), GetEnvPtr, cmdline_options::intern, load_file(), moreswitches(), OBJ_TAINT, opt_enc_index(), origarg, PATH_ENV, PREPARE_PARSE_MAIN, proc_options(), process_sflag(), Qnil, Qtrue, RARRAY_LEN, RARRAY_PTR, rb_argv, rb_cObject, rb_const_get(), rb_default_internal_encoding(), rb_define_global_function(), rb_define_readonly_boolean, rb_enc_associate(), rb_enc_find_index(), rb_enc_from_encoding(), rb_enc_from_index(), rb_enc_set_default_external(), rb_enc_set_default_internal(), rb_f_chomp(), rb_f_chop(), rb_f_gsub(), rb_f_sub(), rb_intern, rb_io_flush(), rb_io_write(), rb_iseq_disasm(), rb_iseq_new_main(), rb_locale_encoding(), rb_obj_freeze(), rb_parser_append_print(), rb_parser_compile_string(), rb_parser_dump_tree(), rb_parser_new(), rb_parser_set_yydebug(), rb_parser_while_loop(), rb_progname, rb_set_safe_level(), rb_stdio_set_default_encoding(), rb_stdout, rb_str_new_cstr(), rb_vm_set_progname(), cmdline_options::req_list, require_libraries(), RSTRING_PTR, ruby_init_gems(), ruby_init_loadpath_safe(), ruby_set_argv(), ruby_show_copyright(), ruby_show_version(), cmdline_options::safe_level, cmdline_options::script, cmdline_options::script_name, cmdline_options::sflag, cmdline_options::src, src_encoding_index, usage(), cmdline_options::verbose, version(), cmdline_options::xflag, and yydebug.

Referenced by ruby_process_options().

static void process_sflag ( int *  sflag  )  [static]
static void push_include ( const char *  path,
VALUE(*)(VALUE filter 
) [static]

Definition at line 215 of file ruby.c.

References CharNext, GET_VM, rb_ary_push(), and rubylib_mangled_path.

Referenced by ruby_push_include().

static VALUE rb_f_chomp ( int  argc,
VALUE argv 
) [static]

Definition at line 1221 of file ruby.c.

References rb_funcall3(), rb_intern, rb_lastline_set(), and uscore_get().

Referenced by process_options().

static VALUE rb_f_chop ( void   )  [static]

Definition at line 1201 of file ruby.c.

References rb_funcall3(), rb_intern, rb_lastline_set(), and uscore_get().

Referenced by process_options().

static VALUE rb_f_gsub ( int  argc,
VALUE argv 
) [static]

Definition at line 1181 of file ruby.c.

References rb_funcall3(), rb_intern, rb_lastline_set(), and uscore_get().

Referenced by process_options().

static VALUE rb_f_sub ( int  argc,
VALUE argv 
) [static]

Definition at line 1160 of file ruby.c.

References rb_funcall3(), rb_intern, rb_lastline_set(), and uscore_get().

Referenced by process_options().

VALUE rb_get_load_path ( void   ) 

Definition at line 30 of file load.c.

References GET_VM.

void* rb_load_file ( const char *  fname  ) 

Definition at line 1649 of file ruby.c.

References cmdline_options_init(), load_file(), and rb_parser_new().

Referenced by rb_load_internal().

NODE* rb_parser_append_print ( VALUE  ,
NODE  
)

Definition at line 15393 of file ripper.c.

References block_append, nd_type, NEW_ARRAY, NEW_FCALL, NEW_GVAR, NODE_PRELUDE, rb_intern, and TypedData_Get_Struct.

Referenced by process_options().

VALUE rb_parser_dump_tree ( NODE node,
int  comment 
)

Definition at line 911 of file node.c.

References buf, dump_node(), and rb_str_new_cstr().

Referenced by process_options().

VALUE rb_parser_get_yydebug ( VALUE   ) 

Definition at line 16196 of file ripper.c.

References Qtrue, and TypedData_Get_Struct.

VALUE rb_parser_set_yydebug ( VALUE  ,
VALUE   
)

Definition at line 16211 of file ripper.c.

References RTEST, and TypedData_Get_Struct.

Referenced by process_options().

NODE* rb_parser_while_loop ( VALUE  ,
NODE ,
int  ,
int   
)
void rb_stdio_set_default_encoding ( void   ) 

Definition at line 8650 of file io.c.

References rb_io_set_encoding(), rb_stderr, rb_stdin, and rb_stdout.

Referenced by process_options().

VALUE rb_vm_top_self ( void   ) 

Definition at line 2158 of file vm.c.

References GET_VM.

static void require_libraries ( VALUE req_list  )  [static]
static VALUE restore_lineno ( VALUE  lineno  )  [static]

Definition at line 1632 of file ruby.c.

References rb_gv_set().

Referenced by load_file().

const char* ruby_get_inplace_mode ( void   ) 

Definition at line 9588 of file io.c.

References ARGF.

void ruby_incpush ( const char *  path  ) 

Definition at line 290 of file ruby.c.

References locale_path(), and ruby_push_include().

void ruby_incpush_expand ( const char *  path  ) 

Definition at line 307 of file ruby.c.

References expand_include_path(), and ruby_push_include().

Referenced by proc_options().

static void ruby_init_gems ( int  enable  )  [static]

Definition at line 1096 of file ruby.c.

References Init_prelude(), rb_cObject, rb_const_remove(), rb_define_module(), and rb_intern_const.

Referenced by process_options().

void ruby_init_loadpath ( void   ) 

Definition at line 333 of file ruby.c.

References ruby_init_loadpath_safe().

void ruby_init_loadpath_safe ( int  safe_level  ) 
void* ruby_process_options ( int  argc,
char **  argv 
)
void ruby_prog_init ( void   ) 
void ruby_push_include ( const char *  path,
VALUE(*)(VALUE filter 
)

Definition at line 270 of file ruby.c.

References push_include().

Referenced by ruby_incpush(), ruby_incpush_expand(), and ruby_init_loadpath_safe().

void ruby_script ( const char *  name  ) 

Definition at line 1763 of file ruby.c.

References rb_external_str_new(), rb_obj_freeze(), rb_progname, and rb_vm_set_progname().

Referenced by ruby_process_options().

void ruby_set_argv ( int  argc,
char **  argv 
)

Definition at line 1837 of file ruby.c.

References OBJ_FREEZE, origarg, rb_ary_clear(), rb_ary_push(), and rb_external_str_new().

Referenced by process_options().

void ruby_set_inplace_mode ( const char *   ) 

Definition at line 9594 of file io.c.

References ARGF, free, and strdup.

Referenced by proc_options().

void ruby_sysinit ( int *  argc,
char ***  argv 
)

Definition at line 1871 of file ruby.c.

References get_arglen(), origarg, and rb_w32_sysinit().

Referenced by main().

static void set_arg0 ( VALUE  val,
ID  id 
) [static]
static void set_option_encoding_once ( const char *  type,
VALUE name,
const char *  e,
long  elen 
) [static]

Definition at line 669 of file ruby.c.

References INT2FIX, rb_eRuntimeError, rb_funcall(), rb_intern, rb_raise(), rb_str_new(), and RSTRING_PTR.

static VALUE true_value ( void   )  [static]

Definition at line 1128 of file ruby.c.

static void usage ( const char *  name  )  [static]

Definition at line 130 of file ruby.c.

References NULL.

Referenced by dump_option(), proc_options(), and process_options().

static VALUE uscore_get ( void   )  [static]

Definition at line 1137 of file ruby.c.

References NIL_P, rb_eTypeError, rb_lastline_get(), rb_obj_classname(), rb_raise(), T_STRING, and TYPE.

Referenced by rb_f_chomp(), rb_f_chop(), rb_f_gsub(), and rb_f_sub().

static void verbose_setter ( VALUE  val,
ID  id,
void *  data 
) [static]

Definition at line 1799 of file ruby.c.

References Qtrue, and RTEST.

Referenced by ruby_prog_init().


Variable Documentation

int argc
char** argv
char** environ

Definition at line 6 of file missing-pips.c.

size_t len

Definition at line 125 of file ruby.c.

struct { ... } origarg [static]

Definition at line 1119 of file ruby.c.