Ruby 2.0.0p247(2013-06-27revision41674)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

Data Structures | Macros | Enumerations | Functions | Variables
load.c File Reference
`#include "ruby/ruby.h"`
`#include "ruby/util.h"`
`#include "internal.h"`
`#include "dln.h"`
`#include "eval_intern.h"`
`#include "probes.h"`
Include dependency graph for load.c:

Go to the source code of this file.

## Data Structures
struct | loaded_feature_searching

## Macros
#define | numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
#define | IS_RBEXT(e) (strcmp((e), ".rb") == 0)
#define | IS_SOEXT(e) (strcmp((e), ".so") == 0 || strcmp((e), ".o") == 0)
#define | IS_DLEXT(e) (strcmp((e), DLEXT) == 0)
#define | rb_intern(str) rb_intern2((str), strlen(str))

## Enumerations
enum | expand_type { EXPAND_ALL, EXPAND_RELATIVE, EXPAND_HOME, EXPAND_NON_CACHE }

## Functions
VALUE | rb_get_load_path (void)
static void | rb_construct_expanded_load_path (int type, int *has_relative, int *has_non_cache)
static VALUE | load_path_getcwd (void)
VALUE | rb_get_expanded_load_path (void)
static VALUE | load_path_getter (ID id, rb_vm_t *vm)
static VALUE | get_loaded_features (void)
static void | reset_loaded_features_snapshot (void)
static struct st_table * | get_loaded_features_index_raw (void)
static st_table * | get_loading_table (void)
static void | features_index_add_single (VALUE short_feature, VALUE offset)
static void | features_index_add (VALUE feature, VALUE offset)
static int | loaded_features_index_clear_i (st_data_t key, st_data_t val, st_data_t arg)
static st_table * | get_loaded_features_index (void)
static VALUE | loaded_feature_path (const char *name, long vlen, const char *feature, long len, int type, VALUE load_path)
static int | loaded_feature_path_i (st_data_t v, st_data_t b, st_data_t f)
static int | rb_feature_p (const char *feature, const char *ext, int rb, int expanded, const char **fn)
int | rb_provided (const char *feature)
int | rb_feature_provided (const char *feature, const char **loading)
static void | rb_provide_feature (VALUE feature)
void | rb_provide (const char *feature)
| NORETURN (static void load_failed(VALUE))
static void | rb_load_internal (VALUE fname, int wrap)
void | rb_load (VALUE fname, int wrap)
void | rb_load_protect (VALUE fname, int wrap, int *state)
static VALUE | rb_f_load (int argc, VALUE *argv)
static char * | load_lock (const char *ftptr)
static int | release_thread_shield (st_data_t *key, st_data_t *value, st_data_t done, int existing)
static void | load_unlock (const char *ftptr, int done)
VALUE | rb_f_require (VALUE obj, VALUE fname)
VALUE | rb_f_require_relative (VALUE obj, VALUE fname)
static int | search_required (VALUE fname, volatile VALUE *path, int safe_level)
static void | load_failed (VALUE fname)
static VALUE | load_ext (VALUE path)
VALUE | rb_require_safe (VALUE fname, int safe)
VALUE | rb_require (const char *fname)
static VALUE | init_ext_call (VALUE arg)
RUBY_FUNC_EXPORTED void | ruby_init_ext (const char *name, void(*init)(void))
static VALUE | rb_mod_autoload (VALUE mod, VALUE sym, VALUE file)
static VALUE | rb_mod_autoload_p (VALUE mod, VALUE sym)
static VALUE | rb_f_autoload (VALUE obj, VALUE sym, VALUE file)
static VALUE | rb_f_autoload_p (VALUE obj, VALUE sym)
void | Init_load ()

## Variables
VALUE | ruby_dln_librefs
static const char *const | loadable_ext []

## Macro Definition Documentation

#define IS_DLEXT | ( |  | e) |  | (strcmp((e), DLEXT) == 0)

Definition at line 21 of file load.c.

Referenced by loaded_feature_path(), rb_feature_p(), rb_feature_provided(), and search_required().

#define IS_RBEXT | ( |  | e) |  | (strcmp((e), ".rb") == 0)

Definition at line 16 of file load.c.

Referenced by loaded_feature_path(), rb_feature_p(), rb_feature_provided(), and search_required().

#define IS_SOEXT | ( |  | e) |  | (strcmp((e), ".so") == 0 || strcmp((e), ".o") == 0)

Definition at line 17 of file load.c.

Referenced by rb_feature_p(), rb_feature_provided(), and search_required().

