2006-12-31 18:02:22 +03:00
|
|
|
/*
|
|
|
|
* load methods from eval.c
|
|
|
|
*/
|
|
|
|
|
* common.mk: clean up
- remove blockinlining.$(OBJEXT) to built
- make ENCODING_H_INCLDUES variable (include/ruby/encoding.h)
- make VM_CORE_H_INCLUDES variable (vm_core.h)
- simplify rules.
- make depends rule to output depend status using gcc -MM.
* include/ruby/mvm.h, include/ruby/vm.h: rename mvm.h to vm.h.
* include/ruby.h: ditto.
* load.c: add inclusion explicitly.
* enumerator.c, object.c, parse.y, thread.c, vm_dump.c:
remove useless inclusion.
* eval_intern.h: cleanup inclusion.
* vm_core.h: rb_thread_t should be defined in this file.
* vm_evalbody.c, vm_exec.c: rename vm_evalbody.c to vm_exec.c.
* vm.h, vm_exec.h: rename vm.h to vm_exec.h.
* insnhelper.h, vm_insnhelper.h: rename insnhelper.h to vm_insnhelper.h.
* vm.c, vm_insnhelper.c, vm_insnhelper.h:
- rename vm_eval() to vm_exec_core().
- rename vm_eval_body() to vm_exec().
- cleanup include order.
* vm_method.c: fix comment.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 04:20:28 +04:00
|
|
|
#include "ruby/ruby.h"
|
|
|
|
#include "ruby/util.h"
|
* internal.h: declare internal functions here.
* node.h: declare NODE dependent internal functions here.
* iseq.h: declare rb_iseq_t dependent internal functions here.
* vm_core.h: declare rb_thread_t dependent internal functions here.
* bignum.c, class.c, compile.c, complex.c, cont.c, dir.c, encoding.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c, io.c,
iseq.c, load.c, marshal.c, math.c, numeric.c, object.c, parse.y,
proc.c, process.c, range.c, rational.c, re.c, ruby.c, string.c,
thread.c, time.c, transcode.c, variable.c, vm.c,
tool/compile_prelude.rb: don't declare internal functions declared
in above headers. include above headers if required.
Note that rb_thread_mark() was declared as
void rb_thread_mark(rb_thread_t *th) in cont.c but defined as
void rb_thread_mark(void *ptr) in vm.c. Now it is declared as
the later in internal.h.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-18 02:43:38 +04:00
|
|
|
#include "internal.h"
|
* common.mk: clean up
- remove blockinlining.$(OBJEXT) to built
- make ENCODING_H_INCLDUES variable (include/ruby/encoding.h)
- make VM_CORE_H_INCLUDES variable (vm_core.h)
- simplify rules.
- make depends rule to output depend status using gcc -MM.
* include/ruby/mvm.h, include/ruby/vm.h: rename mvm.h to vm.h.
* include/ruby.h: ditto.
* load.c: add inclusion explicitly.
* enumerator.c, object.c, parse.y, thread.c, vm_dump.c:
remove useless inclusion.
* eval_intern.h: cleanup inclusion.
* vm_core.h: rb_thread_t should be defined in this file.
* vm_evalbody.c, vm_exec.c: rename vm_evalbody.c to vm_exec.c.
* vm.h, vm_exec.h: rename vm.h to vm_exec.h.
* insnhelper.h, vm_insnhelper.h: rename insnhelper.h to vm_insnhelper.h.
* vm.c, vm_insnhelper.c, vm_insnhelper.h:
- rename vm_eval() to vm_exec_core().
- rename vm_eval_body() to vm_exec().
- cleanup include order.
* vm_method.c: fix comment.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-23 04:20:28 +04:00
|
|
|
#include "dln.h"
|
2006-12-31 18:02:22 +03:00
|
|
|
#include "eval_intern.h"
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
#include "probes.h"
|
2013-11-03 04:35:49 +04:00
|
|
|
#include "node.h"
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
VALUE ruby_dln_librefs;
|
|
|
|
|
2011-05-22 16:52:18 +04:00
|
|
|
#define IS_RBEXT(e) (strcmp((e), ".rb") == 0)
|
|
|
|
#define IS_SOEXT(e) (strcmp((e), ".so") == 0 || strcmp((e), ".o") == 0)
|
2006-12-31 18:02:22 +03:00
|
|
|
#ifdef DLEXT2
|
2011-05-22 16:52:18 +04:00
|
|
|
#define IS_DLEXT(e) (strcmp((e), DLEXT) == 0 || strcmp((e), DLEXT2) == 0)
|
2006-12-31 18:02:22 +03:00
|
|
|
#else
|
2011-05-22 16:52:18 +04:00
|
|
|
#define IS_DLEXT(e) (strcmp((e), DLEXT) == 0)
|
2006-12-31 18:02:22 +03:00
|
|
|
#endif
|
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
static const char *const loadable_ext[] = {
|
|
|
|
".rb", DLEXT,
|
|
|
|
#ifdef DLEXT2
|
|
|
|
DLEXT2,
|
|
|
|
#endif
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2008-04-30 13:03:03 +04:00
|
|
|
VALUE
|
|
|
|
rb_get_load_path(void)
|
2007-11-06 10:37:49 +03:00
|
|
|
{
|
2008-04-30 13:03:03 +04:00
|
|
|
VALUE load_path = GET_VM()->load_path;
|
2008-12-04 21:29:20 +03:00
|
|
|
return load_path;
|
2007-11-06 10:37:49 +03:00
|
|
|
}
|
2007-11-06 09:52:01 +03:00
|
|
|
|
2012-11-05 19:27:08 +04:00
|
|
|
enum expand_type {
|
|
|
|
EXPAND_ALL,
|
|
|
|
EXPAND_RELATIVE,
|
|
|
|
EXPAND_HOME,
|
|
|
|
EXPAND_NON_CACHE
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Construct expanded load path and store it to cache.
|
|
|
|
We rebuild load path partially if the cache is invalid.
|
2012-11-07 02:00:12 +04:00
|
|
|
We don't cache non string object and expand it every time. We ensure that
|
2012-11-05 19:27:08 +04:00
|
|
|
string objects in $LOAD_PATH are frozen.
|
|
|
|
*/
|
2012-11-05 19:27:05 +04:00
|
|
|
static void
|
2012-11-05 19:27:08 +04:00
|
|
|
rb_construct_expanded_load_path(int type, int *has_relative, int *has_non_cache)
|
2008-12-12 05:00:55 +03:00
|
|
|
{
|
2012-11-05 19:27:05 +04:00
|
|
|
rb_vm_t *vm = GET_VM();
|
|
|
|
VALUE load_path = vm->load_path;
|
2012-11-05 19:27:08 +04:00
|
|
|
VALUE expanded_load_path = vm->expanded_load_path;
|
2010-03-13 04:34:38 +03:00
|
|
|
VALUE ary;
|
2008-12-12 05:00:55 +03:00
|
|
|
long i;
|
2012-11-05 19:27:08 +04:00
|
|
|
int level = rb_safe_level();
|
2008-12-12 05:00:55 +03:00
|
|
|
|
2013-03-09 04:03:40 +04:00
|
|
|
ary = rb_ary_tmp_new(RARRAY_LEN(load_path));
|
2008-12-12 05:00:55 +03:00
|
|
|
for (i = 0; i < RARRAY_LEN(load_path); ++i) {
|
2012-11-05 19:27:05 +04:00
|
|
|
VALUE path, as_str, expanded_path;
|
2012-11-05 19:27:08 +04:00
|
|
|
int is_string, non_cache;
|
|
|
|
char *as_cstr;
|
2013-05-13 13:56:22 +04:00
|
|
|
as_str = path = RARRAY_AREF(load_path, i);
|
2012-11-05 19:27:08 +04:00
|
|
|
is_string = RB_TYPE_P(path, T_STRING) ? 1 : 0;
|
|
|
|
non_cache = !is_string ? 1 : 0;
|
|
|
|
as_str = rb_get_path_check_to_string(path, level);
|
|
|
|
as_cstr = RSTRING_PTR(as_str);
|
|
|
|
|
|
|
|
if (!non_cache) {
|
|
|
|
if ((type == EXPAND_RELATIVE &&
|
|
|
|
rb_is_absolute_path(as_cstr)) ||
|
|
|
|
(type == EXPAND_HOME &&
|
|
|
|
(!as_cstr[0] || as_cstr[0] != '~')) ||
|
|
|
|
(type == EXPAND_NON_CACHE)) {
|
|
|
|
/* Use cached expanded path. */
|
2013-05-13 13:56:22 +04:00
|
|
|
rb_ary_push(ary, RARRAY_AREF(expanded_load_path, i));
|
2012-11-05 19:27:08 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!*has_relative && !rb_is_absolute_path(as_cstr))
|
|
|
|
*has_relative = 1;
|
|
|
|
if (!*has_non_cache && non_cache)
|
|
|
|
*has_non_cache = 1;
|
2012-11-07 02:00:12 +04:00
|
|
|
/* Freeze only string object. We expand other objects every time. */
|
2012-11-05 19:27:08 +04:00
|
|
|
if (is_string)
|
|
|
|
rb_str_freeze(path);
|
|
|
|
as_str = rb_get_path_check_convert(path, as_str, level);
|
2012-11-05 19:27:05 +04:00
|
|
|
expanded_path = rb_file_expand_path_fast(as_str, Qnil);
|
|
|
|
rb_str_freeze(expanded_path);
|
|
|
|
rb_ary_push(ary, expanded_path);
|
2008-12-12 05:00:55 +03:00
|
|
|
}
|
|
|
|
rb_obj_freeze(ary);
|
2012-11-05 19:27:05 +04:00
|
|
|
vm->expanded_load_path = ary;
|
|
|
|
rb_ary_replace(vm->load_path_snapshot, vm->load_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2012-11-05 19:27:08 +04:00
|
|
|
load_path_getcwd(void)
|
|
|
|
{
|
|
|
|
char *cwd = my_getcwd();
|
|
|
|
VALUE cwd_str = rb_filesystem_str_new_cstr(cwd);
|
|
|
|
xfree(cwd);
|
|
|
|
return cwd_str;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
2012-11-05 19:27:05 +04:00
|
|
|
rb_get_expanded_load_path(void)
|
|
|
|
{
|
|
|
|
rb_vm_t *vm = GET_VM();
|
2012-11-05 19:27:08 +04:00
|
|
|
const VALUE non_cache = Qtrue;
|
|
|
|
|
2012-11-05 19:27:05 +04:00
|
|
|
if (!rb_ary_shared_with_p(vm->load_path_snapshot, vm->load_path)) {
|
2012-11-05 19:27:08 +04:00
|
|
|
/* The load path was modified. Rebuild the expanded load path. */
|
|
|
|
int has_relative = 0, has_non_cache = 0;
|
|
|
|
rb_construct_expanded_load_path(EXPAND_ALL, &has_relative, &has_non_cache);
|
|
|
|
if (has_relative) {
|
|
|
|
vm->load_path_check_cache = load_path_getcwd();
|
|
|
|
}
|
|
|
|
else if (has_non_cache) {
|
|
|
|
/* Non string object. */
|
|
|
|
vm->load_path_check_cache = non_cache;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
vm->load_path_check_cache = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (vm->load_path_check_cache == non_cache) {
|
|
|
|
int has_relative = 1, has_non_cache = 1;
|
|
|
|
/* Expand only non-cacheable objects. */
|
|
|
|
rb_construct_expanded_load_path(EXPAND_NON_CACHE,
|
|
|
|
&has_relative, &has_non_cache);
|
|
|
|
}
|
|
|
|
else if (vm->load_path_check_cache) {
|
|
|
|
int has_relative = 1, has_non_cache = 1;
|
|
|
|
VALUE cwd = load_path_getcwd();
|
|
|
|
if (!rb_str_equal(vm->load_path_check_cache, cwd)) {
|
|
|
|
/* Current working directory or filesystem encoding was changed.
|
|
|
|
Expand relative load path and non-cacheable objects again. */
|
|
|
|
vm->load_path_check_cache = cwd;
|
|
|
|
rb_construct_expanded_load_path(EXPAND_RELATIVE,
|
|
|
|
&has_relative, &has_non_cache);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Expand only tilde (User HOME) and non-cacheable objects. */
|
|
|
|
rb_construct_expanded_load_path(EXPAND_HOME,
|
|
|
|
&has_relative, &has_non_cache);
|
|
|
|
}
|
2012-11-05 19:27:05 +04:00
|
|
|
}
|
|
|
|
return vm->expanded_load_path;
|
2008-12-12 05:00:55 +03:00
|
|
|
}
|
|
|
|
|
2008-04-30 13:03:03 +04:00
|
|
|
static VALUE
|
|
|
|
load_path_getter(ID id, rb_vm_t *vm)
|
|
|
|
{
|
|
|
|
return vm->load_path;
|
|
|
|
}
|
|
|
|
|
2007-02-14 05:19:02 +03:00
|
|
|
static VALUE
|
|
|
|
get_loaded_features(void)
|
|
|
|
{
|
|
|
|
return GET_VM()->loaded_features;
|
|
|
|
}
|
|
|
|
|
2012-11-05 19:27:01 +04:00
|
|
|
static void
|
|
|
|
reset_loaded_features_snapshot(void)
|
|
|
|
{
|
|
|
|
rb_vm_t *vm = GET_VM();
|
|
|
|
rb_ary_replace(vm->loaded_features_snapshot, vm->loaded_features);
|
|
|
|
}
|
|
|
|
|
2013-03-22 12:38:51 +04:00
|
|
|
static struct st_table *
|
2012-11-05 19:27:01 +04:00
|
|
|
get_loaded_features_index_raw(void)
|
|
|
|
{
|
|
|
|
return GET_VM()->loaded_features_index;
|
|
|
|
}
|
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
static st_table *
|
|
|
|
get_loading_table(void)
|
|
|
|
{
|
|
|
|
return GET_VM()->loading_table;
|
|
|
|
}
|
|
|
|
|
2012-11-05 19:27:01 +04:00
|
|
|
static void
|
|
|
|
features_index_add_single(VALUE short_feature, VALUE offset)
|
|
|
|
{
|
2013-03-22 12:38:51 +04:00
|
|
|
struct st_table *features_index;
|
|
|
|
VALUE this_feature_index = Qnil;
|
|
|
|
char *short_feature_cstr;
|
|
|
|
|
|
|
|
Check_Type(offset, T_FIXNUM);
|
|
|
|
Check_Type(short_feature, T_STRING);
|
|
|
|
short_feature_cstr = StringValueCStr(short_feature);
|
|
|
|
|
2012-11-05 19:27:01 +04:00
|
|
|
features_index = get_loaded_features_index_raw();
|
2013-03-22 12:38:51 +04:00
|
|
|
st_lookup(features_index, (st_data_t)short_feature_cstr, (st_data_t *)&this_feature_index);
|
2013-03-09 03:37:02 +04:00
|
|
|
|
|
|
|
if (NIL_P(this_feature_index)) {
|
2013-03-22 12:38:51 +04:00
|
|
|
st_insert(features_index, (st_data_t)ruby_strdup(short_feature_cstr), (st_data_t)offset);
|
2013-03-09 03:37:02 +04:00
|
|
|
}
|
|
|
|
else if (RB_TYPE_P(this_feature_index, T_FIXNUM)) {
|
|
|
|
VALUE feature_indexes[2];
|
|
|
|
feature_indexes[0] = this_feature_index;
|
|
|
|
feature_indexes[1] = offset;
|
2013-12-03 12:13:31 +04:00
|
|
|
this_feature_index = (VALUE)xcalloc(1, sizeof(struct RArray));
|
|
|
|
RBASIC(this_feature_index)->flags = T_ARRAY; /* fake VALUE, do not mark/sweep */
|
2013-03-09 03:37:02 +04:00
|
|
|
rb_ary_cat(this_feature_index, feature_indexes, numberof(feature_indexes));
|
2013-03-22 12:38:51 +04:00
|
|
|
st_insert(features_index, (st_data_t)short_feature_cstr, (st_data_t)this_feature_index);
|
2012-11-05 19:27:01 +04:00
|
|
|
}
|
2013-03-09 03:37:02 +04:00
|
|
|
else {
|
|
|
|
Check_Type(this_feature_index, T_ARRAY);
|
|
|
|
rb_ary_push(this_feature_index, offset);
|
|
|
|
}
|
2012-11-05 19:27:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add to the loaded-features index all the required entries for
|
|
|
|
`feature`, located at `offset` in $LOADED_FEATURES. We add an
|
|
|
|
index entry at each string `short_feature` for which
|
|
|
|
feature == "#{prefix}#{short_feature}#{e}"
|
|
|
|
where `e` is empty or matches %r{^\.[^./]*$}, and `prefix` is empty
|
|
|
|
or ends in '/'. This maintains the invariant that `rb_feature_p()`
|
|
|
|
relies on for its fast lookup.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
features_index_add(VALUE feature, VALUE offset)
|
|
|
|
{
|
|
|
|
VALUE short_feature;
|
|
|
|
const char *feature_str, *feature_end, *ext, *p;
|
|
|
|
|
|
|
|
feature_str = StringValuePtr(feature);
|
|
|
|
feature_end = feature_str + RSTRING_LEN(feature);
|
|
|
|
|
|
|
|
for (ext = feature_end; ext > feature_str; ext--)
|
|
|
|
if (*ext == '.' || *ext == '/')
|
|
|
|
break;
|
|
|
|
if (*ext != '.')
|
|
|
|
ext = NULL;
|
|
|
|
/* Now `ext` points to the only string matching %r{^\.[^./]*$} that is
|
|
|
|
at the end of `feature`, or is NULL if there is no such string. */
|
|
|
|
|
|
|
|
p = ext ? ext : feature_end;
|
|
|
|
while (1) {
|
|
|
|
p--;
|
|
|
|
while (p >= feature_str && *p != '/')
|
|
|
|
p--;
|
|
|
|
if (p < feature_str)
|
|
|
|
break;
|
|
|
|
/* Now *p == '/'. We reach this point for every '/' in `feature`. */
|
2013-04-05 19:30:52 +04:00
|
|
|
short_feature = rb_str_subseq(feature, p + 1 - feature_str, feature_end - p - 1);
|
2012-11-05 19:27:01 +04:00
|
|
|
features_index_add_single(short_feature, offset);
|
|
|
|
if (ext) {
|
2013-04-05 19:30:52 +04:00
|
|
|
short_feature = rb_str_subseq(feature, p + 1 - feature_str, ext - p - 1);
|
2012-11-05 19:27:01 +04:00
|
|
|
features_index_add_single(short_feature, offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
features_index_add_single(feature, offset);
|
|
|
|
if (ext) {
|
2013-04-05 19:30:52 +04:00
|
|
|
short_feature = rb_str_subseq(feature, 0, ext - feature_str);
|
2012-11-05 19:27:01 +04:00
|
|
|
features_index_add_single(short_feature, offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-22 12:38:51 +04:00
|
|
|
static int
|
|
|
|
loaded_features_index_clear_i(st_data_t key, st_data_t val, st_data_t arg)
|
|
|
|
{
|
2013-12-03 12:13:31 +04:00
|
|
|
VALUE obj = (VALUE)val;
|
|
|
|
if (!SPECIAL_CONST_P(obj)) {
|
|
|
|
rb_ary_free(obj);
|
|
|
|
xfree((void *)obj);
|
|
|
|
}
|
2013-03-22 12:38:51 +04:00
|
|
|
xfree((char *)key);
|
|
|
|
return ST_DELETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static st_table *
|
2012-11-05 19:27:01 +04:00
|
|
|
get_loaded_features_index(void)
|
|
|
|
{
|
|
|
|
VALUE features;
|
|
|
|
int i;
|
|
|
|
rb_vm_t *vm = GET_VM();
|
|
|
|
|
|
|
|
if (!rb_ary_shared_with_p(vm->loaded_features_snapshot, vm->loaded_features)) {
|
|
|
|
/* The sharing was broken; something (other than us in rb_provide_feature())
|
|
|
|
modified loaded_features. Rebuild the index. */
|
2013-03-22 12:38:51 +04:00
|
|
|
st_foreach(vm->loaded_features_index, loaded_features_index_clear_i, 0);
|
2012-11-05 19:27:01 +04:00
|
|
|
features = vm->loaded_features;
|
|
|
|
for (i = 0; i < RARRAY_LEN(features); i++) {
|
|
|
|
VALUE entry, as_str;
|
|
|
|
as_str = entry = rb_ary_entry(features, i);
|
|
|
|
StringValue(as_str);
|
|
|
|
if (as_str != entry)
|
|
|
|
rb_ary_store(features, i, as_str);
|
|
|
|
rb_str_freeze(as_str);
|
|
|
|
features_index_add(as_str, INT2FIX(i));
|
|
|
|
}
|
|
|
|
reset_loaded_features_snapshot();
|
|
|
|
}
|
|
|
|
return vm->loaded_features_index;
|
|
|
|
}
|
|
|
|
|
2012-11-05 19:24:03 +04:00
|
|
|
/* This searches `load_path` for a value such that
|
|
|
|
name == "#{load_path[i]}/#{feature}"
|
|
|
|
if `feature` is a suffix of `name`, or otherwise
|
|
|
|
name == "#{load_path[i]}/#{feature}#{ext}"
|
|
|
|
for an acceptable string `ext`. It returns
|
|
|
|
`load_path[i].to_str` if found, else 0.
|
|
|
|
|
|
|
|
If type is 's', then `ext` is acceptable only if IS_DLEXT(ext);
|
|
|
|
if 'r', then only if IS_RBEXT(ext); otherwise `ext` may be absent
|
|
|
|
or have any value matching `%r{^\.[^./]*$}`.
|
|
|
|
*/
|
2007-11-06 09:52:01 +03:00
|
|
|
static VALUE
|
2007-11-06 10:37:49 +03:00
|
|
|
loaded_feature_path(const char *name, long vlen, const char *feature, long len,
|
2007-11-09 06:56:38 +03:00
|
|
|
int type, VALUE load_path)
|
2007-11-06 09:52:01 +03:00
|
|
|
{
|
|
|
|
long i;
|
2011-06-01 01:56:01 +04:00
|
|
|
long plen;
|
|
|
|
const char *e;
|
|
|
|
|
2012-11-05 19:24:07 +04:00
|
|
|
if (vlen < len+1) return 0;
|
2012-10-29 13:31:50 +04:00
|
|
|
if (!strncmp(name+(vlen-len), feature, len)) {
|
2013-05-23 12:35:34 +04:00
|
|
|
plen = vlen - len;
|
2012-10-29 13:31:50 +04:00
|
|
|
}
|
|
|
|
else {
|
2011-06-01 01:56:01 +04:00
|
|
|
for (e = name + vlen; name != e && *e != '.' && *e != '/'; --e);
|
2012-10-29 13:31:50 +04:00
|
|
|
if (*e != '.' ||
|
2011-06-01 01:56:01 +04:00
|
|
|
e-name < len ||
|
2012-10-29 13:31:50 +04:00
|
|
|
strncmp(e-len, feature, len))
|
2011-06-01 01:56:01 +04:00
|
|
|
return 0;
|
2013-05-23 12:35:34 +04:00
|
|
|
plen = e - name - len;
|
2011-06-01 01:56:01 +04:00
|
|
|
}
|
2013-05-23 12:35:34 +04:00
|
|
|
if (plen > 0 && name[plen-1] != '/') {
|
2013-03-08 09:47:52 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2013-05-23 12:35:34 +04:00
|
|
|
if (type == 's' ? !IS_DLEXT(&name[plen+len]) :
|
|
|
|
type == 'r' ? !IS_RBEXT(&name[plen+len]) :
|
2013-03-08 09:47:52 +04:00
|
|
|
0) {
|
|
|
|
return 0;
|
2012-11-05 19:24:03 +04:00
|
|
|
}
|
|
|
|
/* Now name == "#{prefix}/#{feature}#{ext}" where ext is acceptable
|
|
|
|
(possibly empty) and prefix is some string of length plen. */
|
|
|
|
|
2013-05-23 12:35:34 +04:00
|
|
|
if (plen > 0) --plen; /* exclude '.' */
|
2007-11-06 10:37:49 +03:00
|
|
|
for (i = 0; i < RARRAY_LEN(load_path); ++i) {
|
2013-05-13 13:56:22 +04:00
|
|
|
VALUE p = RARRAY_AREF(load_path, i);
|
2007-11-06 09:52:01 +03:00
|
|
|
const char *s = StringValuePtr(p);
|
|
|
|
long n = RSTRING_LEN(p);
|
|
|
|
|
2012-10-29 13:31:50 +04:00
|
|
|
if (n != plen) continue;
|
2012-11-05 19:24:03 +04:00
|
|
|
if (n && strncmp(name, s, n)) continue;
|
|
|
|
return p;
|
2007-11-06 09:52:01 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct loaded_feature_searching {
|
|
|
|
const char *name;
|
|
|
|
long len;
|
2007-11-09 06:56:38 +03:00
|
|
|
int type;
|
2007-11-06 10:37:49 +03:00
|
|
|
VALUE load_path;
|
2007-11-06 09:52:01 +03:00
|
|
|
const char *result;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
loaded_feature_path_i(st_data_t v, st_data_t b, st_data_t f)
|
|
|
|
{
|
|
|
|
const char *s = (const char *)v;
|
|
|
|
struct loaded_feature_searching *fp = (struct loaded_feature_searching *)f;
|
2007-11-09 06:56:38 +03:00
|
|
|
VALUE p = loaded_feature_path(s, strlen(s), fp->name, fp->len,
|
|
|
|
fp->type, fp->load_path);
|
2007-11-06 09:52:01 +03:00
|
|
|
if (!p) return ST_CONTINUE;
|
|
|
|
fp->result = s;
|
|
|
|
return ST_STOP;
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static int
|
2007-12-24 11:06:16 +03:00
|
|
|
rb_feature_p(const char *feature, const char *ext, int rb, int expanded, const char **fn)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2013-03-24 04:04:43 +04:00
|
|
|
VALUE features, this_feature_index = Qnil, v, p, load_path = 0;
|
2007-05-03 17:19:11 +04:00
|
|
|
const char *f, *e;
|
2007-11-06 09:52:01 +03:00
|
|
|
long i, len, elen, n;
|
2013-03-22 12:38:51 +04:00
|
|
|
st_table *loading_tbl, *features_index;
|
2007-12-24 11:06:16 +03:00
|
|
|
st_data_t data;
|
2007-11-09 06:56:38 +03:00
|
|
|
int type;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-12-24 11:06:16 +03:00
|
|
|
if (fn) *fn = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
if (ext) {
|
|
|
|
elen = strlen(ext);
|
2009-01-29 10:32:07 +03:00
|
|
|
len = strlen(feature) - elen;
|
2007-11-09 06:56:38 +03:00
|
|
|
type = rb ? 'r' : 's';
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
len = strlen(feature);
|
|
|
|
elen = 0;
|
2007-11-09 06:56:38 +03:00
|
|
|
type = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-05-03 17:19:11 +04:00
|
|
|
features = get_loaded_features();
|
2012-11-05 19:27:01 +04:00
|
|
|
features_index = get_loaded_features_index();
|
|
|
|
|
2013-03-22 12:38:51 +04:00
|
|
|
st_lookup(features_index, (st_data_t)feature, (st_data_t *)&this_feature_index);
|
2012-11-05 19:27:01 +04:00
|
|
|
/* We search `features` for an entry such that either
|
|
|
|
"#{features[i]}" == "#{load_path[j]}/#{feature}#{e}"
|
|
|
|
for some j, or
|
|
|
|
"#{features[i]}" == "#{feature}#{e}"
|
|
|
|
Here `e` is an "allowed" extension -- either empty or one
|
|
|
|
of the extensions accepted by IS_RBEXT, IS_SOEXT, or
|
|
|
|
IS_DLEXT. Further, if `ext && rb` then `IS_RBEXT(e)`,
|
|
|
|
and if `ext && !rb` then `IS_SOEXT(e) || IS_DLEXT(e)`.
|
|
|
|
|
|
|
|
If `expanded`, then only the latter form (without load_path[j])
|
|
|
|
is accepted. Otherwise either form is accepted, *unless* `ext`
|
|
|
|
is false and an otherwise-matching entry of the first form is
|
|
|
|
preceded by an entry of the form
|
|
|
|
"#{features[i2]}" == "#{load_path[j2]}/#{feature}#{e2}"
|
|
|
|
where `e2` matches %r{^\.[^./]*$} but is not an allowed extension.
|
|
|
|
After a "distractor" entry of this form, only entries of the
|
|
|
|
form "#{feature}#{e}" are accepted.
|
|
|
|
|
|
|
|
In `rb_provide_feature()` and `get_loaded_features_index()` we
|
|
|
|
maintain an invariant that the array `this_feature_index` will
|
|
|
|
point to every entry in `features` which has the form
|
|
|
|
"#{prefix}#{feature}#{e}"
|
|
|
|
where `e` is empty or matches %r{^\.[^./]*$}, and `prefix` is empty
|
|
|
|
or ends in '/'. This includes both match forms above, as well
|
|
|
|
as any distractors, so we may ignore all other entries in `features`.
|
|
|
|
*/
|
2013-03-09 03:54:41 +04:00
|
|
|
if (!NIL_P(this_feature_index)) {
|
|
|
|
for (i = 0; ; i++) {
|
|
|
|
VALUE entry;
|
|
|
|
long index;
|
|
|
|
if (RB_TYPE_P(this_feature_index, T_ARRAY)) {
|
|
|
|
if (i >= RARRAY_LEN(this_feature_index)) break;
|
2013-05-13 13:56:22 +04:00
|
|
|
entry = RARRAY_AREF(this_feature_index, i);
|
2013-03-09 03:54:41 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (i > 0) break;
|
|
|
|
entry = this_feature_index;
|
|
|
|
}
|
|
|
|
index = FIX2LONG(entry);
|
|
|
|
|
2013-05-13 13:56:22 +04:00
|
|
|
v = RARRAY_AREF(features, index);
|
2013-03-09 03:54:41 +04:00
|
|
|
f = StringValuePtr(v);
|
|
|
|
if ((n = RSTRING_LEN(v)) < len) continue;
|
|
|
|
if (strncmp(f, feature, len) != 0) {
|
|
|
|
if (expanded) continue;
|
|
|
|
if (!load_path) load_path = rb_get_expanded_load_path();
|
|
|
|
if (!(p = loaded_feature_path(f, n, feature, len, type, load_path)))
|
|
|
|
continue;
|
|
|
|
expanded = 1;
|
|
|
|
f += RSTRING_LEN(p) + 1;
|
|
|
|
}
|
|
|
|
if (!*(e = f + len)) {
|
|
|
|
if (ext) continue;
|
|
|
|
return 'u';
|
|
|
|
}
|
|
|
|
if (*e != '.') continue;
|
|
|
|
if ((!rb || !ext) && (IS_SOEXT(e) || IS_DLEXT(e))) {
|
|
|
|
return 's';
|
|
|
|
}
|
|
|
|
if ((rb || !ext) && (IS_RBEXT(e))) {
|
|
|
|
return 'r';
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
2012-11-05 19:27:01 +04:00
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
loading_tbl = get_loading_table();
|
|
|
|
if (loading_tbl) {
|
2007-12-24 11:06:16 +03:00
|
|
|
f = 0;
|
2007-11-06 09:52:01 +03:00
|
|
|
if (!expanded) {
|
|
|
|
struct loaded_feature_searching fs;
|
|
|
|
fs.name = feature;
|
|
|
|
fs.len = len;
|
2007-11-09 06:56:38 +03:00
|
|
|
fs.type = type;
|
2011-12-12 12:26:54 +04:00
|
|
|
fs.load_path = load_path ? load_path : rb_get_expanded_load_path();
|
2007-11-06 09:52:01 +03:00
|
|
|
fs.result = 0;
|
|
|
|
st_foreach(loading_tbl, loaded_feature_path_i, (st_data_t)&fs);
|
2007-12-24 11:06:16 +03:00
|
|
|
if ((f = fs.result) != 0) {
|
|
|
|
if (fn) *fn = f;
|
|
|
|
goto loading;
|
|
|
|
}
|
2007-11-06 09:52:01 +03:00
|
|
|
}
|
2007-12-24 11:06:16 +03:00
|
|
|
if (st_get_key(loading_tbl, (st_data_t)feature, &data)) {
|
|
|
|
if (fn) *fn = (const char*)data;
|
2007-11-06 09:52:01 +03:00
|
|
|
loading:
|
2007-05-03 17:19:11 +04:00
|
|
|
if (!ext) return 'u';
|
2007-11-09 06:56:38 +03:00
|
|
|
return !IS_RBEXT(ext) ? 's' : 'r';
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-01-16 09:26:33 +03:00
|
|
|
VALUE bufstr;
|
2007-05-03 17:19:11 +04:00
|
|
|
char *buf;
|
2013-11-03 04:35:49 +04:00
|
|
|
static const char so_ext[][4] = {
|
|
|
|
".so", ".o",
|
|
|
|
};
|
2007-05-03 17:19:11 +04:00
|
|
|
|
|
|
|
if (ext && *ext) return 0;
|
2008-01-16 09:26:33 +03:00
|
|
|
bufstr = rb_str_tmp_new(len + DLEXT_MAXLEN);
|
|
|
|
buf = RSTRING_PTR(bufstr);
|
2007-05-03 17:19:11 +04:00
|
|
|
MEMCPY(buf, feature, char, len);
|
|
|
|
for (i = 0; (e = loadable_ext[i]) != 0; i++) {
|
2008-12-16 05:37:45 +03:00
|
|
|
strlcpy(buf + len, e, DLEXT_MAXLEN + 1);
|
2007-12-24 11:06:16 +03:00
|
|
|
if (st_get_key(loading_tbl, (st_data_t)buf, &data)) {
|
2008-01-16 09:26:33 +03:00
|
|
|
rb_str_resize(bufstr, 0);
|
2007-12-24 11:06:16 +03:00
|
|
|
if (fn) *fn = (const char*)data;
|
2007-05-03 17:19:11 +04:00
|
|
|
return i ? 's' : 'r';
|
|
|
|
}
|
|
|
|
}
|
2013-11-03 04:35:49 +04:00
|
|
|
for (i = 0; i < numberof(so_ext); i++) {
|
|
|
|
strlcpy(buf + len, so_ext[i], DLEXT_MAXLEN + 1);
|
|
|
|
if (st_get_key(loading_tbl, (st_data_t)buf, &data)) {
|
|
|
|
rb_str_resize(bufstr, 0);
|
|
|
|
if (fn) *fn = (const char*)data;
|
|
|
|
return 's';
|
|
|
|
}
|
|
|
|
}
|
2008-01-16 09:26:33 +03:00
|
|
|
rb_str_resize(bufstr, 0);
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rb_provided(const char *feature)
|
2008-12-04 21:29:20 +03:00
|
|
|
{
|
|
|
|
return rb_feature_provided(feature, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rb_feature_provided(const char *feature, const char **loading)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2007-05-03 17:19:11 +04:00
|
|
|
const char *ext = strrchr(feature, '.');
|
2008-04-07 22:39:28 +04:00
|
|
|
volatile VALUE fullpath = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2008-04-07 22:39:28 +04:00
|
|
|
if (*feature == '.' &&
|
|
|
|
(feature[1] == '/' || strncmp(feature+1, "./", 2) == 0)) {
|
2012-11-05 19:27:08 +04:00
|
|
|
fullpath = rb_file_expand_path_fast(rb_get_path(rb_str_new2(feature)), Qnil);
|
2008-04-07 22:39:28 +04:00
|
|
|
feature = RSTRING_PTR(fullpath);
|
|
|
|
}
|
2007-05-03 17:19:11 +04:00
|
|
|
if (ext && !strchr(ext, '/')) {
|
2007-11-09 06:56:38 +03:00
|
|
|
if (IS_RBEXT(ext)) {
|
2009-08-18 15:18:25 +04:00
|
|
|
if (rb_feature_p(feature, ext, TRUE, FALSE, loading)) return TRUE;
|
2009-07-18 12:05:32 +04:00
|
|
|
return FALSE;
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
|
|
|
else if (IS_SOEXT(ext) || IS_DLEXT(ext)) {
|
2009-08-18 15:18:25 +04:00
|
|
|
if (rb_feature_p(feature, ext, FALSE, FALSE, loading)) return TRUE;
|
2009-07-18 12:05:32 +04:00
|
|
|
return FALSE;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
2009-09-09 10:46:31 +04:00
|
|
|
if (rb_feature_p(feature, 0, TRUE, FALSE, loading))
|
2009-07-18 12:05:32 +04:00
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rb_provide_feature(VALUE feature)
|
|
|
|
{
|
2012-11-05 19:27:01 +04:00
|
|
|
VALUE features;
|
|
|
|
|
|
|
|
features = get_loaded_features();
|
|
|
|
if (OBJ_FROZEN(features)) {
|
2010-08-29 07:51:39 +04:00
|
|
|
rb_raise(rb_eRuntimeError,
|
|
|
|
"$LOADED_FEATURES is frozen; cannot append feature");
|
|
|
|
}
|
2012-11-05 19:27:01 +04:00
|
|
|
rb_str_freeze(feature);
|
|
|
|
|
|
|
|
rb_ary_push(features, feature);
|
|
|
|
features_index_add(feature, INT2FIX(RARRAY_LEN(features)-1));
|
|
|
|
reset_loaded_features_snapshot();
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_provide(const char *feature)
|
|
|
|
{
|
2009-06-13 10:00:45 +04:00
|
|
|
rb_provide_feature(rb_usascii_str_new2(feature));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2007-12-25 07:17:06 +03:00
|
|
|
NORETURN(static void load_failed(VALUE));
|
* this commit is a result of refactoring. only renaming functions,
moving definitions place, add/remove prototypes, deleting
unused variables and removing yarv.h.
This commit doesn't change any behavior of ruby/vm.
* yarv.h, common.mk: remove yarv.h (contents are moved to yarvcore.h).
* error.c, eval_intern.h: include yarvcore.h instead yarv.h
* rename some functions:
* debug.[ch]: debug_*() -> ruby_debug_*()
* iseq.c: iseq_*() -> rb_iseq_*(), ruby_iseq_disasm()
* iseq.c: node_name() -> ruby_node_name()
* vm.c: yarv_check_redefinition_opt_method() ->
rb_vm_check_redefinition_opt_method()
* some refactoring with checking -Wall.
* array.c: remove rb_ary_ptr() (unused) and remove unused
local variables.
* object.c: add a prototype of rb_mod_module_exec().
* eval_intern.h (ruby_cref): set it inline.
* eval_load.c (rb_load), yarvcore.c: yarv_load() -> rb_load_internal().
* parse.y: add a prototype of rb_parse_in_eval() (in eval.c).
* process.c: add a prototype of rb_thread_stop_timer_thread() (in thread.c).
* thread.c: remove raw_gets() function (unused) and fix some format
mismatch (format mismatchs have remained yet. this is todo).
* thread.c (rb_thread_wait_fd_rw): fix typo on label name.
* thread_pthread.ci: comment out codes with USE_THREAD_CACHE.
* vm.c (rb_svar, rb_backref_get, rb_backref_get,
rb_lastline_get, rb_lastline_set) : moved from yarvcore.c.
* vm.c (yarv_init_redefined_flag): add a prototype and rename
yarv_opt_method_table to vm_opt_method_table.
* vm.c (rb_thread_eval): moved from yarvcore.c.
* yarvcore.c: remove unused global variables and fix to use nsdr().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11652 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-07 04:25:05 +03:00
|
|
|
|
2013-11-01 11:37:27 +04:00
|
|
|
static inline void
|
|
|
|
rb_load_internal0(rb_thread_t *th, VALUE fname, int wrap)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
int state;
|
2007-11-06 09:52:01 +03:00
|
|
|
volatile VALUE wrapper = th->top_wrapper;
|
|
|
|
volatile VALUE self = th->top_self;
|
2009-07-18 12:05:32 +04:00
|
|
|
volatile int loaded = FALSE;
|
2008-07-01 20:55:30 +04:00
|
|
|
volatile int mild_compile_error;
|
2013-11-01 11:37:27 +04:00
|
|
|
#if !defined __GNUC__
|
2007-11-06 09:52:01 +03:00
|
|
|
rb_thread_t *volatile th0 = th;
|
|
|
|
#endif
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-02-25 19:29:26 +03:00
|
|
|
th->errinfo = Qnil; /* ensure */
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
if (!wrap) {
|
2007-02-25 19:29:26 +03:00
|
|
|
th->top_wrapper = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* load in anonymous module as toplevel */
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
th->top_self = rb_obj_clone(rb_vm_top_self());
|
2007-02-25 19:29:26 +03:00
|
|
|
th->top_wrapper = rb_module_new();
|
|
|
|
rb_extend_object(th->top_self, th->top_wrapper);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2008-07-01 20:55:30 +04:00
|
|
|
mild_compile_error = th->mild_compile_error;
|
2007-04-25 05:35:13 +04:00
|
|
|
PUSH_TAG();
|
2006-12-31 18:02:22 +03:00
|
|
|
state = EXEC_TAG();
|
|
|
|
if (state == 0) {
|
* include/ruby/{intern,ruby}.h, compile.[ch], error.c, eval.c,
eval_load.c, gc.c, iseq.c, main.c, parse.y, re.c, ruby.c,
yarvcore.[ch] (ruby_eval_tree, ruby_sourcefile, ruby_sourceline,
ruby_nerrs): purge global variables.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-05 12:12:18 +04:00
|
|
|
NODE *node;
|
|
|
|
VALUE iseq;
|
|
|
|
|
2008-07-01 20:55:30 +04:00
|
|
|
th->mild_compile_error++;
|
2013-07-26 08:04:23 +04:00
|
|
|
node = (NODE *)rb_load_file_str(fname);
|
2009-07-18 12:05:32 +04:00
|
|
|
loaded = TRUE;
|
2010-06-17 18:32:20 +04:00
|
|
|
iseq = rb_iseq_new_top(node, rb_str_new2("<top (required)>"), fname, rb_realpath_internal(Qnil, fname, 1), Qfalse);
|
2008-07-01 20:55:30 +04:00
|
|
|
th->mild_compile_error--;
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
rb_iseq_eval(iseq);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
POP_TAG();
|
|
|
|
|
2013-11-01 11:37:27 +04:00
|
|
|
#if !defined __GNUC__
|
2007-11-06 09:52:01 +03:00
|
|
|
th = th0;
|
|
|
|
fname = RB_GC_GUARD(fname);
|
|
|
|
#endif
|
2008-07-01 20:55:30 +04:00
|
|
|
th->mild_compile_error = mild_compile_error;
|
2007-02-25 19:29:26 +03:00
|
|
|
th->top_self = self;
|
|
|
|
th->top_wrapper = wrapper;
|
|
|
|
|
2013-11-01 11:37:24 +04:00
|
|
|
if (!loaded && !FIXNUM_P(th->errinfo)) {
|
2012-05-12 00:39:35 +04:00
|
|
|
/* an error on loading don't include INT2FIX(TAG_FATAL) see r35625 */
|
2013-11-01 11:37:24 +04:00
|
|
|
rb_exc_raise(th->errinfo);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
if (state) {
|
2012-12-18 21:04:05 +04:00
|
|
|
rb_vm_jump_tag_but_local_jump(state);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2013-11-01 11:37:24 +04:00
|
|
|
if (!NIL_P(th->errinfo)) {
|
2006-12-31 18:02:22 +03:00
|
|
|
/* exception during load */
|
2007-02-25 19:29:26 +03:00
|
|
|
rb_exc_raise(th->errinfo);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-01 11:37:27 +04:00
|
|
|
static void
|
|
|
|
rb_load_internal(VALUE fname, int wrap)
|
|
|
|
{
|
|
|
|
rb_load_internal0(GET_THREAD(), fname, wrap);
|
|
|
|
}
|
|
|
|
|
2009-06-23 11:05:04 +04:00
|
|
|
void
|
|
|
|
rb_load(VALUE fname, int wrap)
|
|
|
|
{
|
|
|
|
VALUE tmp = rb_find_file(FilePathValue(fname));
|
|
|
|
if (!tmp) load_failed(fname);
|
|
|
|
rb_load_internal(tmp, wrap);
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
void
|
|
|
|
rb_load_protect(VALUE fname, int wrap, int *state)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
2007-04-25 05:35:13 +04:00
|
|
|
PUSH_TAG();
|
2006-12-31 18:02:22 +03:00
|
|
|
if ((status = EXEC_TAG()) == 0) {
|
|
|
|
rb_load(fname, wrap);
|
|
|
|
}
|
2007-04-25 05:35:13 +04:00
|
|
|
POP_TAG();
|
2006-12-31 18:02:22 +03:00
|
|
|
if (state)
|
|
|
|
*state = status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:31:22 +04:00
|
|
|
* load(filename, wrap=false) -> true
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Loads and executes the Ruby
|
|
|
|
* program in the file _filename_. If the filename does not
|
|
|
|
* resolve to an absolute path, the file is searched for in the library
|
|
|
|
* directories listed in <code>$:</code>. If the optional _wrap_
|
|
|
|
* parameter is +true+, the loaded script will be executed
|
|
|
|
* under an anonymous module, protecting the calling program's global
|
|
|
|
* namespace. In no circumstance will any local variables in the loaded
|
|
|
|
* file be propagated to the loading environment.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
2007-12-24 10:52:39 +03:00
|
|
|
rb_f_load(int argc, VALUE *argv)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2014-10-29 08:44:33 +03:00
|
|
|
VALUE fname, wrap, path, orig_fname;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "11", &fname, &wrap);
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
|
2012-12-01 19:25:28 +04:00
|
|
|
if (RUBY_DTRACE_LOAD_ENTRY_ENABLED()) {
|
|
|
|
RUBY_DTRACE_LOAD_ENTRY(StringValuePtr(fname),
|
|
|
|
rb_sourcefile(),
|
|
|
|
rb_sourceline());
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
}
|
|
|
|
|
2014-10-29 08:44:33 +03:00
|
|
|
orig_fname = FilePathValue(fname);
|
|
|
|
fname = rb_str_encode_ospath(orig_fname);
|
|
|
|
path = rb_find_file(fname);
|
2009-06-23 11:05:04 +04:00
|
|
|
if (!path) {
|
|
|
|
if (!rb_file_load_ok(RSTRING_PTR(fname)))
|
2014-10-29 08:44:33 +03:00
|
|
|
load_failed(orig_fname);
|
2009-06-23 11:05:04 +04:00
|
|
|
path = fname;
|
|
|
|
}
|
|
|
|
rb_load_internal(path, RTEST(wrap));
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
|
2012-12-01 19:25:28 +04:00
|
|
|
if (RUBY_DTRACE_LOAD_RETURN_ENABLED()) {
|
2013-01-10 06:16:00 +04:00
|
|
|
RUBY_DTRACE_LOAD_RETURN(StringValuePtr(fname),
|
|
|
|
rb_sourcefile(),
|
|
|
|
rb_sourceline());
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
static char *
|
|
|
|
load_lock(const char *ftptr)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2007-05-03 17:19:11 +04:00
|
|
|
st_data_t data;
|
|
|
|
st_table *loading_tbl = get_loading_table();
|
|
|
|
|
|
|
|
if (!loading_tbl || !st_lookup(loading_tbl, (st_data_t)ftptr, &data)) {
|
|
|
|
/* loading ruby library should be serialized. */
|
|
|
|
if (!loading_tbl) {
|
2011-05-22 16:52:18 +04:00
|
|
|
GET_VM()->loading_table = loading_tbl = st_init_strtable();
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
|
|
|
/* partial state */
|
|
|
|
ftptr = ruby_strdup(ftptr);
|
2012-07-05 11:00:29 +04:00
|
|
|
data = (st_data_t)rb_thread_shield_new();
|
2007-05-03 17:19:11 +04:00
|
|
|
st_insert(loading_tbl, (st_data_t)ftptr, data);
|
|
|
|
return (char *)ftptr;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2013-11-03 04:35:49 +04:00
|
|
|
else if (RB_TYPE_P((VALUE)data, T_NODE) && nd_type((VALUE)data) == NODE_MEMO) {
|
|
|
|
NODE *memo = RNODE(data);
|
|
|
|
void (*init)(void) = (void (*)(void))memo->nd_cfnc;
|
|
|
|
data = (st_data_t)rb_thread_shield_new();
|
|
|
|
st_insert(loading_tbl, (st_data_t)ftptr, data);
|
|
|
|
(*init)();
|
|
|
|
return (char *)"";
|
|
|
|
}
|
2009-06-13 10:03:44 +04:00
|
|
|
if (RTEST(ruby_verbose)) {
|
|
|
|
rb_warning("loading in progress, circular require considered harmful - %s", ftptr);
|
2013-10-08 19:56:01 +04:00
|
|
|
rb_backtrace_print_to(rb_stderr);
|
2009-06-13 10:03:44 +04:00
|
|
|
}
|
2012-07-05 11:00:29 +04:00
|
|
|
switch (rb_thread_shield_wait((VALUE)data)) {
|
2011-12-14 05:20:11 +04:00
|
|
|
case Qfalse:
|
2013-01-09 17:14:05 +04:00
|
|
|
data = (st_data_t)ftptr;
|
2013-01-09 17:14:09 +04:00
|
|
|
st_insert(loading_tbl, data, (st_data_t)rb_thread_shield_new());
|
2013-01-09 17:14:05 +04:00
|
|
|
return 0;
|
2011-12-14 05:20:11 +04:00
|
|
|
case Qnil:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return (char *)ftptr;
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2012-01-13 12:23:43 +04:00
|
|
|
static int
|
2012-07-05 11:00:29 +04:00
|
|
|
release_thread_shield(st_data_t *key, st_data_t *value, st_data_t done, int existing)
|
2012-01-13 12:23:43 +04:00
|
|
|
{
|
2012-07-05 11:00:29 +04:00
|
|
|
VALUE thread_shield = (VALUE)*value;
|
2012-03-29 11:36:12 +04:00
|
|
|
if (!existing) return ST_STOP;
|
2012-07-05 11:00:29 +04:00
|
|
|
if (done ? rb_thread_shield_destroy(thread_shield) : rb_thread_shield_release(thread_shield)) {
|
2012-01-13 12:23:43 +04:00
|
|
|
/* still in-use */
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
2012-03-29 18:50:20 +04:00
|
|
|
xfree((char *)*key);
|
2012-01-13 12:23:43 +04:00
|
|
|
return ST_DELETE;
|
|
|
|
}
|
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
static void
|
2008-11-11 21:28:47 +03:00
|
|
|
load_unlock(const char *ftptr, int done)
|
2007-05-03 17:19:11 +04:00
|
|
|
{
|
|
|
|
if (ftptr) {
|
|
|
|
st_data_t key = (st_data_t)ftptr;
|
|
|
|
st_table *loading_tbl = get_loading_table();
|
|
|
|
|
2012-07-05 11:00:29 +04:00
|
|
|
st_update(loading_tbl, key, release_thread_shield, done);
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2011-08-23 10:26:11 +04:00
|
|
|
* require(name) -> true or false
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2011-08-23 10:26:11 +04:00
|
|
|
* Loads the given +name+, returning +true+ if successful and +false+ if the
|
|
|
|
* feature is already loaded.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2011-08-23 10:26:11 +04:00
|
|
|
* If the filename does not resolve to an absolute path, it will be searched
|
|
|
|
* for in the directories listed in <code>$LOAD_PATH</code> (<code>$:</code>).
|
|
|
|
*
|
|
|
|
* If the filename has the extension ".rb", it is loaded as a source file; if
|
|
|
|
* the extension is ".so", ".o", or ".dll", or the default shared library
|
|
|
|
* extension on the current platform, Ruby loads the shared library as a
|
|
|
|
* Ruby extension. Otherwise, Ruby tries adding ".rb", ".so", and so on
|
|
|
|
* to the name until found. If the file named cannot be found, a LoadError
|
|
|
|
* will be raised.
|
|
|
|
*
|
|
|
|
* For Ruby extensions the filename given may use any shared library
|
|
|
|
* extension. For example, on Linux the socket extension is "socket.so" and
|
|
|
|
* <code>require 'socket.dll'</code> will load the socket extension.
|
|
|
|
*
|
|
|
|
* The absolute path of the loaded file is added to
|
|
|
|
* <code>$LOADED_FEATURES</code> (<code>$"</code>). A file will not be
|
|
|
|
* loaded again if its path already appears in <code>$"</code>. For example,
|
|
|
|
* <code>require 'a'; require './a'</code> will not load <code>a.rb</code>
|
|
|
|
* again.
|
|
|
|
*
|
|
|
|
* require "my-library.rb"
|
|
|
|
* require "db-driver"
|
2012-02-23 05:58:01 +04:00
|
|
|
*
|
|
|
|
* Any constants or globals within the loaded source file will be available
|
|
|
|
* in the calling program's global namespace. However, local variables will
|
|
|
|
* not be propagated to the loading environment.
|
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_f_require(VALUE obj, VALUE fname)
|
|
|
|
{
|
|
|
|
return rb_require_safe(fname, rb_safe_level());
|
|
|
|
}
|
|
|
|
|
2010-12-25 05:07:13 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* require_relative(string) -> true or false
|
|
|
|
*
|
|
|
|
* Ruby tries to load the library named _string_ relative to the requiring
|
|
|
|
* file's path. If the file's path cannot be determined a LoadError is raised.
|
|
|
|
* If a file is loaded +true+ is returned and false otherwise.
|
|
|
|
*/
|
2010-12-25 06:48:57 +03:00
|
|
|
VALUE
|
2010-03-16 20:40:00 +03:00
|
|
|
rb_f_require_relative(VALUE obj, VALUE fname)
|
|
|
|
{
|
|
|
|
VALUE base = rb_current_realfilepath();
|
|
|
|
if (NIL_P(base)) {
|
2012-03-07 03:38:33 +04:00
|
|
|
rb_loaderror("cannot infer basepath");
|
2010-03-16 20:40:00 +03:00
|
|
|
}
|
2010-03-30 13:26:09 +04:00
|
|
|
base = rb_file_dirname(base);
|
|
|
|
return rb_require_safe(rb_file_absolute_path(fname, base), rb_safe_level());
|
2010-03-16 20:40:00 +03:00
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static int
|
2009-06-23 11:05:04 +04:00
|
|
|
search_required(VALUE fname, volatile VALUE *path, int safe_level)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
VALUE tmp;
|
|
|
|
char *ext, *ftptr;
|
|
|
|
int type, ft = 0;
|
2007-12-24 11:06:16 +03:00
|
|
|
const char *loading;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
*path = 0;
|
|
|
|
ext = strrchr(ftptr = RSTRING_PTR(fname), '.');
|
|
|
|
if (ext && !strchr(ext, '/')) {
|
2007-11-09 06:56:38 +03:00
|
|
|
if (IS_RBEXT(ext)) {
|
2009-07-18 12:05:32 +04:00
|
|
|
if (rb_feature_p(ftptr, ext, TRUE, FALSE, &loading)) {
|
2012-08-23 11:46:12 +04:00
|
|
|
if (loading) *path = rb_filesystem_str_new_cstr(loading);
|
2006-12-31 18:02:22 +03:00
|
|
|
return 'r';
|
2007-12-24 11:06:16 +03:00
|
|
|
}
|
2009-06-23 11:05:04 +04:00
|
|
|
if ((tmp = rb_find_file_safe(fname, safe_level)) != 0) {
|
2006-12-31 18:02:22 +03:00
|
|
|
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
|
2009-07-18 12:05:32 +04:00
|
|
|
if (!rb_feature_p(ftptr, ext, TRUE, TRUE, &loading) || loading)
|
2006-12-31 18:02:22 +03:00
|
|
|
*path = tmp;
|
|
|
|
return 'r';
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (IS_SOEXT(ext)) {
|
2009-07-18 12:05:32 +04:00
|
|
|
if (rb_feature_p(ftptr, ext, FALSE, FALSE, &loading)) {
|
2012-08-23 11:46:12 +04:00
|
|
|
if (loading) *path = rb_filesystem_str_new_cstr(loading);
|
2006-12-31 18:02:22 +03:00
|
|
|
return 's';
|
2007-12-24 11:06:16 +03:00
|
|
|
}
|
2012-08-23 11:46:12 +04:00
|
|
|
tmp = rb_str_subseq(fname, 0, ext - RSTRING_PTR(fname));
|
2006-12-31 18:02:22 +03:00
|
|
|
#ifdef DLEXT2
|
|
|
|
OBJ_FREEZE(tmp);
|
2009-06-23 11:05:04 +04:00
|
|
|
if (rb_find_file_ext_safe(&tmp, loadable_ext + 1, safe_level)) {
|
2006-12-31 18:02:22 +03:00
|
|
|
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
|
2009-09-09 10:46:31 +04:00
|
|
|
if (!rb_feature_p(ftptr, ext, FALSE, TRUE, &loading) || loading)
|
2006-12-31 18:02:22 +03:00
|
|
|
*path = tmp;
|
|
|
|
return 's';
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
rb_str_cat2(tmp, DLEXT);
|
|
|
|
OBJ_FREEZE(tmp);
|
2009-06-23 11:05:04 +04:00
|
|
|
if ((tmp = rb_find_file_safe(tmp, safe_level)) != 0) {
|
2006-12-31 18:02:22 +03:00
|
|
|
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
|
2009-07-18 12:05:32 +04:00
|
|
|
if (!rb_feature_p(ftptr, ext, FALSE, TRUE, &loading) || loading)
|
2006-12-31 18:02:22 +03:00
|
|
|
*path = tmp;
|
|
|
|
return 's';
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if (IS_DLEXT(ext)) {
|
2009-07-18 12:05:32 +04:00
|
|
|
if (rb_feature_p(ftptr, ext, FALSE, FALSE, &loading)) {
|
2012-08-23 11:46:12 +04:00
|
|
|
if (loading) *path = rb_filesystem_str_new_cstr(loading);
|
2006-12-31 18:02:22 +03:00
|
|
|
return 's';
|
2007-12-24 11:06:16 +03:00
|
|
|
}
|
2009-06-23 11:05:04 +04:00
|
|
|
if ((tmp = rb_find_file_safe(fname, safe_level)) != 0) {
|
2006-12-31 18:02:22 +03:00
|
|
|
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
|
2009-07-18 12:05:32 +04:00
|
|
|
if (!rb_feature_p(ftptr, ext, FALSE, TRUE, &loading) || loading)
|
2006-12-31 18:02:22 +03:00
|
|
|
*path = tmp;
|
|
|
|
return 's';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-18 12:05:32 +04:00
|
|
|
else if ((ft = rb_feature_p(ftptr, 0, FALSE, FALSE, &loading)) == 'r') {
|
2012-08-23 11:46:12 +04:00
|
|
|
if (loading) *path = rb_filesystem_str_new_cstr(loading);
|
2006-12-31 18:02:22 +03:00
|
|
|
return 'r';
|
|
|
|
}
|
|
|
|
tmp = fname;
|
2009-06-23 11:05:04 +04:00
|
|
|
type = rb_find_file_ext_safe(&tmp, loadable_ext, safe_level);
|
2006-12-31 18:02:22 +03:00
|
|
|
switch (type) {
|
2007-05-03 17:19:11 +04:00
|
|
|
case 0:
|
2006-12-31 18:02:22 +03:00
|
|
|
if (ft)
|
2013-11-03 04:35:49 +04:00
|
|
|
goto statically_linked;
|
2007-12-24 11:06:16 +03:00
|
|
|
ftptr = RSTRING_PTR(tmp);
|
2009-07-18 12:05:32 +04:00
|
|
|
return rb_feature_p(ftptr, 0, FALSE, TRUE, 0);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
default:
|
2013-11-03 04:35:49 +04:00
|
|
|
if (ft) {
|
|
|
|
statically_linked:
|
|
|
|
if (loading) *path = rb_filesystem_str_new_cstr(loading);
|
|
|
|
return ft;
|
|
|
|
}
|
2007-05-03 17:19:11 +04:00
|
|
|
case 1:
|
2006-12-31 18:02:22 +03:00
|
|
|
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
|
2009-07-18 12:05:32 +04:00
|
|
|
if (rb_feature_p(ftptr, ext, !--type, TRUE, &loading) && !loading)
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
*path = tmp;
|
|
|
|
}
|
|
|
|
return type ? 's' : 'r';
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
load_failed(VALUE fname)
|
|
|
|
{
|
2012-03-07 11:30:31 +04:00
|
|
|
rb_load_fail(fname, "cannot load such file");
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2007-06-18 12:02:30 +04:00
|
|
|
static VALUE
|
2007-06-19 05:53:31 +04:00
|
|
|
load_ext(VALUE path)
|
2007-06-18 12:02:30 +04:00
|
|
|
{
|
|
|
|
SCOPE_SET(NOEX_PUBLIC);
|
2010-02-24 05:52:08 +03:00
|
|
|
return (VALUE)dln_load(RSTRING_PTR(path));
|
2007-06-18 12:02:30 +04:00
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
VALUE
|
|
|
|
rb_require_safe(VALUE fname, int safe)
|
|
|
|
{
|
2009-06-13 09:59:01 +04:00
|
|
|
volatile VALUE result = Qnil;
|
* blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
eval_jump.h, eval_load.c, eval_safe.h, gc.c, proc.c, signal.c,
thread.c, thread_pthread.ci, thread_win32.ci, vm.c, vm.h,
vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fix typo (rb_thead_t -> rb_thread_t).
* eval_intern.h: remove unused definitions.
* common.mk: fix around vm_opts.h path
and remove harmful argument passed to insns2vm.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-08 09:37:46 +03:00
|
|
|
rb_thread_t *th = GET_THREAD();
|
2007-05-03 17:19:11 +04:00
|
|
|
volatile VALUE errinfo = th->errinfo;
|
2006-12-31 18:02:22 +03:00
|
|
|
int state;
|
2007-02-21 03:14:07 +03:00
|
|
|
struct {
|
|
|
|
int safe;
|
|
|
|
} volatile saved;
|
2006-12-31 18:02:22 +03:00
|
|
|
char *volatile ftptr = 0;
|
|
|
|
|
2012-12-01 19:25:28 +04:00
|
|
|
if (RUBY_DTRACE_REQUIRE_ENTRY_ENABLED()) {
|
|
|
|
RUBY_DTRACE_REQUIRE_ENTRY(StringValuePtr(fname),
|
|
|
|
rb_sourcefile(),
|
|
|
|
rb_sourceline());
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
}
|
|
|
|
|
2007-04-25 05:35:13 +04:00
|
|
|
PUSH_TAG();
|
2007-02-21 03:14:07 +03:00
|
|
|
saved.safe = rb_safe_level();
|
2006-12-31 18:02:22 +03:00
|
|
|
if ((state = EXEC_TAG()) == 0) {
|
|
|
|
VALUE path;
|
|
|
|
long handle;
|
|
|
|
int found;
|
|
|
|
|
|
|
|
rb_set_safe_level_force(safe);
|
2008-04-08 05:40:49 +04:00
|
|
|
FilePathValue(fname);
|
2009-01-31 13:07:49 +03:00
|
|
|
rb_set_safe_level_force(0);
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
|
2012-12-01 19:25:28 +04:00
|
|
|
if (RUBY_DTRACE_FIND_REQUIRE_ENTRY_ENABLED()) {
|
|
|
|
RUBY_DTRACE_FIND_REQUIRE_ENTRY(StringValuePtr(fname),
|
|
|
|
rb_sourcefile(),
|
|
|
|
rb_sourceline());
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
}
|
|
|
|
|
2013-07-26 08:04:23 +04:00
|
|
|
path = rb_str_encode_ospath(fname);
|
|
|
|
found = search_required(path, &path, safe);
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
|
2012-12-01 19:25:28 +04:00
|
|
|
if (RUBY_DTRACE_FIND_REQUIRE_RETURN_ENABLED()) {
|
|
|
|
RUBY_DTRACE_FIND_REQUIRE_RETURN(StringValuePtr(fname),
|
|
|
|
rb_sourcefile(),
|
|
|
|
rb_sourceline());
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
if (found) {
|
2007-05-03 17:19:11 +04:00
|
|
|
if (!path || !(ftptr = load_lock(RSTRING_PTR(path)))) {
|
2006-12-31 18:02:22 +03:00
|
|
|
result = Qfalse;
|
|
|
|
}
|
2013-11-03 04:35:49 +04:00
|
|
|
else if (!*ftptr) {
|
|
|
|
rb_provide_feature(path);
|
|
|
|
result = Qtrue;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
else {
|
|
|
|
switch (found) {
|
2007-05-03 17:19:11 +04:00
|
|
|
case 'r':
|
2009-06-23 11:05:04 +04:00
|
|
|
rb_load_internal(path, 0);
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
case 's':
|
* blockinlining.c: remove "yarv" prefix.
* array.c, numeric.c: ditto.
* insnhelper.ci, insns.def, vm_evalbody.ci: ditto.
* yarvcore.c: removed.
* yarvcore.h: renamed to core.h.
* cont.c, debug.c, error.c, process.c, signal.c : ditto.
* ext/probeprofiler/probeprofiler.c: ditto.
* id.c, id.h: added.
* inits.c: ditto.
* compile.c: rename internal functions.
* compile.h: fix debug flag.
* eval.c, object.c, vm.c: remove ruby_top_self.
use rb_vm_top_self() instead.
* eval_intern.h, eval_load: ditto.
* gc.c: rename yarv_machine_stack_mark() to
rb_gc_mark_machine_stack().
* insnhelper.h: remove unused macros.
* iseq.c: add iseq_compile() to create iseq object
from source string.
* proc.c: rename a internal function.
* template/insns.inc.tmpl: remove YARV prefix.
* thread.c:
* vm.c (rb_iseq_eval): added.
* vm.c: move some functions from yarvcore.c.
* vm_dump.c: fix to remove compiler warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12741 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-07-12 08:25:46 +04:00
|
|
|
handle = (long)rb_vm_call_cfunc(rb_vm_top_self(), load_ext,
|
2010-06-17 18:32:20 +04:00
|
|
|
path, 0, path);
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_ary_push(ruby_dln_librefs, LONG2NUM(handle));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rb_provide_feature(path);
|
|
|
|
result = Qtrue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
POP_TAG();
|
2008-11-11 21:28:47 +03:00
|
|
|
load_unlock(ftptr, !state);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-02-21 03:14:07 +03:00
|
|
|
rb_set_safe_level_force(saved.safe);
|
2006-12-31 18:02:22 +03:00
|
|
|
if (state) {
|
|
|
|
JUMP_TAG(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NIL_P(result)) {
|
|
|
|
load_failed(fname);
|
|
|
|
}
|
|
|
|
|
|
|
|
th->errinfo = errinfo;
|
|
|
|
|
2012-12-01 19:25:28 +04:00
|
|
|
if (RUBY_DTRACE_REQUIRE_RETURN_ENABLED()) {
|
2013-01-10 06:16:00 +04:00
|
|
|
RUBY_DTRACE_REQUIRE_RETURN(StringValuePtr(fname),
|
|
|
|
rb_sourcefile(),
|
|
|
|
rb_sourceline());
|
* probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.
* compile.c (rb_insns_name): allowing DTrace probes to access
instruction sequence name.
* Makefile.in: translate probes.d file to appropriate header file.
* common.mk: declare dependencies on the DTrace header.
* configure.in: add a test for existence of DTrace.
* eval.c (setup_exception): add a probe for when an exception is
raised.
* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
end.
* hash.c (empty_hash_alloc): Add a probe for hash allocation.
* insns.def: Add probes for function entry and return.
* internal.h: function declaration for compile.c change.
* load.c (rb_f_load): add probes for `load` entry and exit, require
entry and exit, and wrapping search_required for load path search.
* object.c (rb_obj_alloc): added a probe for general object creation.
* parse.y (yycompile0): added a probe around parse and compile phase.
* string.c (empty_str_alloc, str_new): DTrace probes for string
allocation.
* test/dtrace/*: tests for DTrace probes.
* vm.c (vm_invoke_proc): add probes for function return on exception
raise, hash create, and instruction sequence execution.
* vm_core.h: add probe declarations for function entry and exit.
* vm_dump.c: add probes header file.
* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
function entry and return.
* vm_exec.c: expose instruction number to instruction name function.
* vm_insnshelper.c: add function entry and exit probes for cfunc
methods.
* vm_insnhelper.h: vm usage information is always collected, so
uncomment the functions.
12 19:14:50 2012 Akinori MUSHA <knu@iDaemons.org>
* configure.in (isinf, isnan): isinf() and isnan() are macros on
DragonFly which cannot be found by AC_REPLACE_FUNCS(). This
workaround enforces the fact that they exist on DragonFly.
12 15:59:38 2012 Shugo Maeda <shugo@ruby-lang.org>
* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
vm_insnhelper.c (vm_search_method): revert r37616 because it's too
slow. [ruby-dev:46477]
* test/ruby/test_refinement.rb (test_inline_method_cache): skip
the test until the bug is fixed efficiently.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13 01:52:12 +04:00
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_require(const char *fname)
|
|
|
|
{
|
|
|
|
VALUE fn = rb_str_new2(fname);
|
|
|
|
OBJ_FREEZE(fn);
|
|
|
|
return rb_require_safe(fn, rb_safe_level());
|
|
|
|
}
|
|
|
|
|
2013-11-03 04:35:49 +04:00
|
|
|
static int
|
|
|
|
register_init_ext(st_data_t *key, st_data_t *value, st_data_t init, int existing)
|
2007-06-18 12:02:30 +04:00
|
|
|
{
|
2013-11-03 04:35:49 +04:00
|
|
|
const char *name = (char *)*key;
|
|
|
|
if (existing) {
|
|
|
|
/* already registered */
|
|
|
|
rb_warn("%s is already registered", name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*value = (st_data_t)NEW_MEMO(init, 0, 0);
|
|
|
|
*key = (st_data_t)ruby_strdup(name);
|
2014-02-14 20:40:26 +04:00
|
|
|
(*(void (*)(void))init)();
|
2013-11-03 04:35:49 +04:00
|
|
|
}
|
|
|
|
return ST_CONTINUE;
|
2007-06-18 12:02:30 +04:00
|
|
|
}
|
|
|
|
|
2010-09-04 05:41:04 +04:00
|
|
|
RUBY_FUNC_EXPORTED void
|
2007-05-03 17:19:11 +04:00
|
|
|
ruby_init_ext(const char *name, void (*init)(void))
|
|
|
|
{
|
2013-11-03 04:35:49 +04:00
|
|
|
st_table *loading_tbl = get_loading_table();
|
|
|
|
|
2014-03-02 05:49:15 +04:00
|
|
|
if (rb_provided(name))
|
|
|
|
return;
|
2013-11-03 04:35:49 +04:00
|
|
|
if (!loading_tbl) {
|
|
|
|
GET_VM()->loading_table = loading_tbl = st_init_strtable();
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
2013-11-03 04:35:49 +04:00
|
|
|
st_update(loading_tbl, (st_data_t)name, register_init_ext, (st_data_t)init);
|
2014-03-02 05:49:15 +04:00
|
|
|
rb_provide(name);
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:31:22 +04:00
|
|
|
* mod.autoload(module, filename) -> nil
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Registers _filename_ to be loaded (using <code>Kernel::require</code>)
|
|
|
|
* the first time that _module_ (which may be a <code>String</code> or
|
|
|
|
* a symbol) is accessed in the namespace of _mod_.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* module A
|
|
|
|
* end
|
|
|
|
* A.autoload(:B, "b")
|
|
|
|
* A::B.doit # autoloads "b"
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_mod_autoload(VALUE mod, VALUE sym, VALUE file)
|
|
|
|
{
|
|
|
|
ID id = rb_to_id(sym);
|
|
|
|
|
2009-06-13 09:57:41 +04:00
|
|
|
FilePathValue(file);
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_autoload(mod, id, RSTRING_PTR(file));
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-09-23 23:45:37 +04:00
|
|
|
* call-seq:
|
2010-05-18 01:31:22 +04:00
|
|
|
* mod.autoload?(name) -> String or nil
|
2009-09-23 23:45:37 +04:00
|
|
|
*
|
|
|
|
* Returns _filename_ to be loaded if _name_ is registered as
|
|
|
|
* +autoload+ in the namespace of _mod_.
|
|
|
|
*
|
|
|
|
* module A
|
|
|
|
* end
|
|
|
|
* A.autoload(:B, "b")
|
2010-05-18 01:07:33 +04:00
|
|
|
* A.autoload?(:B) #=> "b"
|
2006-12-31 18:02:22 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_mod_autoload_p(VALUE mod, VALUE sym)
|
|
|
|
{
|
2014-07-09 10:14:41 +04:00
|
|
|
ID id = rb_check_id(&sym);
|
2011-07-26 20:05:35 +04:00
|
|
|
if (!id) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
return rb_autoload_p(mod, id);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-18 01:31:22 +04:00
|
|
|
* autoload(module, filename) -> nil
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* Registers _filename_ to be loaded (using <code>Kernel::require</code>)
|
|
|
|
* the first time that _module_ (which may be a <code>String</code> or
|
|
|
|
* a symbol) is accessed.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* autoload(:MyModule, "/usr/local/lib/modules/my_module.rb")
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_f_autoload(VALUE obj, VALUE sym, VALUE file)
|
|
|
|
{
|
2011-07-10 10:32:06 +04:00
|
|
|
VALUE klass = rb_class_real(rb_vm_cbase());
|
2006-12-31 18:02:22 +03:00
|
|
|
if (NIL_P(klass)) {
|
|
|
|
rb_raise(rb_eTypeError, "Can not set autoload on singleton class");
|
|
|
|
}
|
|
|
|
return rb_mod_autoload(klass, sym, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-09-23 23:45:37 +04:00
|
|
|
* call-seq:
|
2010-05-18 01:31:22 +04:00
|
|
|
* autoload?(name) -> String or nil
|
2009-09-23 23:45:37 +04:00
|
|
|
*
|
|
|
|
* Returns _filename_ to be loaded if _name_ is registered as
|
|
|
|
* +autoload+.
|
|
|
|
*
|
|
|
|
* autoload(:B, "b")
|
2010-05-18 01:07:33 +04:00
|
|
|
* autoload?(:B) #=> "b"
|
2006-12-31 18:02:22 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_f_autoload_p(VALUE obj, VALUE sym)
|
|
|
|
{
|
* vm.c, insns.def, eval.c, vm_insnhelper.c: fix CREF handling.
VM value stack frame of block contains cref information.
(dfp[-1] points CREF)
* compile.c, eval_intern.h, eval_method.c, load.c, proc.c,
vm_dump.h, vm_core.h: ditto.
* include/ruby/ruby.h, gc.c: remove T_VALUES because of above
changes.
* bootstraptest/test_eval.rb, test_knownbug.rb: move solved test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16468 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-19 07:08:50 +04:00
|
|
|
/* use rb_vm_cbase() as same as rb_f_autoload. */
|
|
|
|
VALUE klass = rb_vm_cbase();
|
2006-12-31 18:02:22 +03:00
|
|
|
if (NIL_P(klass)) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
return rb_mod_autoload_p(klass, sym);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-30 09:25:32 +04:00
|
|
|
Init_load(void)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2008-08-16 04:20:31 +04:00
|
|
|
#undef rb_intern
|
2010-12-18 08:43:01 +03:00
|
|
|
#define rb_intern(str) rb_intern2((str), strlen(str))
|
2008-04-30 13:03:03 +04:00
|
|
|
rb_vm_t *vm = GET_VM();
|
2008-08-16 04:20:31 +04:00
|
|
|
static const char var_load_path[] = "$:";
|
|
|
|
ID id_load_path = rb_intern2(var_load_path, sizeof(var_load_path)-1);
|
2008-04-30 13:03:03 +04:00
|
|
|
|
2009-06-21 17:35:41 +04:00
|
|
|
rb_define_hooked_variable(var_load_path, (VALUE*)vm, load_path_getter, rb_gvar_readonly_setter);
|
2008-08-16 04:20:31 +04:00
|
|
|
rb_alias_variable(rb_intern("$-I"), id_load_path);
|
|
|
|
rb_alias_variable(rb_intern("$LOAD_PATH"), id_load_path);
|
2008-04-30 13:03:03 +04:00
|
|
|
vm->load_path = rb_ary_new();
|
2013-03-09 04:03:40 +04:00
|
|
|
vm->expanded_load_path = rb_ary_tmp_new(0);
|
|
|
|
vm->load_path_snapshot = rb_ary_tmp_new(0);
|
2012-11-05 19:27:08 +04:00
|
|
|
vm->load_path_check_cache = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-02-14 05:19:02 +03:00
|
|
|
rb_define_virtual_variable("$\"", get_loaded_features, 0);
|
|
|
|
rb_define_virtual_variable("$LOADED_FEATURES", get_loaded_features, 0);
|
2008-04-30 13:03:03 +04:00
|
|
|
vm->loaded_features = rb_ary_new();
|
2013-03-09 04:03:40 +04:00
|
|
|
vm->loaded_features_snapshot = rb_ary_tmp_new(0);
|
2013-03-22 12:38:51 +04:00
|
|
|
vm->loaded_features_index = st_init_strtable();
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
rb_define_global_function("load", rb_f_load, -1);
|
|
|
|
rb_define_global_function("require", rb_f_require, 1);
|
2010-03-16 20:40:00 +03:00
|
|
|
rb_define_global_function("require_relative", rb_f_require_relative, 1);
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_define_method(rb_cModule, "autoload", rb_mod_autoload, 2);
|
|
|
|
rb_define_method(rb_cModule, "autoload?", rb_mod_autoload_p, 1);
|
|
|
|
rb_define_global_function("autoload", rb_f_autoload, 2);
|
|
|
|
rb_define_global_function("autoload?", rb_f_autoload_p, 1);
|
|
|
|
|
2013-03-09 04:05:40 +04:00
|
|
|
ruby_dln_librefs = rb_ary_tmp_new(0);
|
* gc.c, include/ruby/ruby.h: rename rb_register_mark_object()
to rb_gc_register_mark_object().
* eval.c, vm.c: initialize vm->mark_object_ary at
Init_top_self().
* bignum.c, complex.c, encoding.c, ext/win32ole/win32ole.c,
io.c, load.c, marshal.c, rational.c, ruby.c, vm.c:
use rb_gc_register_mark_object() instead of
rb_global_variable() or rb_gc_register_address().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19365 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-15 18:59:14 +04:00
|
|
|
rb_gc_register_mark_object(ruby_dln_librefs);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|