#define numberof | ( |  | array) |  | (int)(sizeof(array) / sizeof((array)[0]))

Definition at line 14 of file load.c.

Referenced by features_index_add_single().

#define rb_intern | ( |  | str) |  | rb_intern2((str), strlen(str))

## Enumeration Type Documentation

enum expand_type

Enumerator
EXPAND_ALL |
EXPAND_RELATIVE |
EXPAND_HOME |
EXPAND_NON_CACHE |

Definition at line 39 of file load.c.

## Function Documentation

static void features_index_add | ( | VALUE | feature,
|  | VALUE | offset
| ) |  |
| static

Definition at line 226 of file load.c.

References features_index_add_single(), NULL, p, rb_str_subseq(), RSTRING_LEN, and StringValuePtr.

Referenced by get_loaded_features_index(), and rb_provide_feature().

static void features_index_add_single | ( | VALUE | short_feature,
|  | VALUE | offset
| ) |  |
| static

Definition at line 187 of file load.c.

References Check_Type, get_loaded_features_index_raw(), NIL_P, numberof, Qnil, rb_ary_cat(), rb_ary_push(), rb_ary_tmp_new(), RB_TYPE_P, ruby_strdup(), st_insert(), st_lookup(), StringValueCStr, T_ARRAY, T_FIXNUM, and T_STRING.

Referenced by features_index_add().

static VALUE get_loaded_features | ( | void | ) |  |
| static

Definition at line 162 of file load.c.

References GET_VM.

Referenced by Init_load(), rb_feature_p(), and rb_provide_feature().

static st_table* get_loaded_features_index | ( | void | ) |  |
| static

Definition at line 272 of file load.c.

References features_index_add(), GET_VM, i, INT2FIX, rb_vm_struct::loaded_features, rb_vm_struct::loaded_features_index, loaded_features_index_clear_i(), rb_vm_struct::loaded_features_snapshot, RARRAY_LEN, rb_ary_entry(), rb_ary_shared_with_p(), rb_ary_store(), rb_str_freeze(), reset_loaded_features_snapshot(), st_foreach(), and StringValue.

Referenced by rb_feature_p().

static struct st_table* get_loaded_features_index_raw | ( | void | ) |  |
| static

Definition at line 175 of file load.c.

References GET_VM.

Referenced by features_index_add_single().

static st_table* get_loading_table | ( | void | ) |  |
| static

Definition at line 181 of file load.c.

References GET_VM.

Referenced by load_lock(), load_unlock(), and rb_feature_p().

static VALUE init_ext_call | ( | VALUE | arg) |  |
| static

Definition at line 1005 of file load.c.

References arg, NOEX_PUBLIC, Qnil, and SCOPE_SET.

Referenced by ruby_init_ext().

void Init_load | ( | ) |  |

Definition at line 1115 of file load.c.

References rb_vm_struct::expanded_load_path, get_loaded_features(), GET_VM, rb_vm_struct::load_path, rb_vm_struct::load_path_check_cache, load_path_getter(), rb_vm_struct::load_path_snapshot, rb_vm_struct::loaded_features, rb_vm_struct::loaded_features_index, rb_vm_struct::loaded_features_snapshot, rb_alias_variable(), rb_ary_new(), rb_ary_tmp_new(), rb_cModule, rb_define_global_function(), rb_define_hooked_variable(), rb_define_method(), rb_define_virtual_variable(), rb_f_autoload(), rb_f_autoload_p(), rb_f_load(), rb_f_require(), rb_f_require_relative(), rb_gc_register_mark_object(), rb_gvar_readonly_setter(), rb_intern, rb_intern2(), rb_mod_autoload(), rb_mod_autoload_p(), ruby_dln_librefs, and st_init_strtable().

static VALUE load_ext | ( | VALUE | path) |  |
| static

Definition at line 904 of file load.c.

References dln_load(), NOEX_PUBLIC, RSTRING_PTR, and SCOPE_SET.

Referenced by rb_require_safe().

static void load_failed | ( | VALUE | fname) |  |
| static

Definition at line 898 of file load.c.

References rb_load_fail().

Referenced by rb_f_load(), rb_load(), and rb_require_safe().

static char* load_lock | ( | const char * | ftptr) |  |
| static

Definition at line 692 of file load.c.

References get_loading_table(), GET_VM, Qfalse, Qnil, rb_backtrace(), rb_thread_shield_new(), rb_thread_shield_wait(), rb_warning(), RTEST, ruby_strdup(), ruby_verbose, st_init_strtable(), st_insert(), and st_lookup().

Referenced by rb_require_safe(), and ruby_init_ext().

static VALUE load_path_getcwd | ( | void | ) |  |
| static

Definition at line 101 of file load.c.

References my_getcwd, rb_filesystem_str_new_cstr(), and xfree.

Referenced by rb_get_expanded_load_path().

static VALUE load_path_getter | ( | ID | id,
|  | rb_vm_t * | vm
| ) |  |
| static

Definition at line 156 of file load.c.

References rb_vm_struct::load_path.

Referenced by Init_load().

static void load_unlock | ( | const char * | ftptr,
|  | int | done
| ) |  |
| static

Definition at line 738 of file load.c.

References get_loading_table(), key, release_thread_shield(), and st_update().

Referenced by rb_require_safe(), and ruby_init_ext().

static VALUE loaded_feature_path | ( | const char * | name,
|  | long | vlen,
|  | const char * | feature,
|  | long | len,
|  | int | type,
|  | VALUE | load_path
| ) |  |
| static

Definition at line 309 of file load.c.

References i, IS_DLEXT, IS_RBEXT, p, RARRAY_LEN, RARRAY_PTR, RSTRING_LEN, and StringValuePtr.

Referenced by loaded_feature_path_i(), and rb_feature_p().

static int loaded_feature_path_i | ( | st_data_t | v,
|  | st_data_t | b,
|  | st_data_t | f
| ) |  |
| static

Definition at line 361 of file load.c.

References loaded_feature_searching::len, loaded_feature_searching::load_path, loaded_feature_path(), loaded_feature_searching::name, p, loaded_feature_searching::result, ST_CONTINUE, ST_STOP, strlen(), and loaded_feature_searching::type.

Referenced by rb_feature_p().

static int loaded_features_index_clear_i | ( | st_data_t | key,
|  | st_data_t | val,
|  | st_data_t | arg
| ) |  |
| static

Definition at line 265 of file load.c.

References ST_DELETE, and xfree.

Referenced by get_loaded_features_index().

NORETURN | ( | static void | load_failedVALUE) |  |

static void rb_construct_expanded_load_path | ( | int | type,
|  | int * | has_relative,
|  | int * | has_non_cache
| ) |  |
| static

Definition at line 52 of file load.c.

References EXPAND_HOME, EXPAND_NON_CACHE, EXPAND_RELATIVE, rb_vm_struct::expanded_load_path, GET_VM, i, level, rb_vm_struct::load_path, rb_vm_struct::load_path_snapshot, Qnil, RARRAY_LEN, RARRAY_PTR, rb_ary_push(), rb_ary_replace(), rb_ary_tmp_new(), rb_file_expand_path_fast(), rb_get_path_check_convert(), rb_get_path_check_to_string(), rb_is_absolute_path(), rb_obj_freeze(), rb_safe_level, rb_str_freeze(), RB_TYPE_P, RSTRING_PTR, and T_STRING.

Referenced by rb_get_expanded_load_path().

static VALUE rb_f_autoload | ( | VALUE | obj,
|  | VALUE | sym,
|  | VALUE | file
| ) |  |
| static

Definition at line 1083 of file load.c.

References NIL_P, rb_class_real(), rb_eTypeError, rb_mod_autoload(), rb_raise(), and rb_vm_cbase().

Referenced by Init_load().

static VALUE rb_f_autoload_p | ( | VALUE | obj,
|  | VALUE | sym
| ) |  |
| static

Definition at line 1104 of file load.c.

References NIL_P, Qnil, rb_mod_autoload_p(), and rb_vm_cbase().

Referenced by Init_load().

static VALUE rb_f_load | ( | int | argc,
|  | VALUE * | argv
| ) |  |
| static

Definition at line 662 of file load.c.

References FilePathValue, load_failed(), Qtrue, rb_file_load_ok(), rb_find_file(), rb_load_internal(), rb_scan_args(), rb_sourcefile, rb_sourceline(), RSTRING_PTR, RTEST, RUBY_DTRACE_LOAD_ENTRY, RUBY_DTRACE_LOAD_ENTRY_ENABLED, RUBY_DTRACE_LOAD_RETURN, RUBY_DTRACE_LOAD_RETURN_ENABLED, and StringValuePtr.

Referenced by Init_load().

VALUE rb_f_require | ( | VALUE | obj,
|  | VALUE | fname
| ) |  |

Definition at line 786 of file load.c.

References rb_require_safe(), and rb_safe_level.

Referenced by Init_load().

VALUE rb_f_require_relative | ( | VALUE | obj,
|  | VALUE | fname
| ) |  |

Definition at line 800 of file load.c.

References NIL_P, rb_current_realfilepath(), rb_file_absolute_path(), rb_file_dirname(), rb_loaderror(), rb_require_safe(), and rb_safe_level.

Referenced by Init_load().

static int rb_feature_p | ( | const char * | feature,
|  | const char * | ext,
|  | int | rb,
|  | int | expanded,
|  | const char ** | fn
| ) |  |
| static

Definition at line 373 of file load.c.

References buf, DLEXT_MAXLEN, f, FIX2LONG, get_loaded_features(), get_loaded_features_index(), get_loading_table(), i, IS_DLEXT, IS_RBEXT, IS_SOEXT, loaded_feature_searching::len, loaded_feature_searching::load_path, loadable_ext, loaded_feature_path(), loaded_feature_path_i(), MEMCPY, loaded_feature_searching::name, NIL_P, p, Qnil, RARRAY_LEN, RARRAY_PTR, rb_get_expanded_load_path(), rb_str_resize(), rb_str_tmp_new(), RB_TYPE_P, loaded_feature_searching::result, RSTRING_LEN, RSTRING_PTR, st_foreach(), st_get_key(), st_lookup(), StringValuePtr, strlcpy(), strlen(), T_ARRAY, type, loaded_feature_searching::type, and v.

Referenced by rb_feature_provided(), and search_required().

int rb_feature_provided | ( | const char * | feature,
|  | const char ** | loading
| ) |  |

Definition at line 511 of file load.c.

References FALSE, IS_DLEXT, IS_RBEXT, IS_SOEXT, Qnil, rb_feature_p(), rb_file_expand_path_fast(), rb_get_path(), rb_str_new2, RSTRING_PTR, strchr(), strrchr(), and TRUE.

Referenced by autoload_provided(), and rb_provided().

VALUE rb_get_expanded_load_path | ( | void | ) |  |

Definition at line 110 of file load.c.

References EXPAND_ALL, EXPAND_HOME, EXPAND_NON_CACHE, EXPAND_RELATIVE, rb_vm_struct::expanded_load_path, GET_VM, rb_vm_struct::load_path, rb_vm_struct::load_path_check_cache, load_path_getcwd(), rb_vm_struct::load_path_snapshot, Qtrue, rb_ary_shared_with_p(), rb_construct_expanded_load_path(), and rb_str_equal().

Referenced by rb_feature_p(), rb_find_file_ext_safe(), and rb_find_file_safe().

VALUE rb_get_load_path | ( | void | ) |  |

Definition at line 33 of file load.c.

References GET_VM.

void rb_load | ( | VALUE | fname,
|  | int | wrap
| ) |  |

Definition at line 626 of file load.c.

References FilePathValue, load_failed(), rb_find_file(), and rb_load_internal().

Referenced by rb_load_protect().

static void rb_load_internal | ( | VALUE | fname,
|  | int | wrap
| ) |  |
| static

Definition at line 562 of file load.c.

References rb_thread_struct::errinfo, EXEC_TAG, FALSE, FIXNUM_P, GET_THREAD(), rb_thread_struct::mild_compile_error, NIL_P, POP_TAG, PUSH_TAG, Qfalse, Qnil, rb_exc_raise(), rb_extend_object(), RB_GC_GUARD, rb_iseq_eval(), rb_iseq_new_top(), rb_load_file(), rb_module_new(), rb_obj_clone(), rb_realpath_internal(), rb_secure(), rb_str_new2, rb_vm_jump_tag_but_local_jump(), rb_vm_top_self(), RSTRING_PTR, rb_thread_struct::top_self, rb_thread_struct::top_wrapper, and TRUE.

Referenced by rb_f_load(), rb_load(), and rb_require_safe().

void rb_load_protect | ( | VALUE | fname,
|  | int | wrap,
|  | int * | state
| ) |  |

Definition at line 634 of file load.c.

References EXEC_TAG, POP_TAG, PUSH_TAG, and rb_load().

static VALUE rb_mod_autoload | ( | VALUE | mod,
|  | VALUE | sym,
|  | VALUE | file
| ) |  |
| static

Definition at line 1039 of file load.c.

References FilePathValue, Qnil, rb_autoload(), rb_to_id(), and RSTRING_PTR.

Referenced by Init_load(), and rb_f_autoload().

static VALUE rb_mod_autoload_p | ( | VALUE | mod,
|  | VALUE | sym
| ) |  |
| static

Definition at line 1062 of file load.c.

References Qnil, rb_autoload_p(), and rb_check_id().

Referenced by Init_load(), and rb_f_autoload_p().

void rb_provide | ( | const char * | feature) |  |

Definition at line 554 of file load.c.

References rb_provide_feature(), and rb_usascii_str_new2.

Referenced by InitVM_Enumerator(), and ruby_init_ext().

static void rb_provide_feature | ( | VALUE | feature) |  |
| static

Definition at line 537 of file load.c.

References features_index_add(), get_loaded_features(), INT2FIX, OBJ_FROZEN, RARRAY_LEN, rb_ary_push(), rb_eRuntimeError, rb_raise(), rb_str_freeze(), and reset_loaded_features_snapshot().

Referenced by rb_provide(), and rb_require_safe().

int rb_provided | ( | const char * | feature) |  |

Definition at line 505 of file load.c.

References rb_feature_provided().

VALUE rb_require | ( | const char * | fname) |  |

Definition at line 997 of file load.c.

References OBJ_FREEZE, rb_require_safe(), rb_safe_level, and rb_str_new2.

Referenced by Init_bubblebabble(), Init_generator(), Init_md5(), Init_ossl_digest(), Init_parser(), Init_psych_parser(), Init_rmd160(), Init_sha1(), Init_sha2(), Init_tkutil(), and process_options().

VALUE rb_require_safe | ( | VALUE | fname,
|  | int | safe
| ) |  |

Definition at line 911 of file load.c.

References rb_thread_struct::errinfo, EXEC_TAG, FilePathValue, GET_THREAD(), JUMP_TAG, load_ext(), load_failed(), load_lock(), load_unlock(), LONG2NUM, NIL_P, POP_TAG, PUSH_TAG, Qfalse, Qnil, Qtrue, rb_ary_push(), rb_load_internal(), rb_provide_feature(), rb_safe_level, rb_set_safe_level_force(), rb_sourcefile, rb_sourceline(), rb_vm_call_cfunc(), rb_vm_top_self(), result, RSTRING_PTR, ruby_dln_librefs, RUBY_DTRACE_FIND_REQUIRE_ENTRY, RUBY_DTRACE_FIND_REQUIRE_ENTRY_ENABLED, RUBY_DTRACE_FIND_REQUIRE_RETURN, RUBY_DTRACE_FIND_REQUIRE_RETURN_ENABLED, RUBY_DTRACE_REQUIRE_ENTRY, RUBY_DTRACE_REQUIRE_ENTRY_ENABLED, RUBY_DTRACE_REQUIRE_RETURN, RUBY_DTRACE_REQUIRE_RETURN_ENABLED, search_required(), and StringValuePtr.

Referenced by autoload_require(), load_transcoder_entry(), rb_f_require(), rb_f_require_relative(), rb_require(), and require_enc().

static int release_thread_shield | ( | st_data_t * | key,
|  | st_data_t * | value,
|  | st_data_t | done,
|  | int | existing
| ) |  |
| static

Definition at line 725 of file load.c.

References rb_thread_shield_destroy(), rb_thread_shield_release(), ST_CONTINUE, ST_DELETE, ST_STOP, and xfree.

Referenced by load_unlock().

static void reset_loaded_features_snapshot | ( | void | ) |  |
| static

Definition at line 168 of file load.c.

References GET_VM, rb_vm_struct::loaded_features, rb_vm_struct::loaded_features_snapshot, and rb_ary_replace().

Referenced by get_loaded_features_index(), and rb_provide_feature().

RUBY_FUNC_EXPORTED void ruby_init_ext | ( | const char * | name,
|  | void(*)(void) | init
| ) |  |

Definition at line 1013 of file load.c.

References init_ext_call(), load_lock(), load_unlock(), rb_provide(), rb_str_new2, rb_vm_call_cfunc(), and rb_vm_top_self().

Referenced by init_golf().

static int search_required | ( | VALUE | fname,
|  | volatile VALUE * | path,
|  | int | safe_level
| ) |  |
| static

Definition at line 811 of file load.c.

References FALSE, IS_DLEXT, IS_RBEXT, IS_SOEXT, loadable_ext, OBJ_FREEZE, rb_feature_p(), rb_filesystem_str_new_cstr(), rb_find_file_ext_safe(), rb_find_file_safe(), rb_str_cat2(), rb_str_subseq(), RSTRING_PTR, strchr(), strrchr(), TRUE, and type.

Referenced by rb_require_safe().

## Variable Documentation

const char* const loadable_ext[]
| static

Initial value:
= {
".rb", DLEXT,
0
}

Definition at line 24 of file load.c.

Referenced by rb_feature_p(), and search_required().

VALUE ruby_dln_librefs

Definition at line 12 of file load.c.

Referenced by Init_load(), and rb_require_safe().