2006-12-31 18:02:22 +03:00
|
|
|
/*
|
|
|
|
* load methods from eval.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "eval_intern.h"
|
|
|
|
|
|
|
|
VALUE ruby_dln_librefs;
|
|
|
|
|
2007-11-09 06:56:38 +03:00
|
|
|
#define IS_RBEXT(e) (strcmp(e, ".rb") == 0)
|
2006-12-31 18:02:22 +03:00
|
|
|
#define IS_SOEXT(e) (strcmp(e, ".so") == 0 || strcmp(e, ".o") == 0)
|
|
|
|
#ifdef DLEXT2
|
|
|
|
#define IS_DLEXT(e) (strcmp(e, DLEXT) == 0 || strcmp(e, DLEXT2) == 0)
|
|
|
|
#else
|
|
|
|
#define IS_DLEXT(e) (strcmp(e, DLEXT) == 0)
|
|
|
|
#endif
|
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
|
|
|
|
static const char *const loadable_ext[] = {
|
|
|
|
".rb", DLEXT,
|
|
|
|
#ifdef DLEXT2
|
|
|
|
DLEXT2,
|
|
|
|
#endif
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2007-11-06 09:52:01 +03:00
|
|
|
VALUE rb_load_path; /* to be moved to VM */
|
2007-11-06 10:37:49 +03:00
|
|
|
static VALUE
|
|
|
|
get_load_path(void)
|
|
|
|
{
|
|
|
|
VALUE load_path = rb_load_path;
|
|
|
|
VALUE ary = rb_ary_new2(RARRAY_LEN(load_path));
|
|
|
|
long i;
|
|
|
|
|
|
|
|
for (i = 0; i < RARRAY_LEN(load_path); ++i) {
|
|
|
|
rb_ary_push(ary, rb_file_expand_path(RARRAY_PTR(load_path)[i], Qnil));
|
|
|
|
}
|
|
|
|
return ary;
|
|
|
|
}
|
2007-11-06 09:52:01 +03:00
|
|
|
|
2007-02-14 05:19:02 +03:00
|
|
|
static VALUE
|
|
|
|
get_loaded_features(void)
|
|
|
|
{
|
|
|
|
return GET_VM()->loaded_features;
|
|
|
|
}
|
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
static st_table *
|
|
|
|
get_loading_table(void)
|
|
|
|
{
|
|
|
|
return GET_VM()->loading_table;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2007-11-06 10:37:49 +03:00
|
|
|
for (i = 0; i < RARRAY_LEN(load_path); ++i) {
|
|
|
|
VALUE p = RARRAY_PTR(load_path)[i];
|
2007-11-06 09:52:01 +03:00
|
|
|
const char *s = StringValuePtr(p);
|
|
|
|
long n = RSTRING_LEN(p);
|
|
|
|
|
|
|
|
if (vlen < n + len + 1) continue;
|
|
|
|
if (n && (strncmp(name, s, n) || name[n] != '/')) continue;
|
|
|
|
if (strncmp(name + n + 1, feature, len)) continue;
|
|
|
|
if (name[n+len+1] && name[n+len+1] != '.') continue;
|
2007-11-09 06:56:38 +03:00
|
|
|
switch (type) {
|
|
|
|
case 's':
|
|
|
|
if (IS_DLEXT(&name[n+len+1])) return p;
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
if (IS_RBEXT(&name[n+len+1])) return p;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
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
|
|
|
{
|
2007-11-06 10:37:49 +03:00
|
|
|
VALUE v, features, 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;
|
2007-05-03 17:19:11 +04:00
|
|
|
st_table *loading_tbl;
|
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) {
|
|
|
|
len = ext - feature;
|
|
|
|
elen = strlen(ext);
|
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();
|
|
|
|
for (i = 0; i < RARRAY_LEN(features); ++i) {
|
|
|
|
v = RARRAY_PTR(features)[i];
|
2006-12-31 18:02:22 +03:00
|
|
|
f = StringValuePtr(v);
|
2007-11-06 09:52:01 +03:00
|
|
|
if ((n = RSTRING_LEN(v)) < len) continue;
|
|
|
|
if (strncmp(f, feature, len) != 0) {
|
2007-11-06 10:37:49 +03:00
|
|
|
if (expanded) continue;
|
|
|
|
if (!load_path) load_path = get_load_path();
|
2007-11-09 06:56:38 +03:00
|
|
|
if (!(p = loaded_feature_path(f, n, feature, len, type, load_path)))
|
2007-11-06 09:52:01 +03:00
|
|
|
continue;
|
|
|
|
f += RSTRING_LEN(p) + 1;
|
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
if (!*(e = f + len)) {
|
2007-05-03 17:19:11 +04:00
|
|
|
if (ext) continue;
|
2006-12-31 18:02:22 +03:00
|
|
|
return 'u';
|
|
|
|
}
|
2007-05-03 17:19:11 +04:00
|
|
|
if (*e != '.') continue;
|
2006-12-31 18:02:22 +03:00
|
|
|
if ((!rb || !ext) && (IS_SOEXT(e) || IS_DLEXT(e))) {
|
|
|
|
return 's';
|
|
|
|
}
|
2007-11-09 06:56:38 +03:00
|
|
|
if ((rb || !ext) && (IS_RBEXT(e))) {
|
2006-12-31 18:02:22 +03:00
|
|
|
return 'r';
|
|
|
|
}
|
|
|
|
}
|
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;
|
2007-11-06 10:37:49 +03:00
|
|
|
fs.load_path = load_path ? load_path : get_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;
|
|
|
|
|
|
|
|
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++) {
|
|
|
|
strncpy(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';
|
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
{
|
2007-05-03 17:19:11 +04:00
|
|
|
const char *ext = strrchr(feature, '.');
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
if (ext && !strchr(ext, '/')) {
|
2007-11-09 06:56:38 +03:00
|
|
|
if (IS_RBEXT(ext)) {
|
2007-12-24 11:06:16 +03:00
|
|
|
if (rb_feature_p(feature, ext, Qtrue, Qfalse, 0)) return Qtrue;
|
2007-05-03 17:19:11 +04:00
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
else if (IS_SOEXT(ext) || IS_DLEXT(ext)) {
|
2007-12-24 11:06:16 +03:00
|
|
|
if (rb_feature_p(feature, ext, Qfalse, Qfalse, 0)) return Qtrue;
|
2007-05-03 17:19:11 +04:00
|
|
|
return Qfalse;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
2007-12-24 11:06:16 +03:00
|
|
|
if (rb_feature_p(feature, feature + strlen(feature), Qtrue, Qfalse, 0))
|
2007-05-03 17:19:11 +04:00
|
|
|
return Qtrue;
|
2006-12-31 18:02:22 +03:00
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rb_provide_feature(VALUE feature)
|
|
|
|
{
|
2007-02-14 05:19:02 +03:00
|
|
|
rb_ary_push(get_loaded_features(), feature);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_provide(const char *feature)
|
|
|
|
{
|
|
|
|
rb_provide_feature(rb_str_new2(feature));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
void
|
|
|
|
rb_load(VALUE fname, int wrap)
|
|
|
|
{
|
|
|
|
VALUE tmp;
|
|
|
|
int state;
|
2007-02-25 19:29:26 +03:00
|
|
|
rb_thread_t *th = GET_THREAD();
|
2007-11-06 09:52:01 +03:00
|
|
|
volatile VALUE wrapper = th->top_wrapper;
|
|
|
|
volatile VALUE self = th->top_self;
|
* 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
|
|
|
volatile int parse_in_eval;
|
|
|
|
volatile int loaded = Qfalse;
|
2007-11-06 09:52:01 +03:00
|
|
|
#ifndef __GNUC__
|
|
|
|
rb_thread_t *volatile th0 = th;
|
|
|
|
#endif
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
FilePathValue(fname);
|
|
|
|
fname = rb_str_new4(fname);
|
|
|
|
tmp = rb_find_file(fname);
|
|
|
|
if (!tmp) {
|
|
|
|
load_failed(fname);
|
|
|
|
}
|
* 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
|
|
|
RB_GC_GUARD(fname) = rb_str_new4(tmp);
|
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) {
|
|
|
|
rb_secure(4); /* should alter global state */
|
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
|
|
|
}
|
|
|
|
|
* 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
|
|
|
parse_in_eval = th->parse_in_eval;
|
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;
|
|
|
|
|
|
|
|
th->parse_in_eval++;
|
|
|
|
node = (NODE *)rb_load_file(RSTRING_PTR(fname));
|
|
|
|
th->parse_in_eval--;
|
|
|
|
loaded = Qtrue;
|
|
|
|
iseq = rb_iseq_new(node, rb_str_new2("<top (required)>"),
|
|
|
|
fname, Qfalse, ISEQ_TYPE_TOP);
|
* 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();
|
|
|
|
|
2007-11-06 09:52:01 +03:00
|
|
|
#ifndef __GNUC__
|
|
|
|
th = th0;
|
|
|
|
fname = RB_GC_GUARD(fname);
|
|
|
|
#endif
|
* 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
|
|
|
th->parse_in_eval = parse_in_eval;
|
2007-02-25 19:29:26 +03:00
|
|
|
th->top_self = self;
|
|
|
|
th->top_wrapper = wrapper;
|
|
|
|
|
* 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
|
|
|
if (!loaded) {
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_exc_raise(GET_THREAD()->errinfo);
|
|
|
|
}
|
|
|
|
if (state) {
|
* vm.c: some refactoring.
* rename th_* to vm_*.
* remove unused variables functions.
* add prototypes.
* blockinlining.c, compile.c, cont.c, eval.c, eval_intern.h,
eval_jump.h, eval_load.c, inits.c, insns.def, iseq.c, parse.y,
proc.c, process.c, signal.c, thread.c, vm.c, vm_dump.c,
vm_evalbody.ci, yarvcore.c, yarvcore.h: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-06-24 19:42:41 +04:00
|
|
|
vm_jump_tag_but_local_jump(state, Qundef);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!NIL_P(GET_THREAD()->errinfo)) {
|
|
|
|
/* exception during load */
|
2007-02-25 19:29:26 +03:00
|
|
|
rb_exc_raise(th->errinfo);
|
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:
|
|
|
|
* load(filename, wrap=false) => true
|
|
|
|
*
|
|
|
|
* 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
|
|
|
{
|
|
|
|
VALUE fname, wrap;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "11", &fname, &wrap);
|
|
|
|
rb_load(fname, RTEST(wrap));
|
|
|
|
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) {
|
|
|
|
GET_VM()->loading_table = loading_tbl = st_init_strtable();
|
|
|
|
}
|
|
|
|
/* partial state */
|
|
|
|
ftptr = ruby_strdup(ftptr);
|
|
|
|
data = (st_data_t)rb_barrier_new();
|
|
|
|
st_insert(loading_tbl, (st_data_t)ftptr, data);
|
|
|
|
return (char *)ftptr;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2007-12-24 11:59:31 +03:00
|
|
|
return RTEST(rb_barrier_wait((VALUE)data)) ? (char *)ftptr : 0;
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
static void
|
|
|
|
load_unlock(const char *ftptr)
|
|
|
|
{
|
|
|
|
if (ftptr) {
|
|
|
|
st_data_t key = (st_data_t)ftptr;
|
|
|
|
st_data_t data;
|
|
|
|
st_table *loading_tbl = get_loading_table();
|
|
|
|
|
|
|
|
if (st_delete(loading_tbl, &key, &data)) {
|
|
|
|
free((char *)key);
|
|
|
|
rb_barrier_release((VALUE)data);
|
|
|
|
}
|
|
|
|
}
|
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:
|
|
|
|
* require(string) => true or false
|
|
|
|
*
|
|
|
|
* Ruby tries to load the library named _string_, returning
|
|
|
|
* +true+ if successful. If the filename does not resolve to
|
|
|
|
* an absolute path, it will be searched for in the directories listed
|
|
|
|
* in <code>$:</code>. If the file has the extension ``.rb'', it is
|
|
|
|
* loaded as a source file; if the extension is ``.so'', ``.o'', or
|
|
|
|
* ``.dll'', or whatever the default shared library extension is 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. The name of the loaded feature is added to the array in
|
|
|
|
* <code>$"</code>. A feature will not be loaded if it's name already
|
|
|
|
* appears in <code>$"</code>. However, the file name is not converted
|
|
|
|
* to an absolute path, so that ``<code>require 'a';require
|
|
|
|
* './a'</code>'' will load <code>a.rb</code> twice.
|
|
|
|
*
|
|
|
|
* require "my-library.rb"
|
|
|
|
* require "db-driver"
|
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_f_require(VALUE obj, VALUE fname)
|
|
|
|
{
|
|
|
|
return rb_require_safe(fname, rb_safe_level());
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
* 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
|
|
|
search_required(VALUE fname, volatile VALUE *path)
|
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)) {
|
2007-12-24 11:06:16 +03:00
|
|
|
if (rb_feature_p(ftptr, ext, Qtrue, Qfalse, &loading)) {
|
|
|
|
if (loading) *path = rb_str_new2(loading);
|
2006-12-31 18:02:22 +03:00
|
|
|
return 'r';
|
2007-12-24 11:06:16 +03:00
|
|
|
}
|
* 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
|
|
|
if ((tmp = rb_find_file(fname)) != 0) {
|
2006-12-31 18:02:22 +03:00
|
|
|
tmp = rb_file_expand_path(tmp, Qnil);
|
|
|
|
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
|
2007-12-24 11:06:16 +03:00
|
|
|
if (!rb_feature_p(ftptr, ext, Qtrue, Qtrue, 0))
|
2006-12-31 18:02:22 +03:00
|
|
|
*path = tmp;
|
|
|
|
return 'r';
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (IS_SOEXT(ext)) {
|
2007-12-24 11:06:16 +03:00
|
|
|
if (rb_feature_p(ftptr, ext, Qfalse, Qfalse, &loading)) {
|
|
|
|
if (loading) *path = rb_str_new2(loading);
|
2006-12-31 18:02:22 +03:00
|
|
|
return 's';
|
2007-12-24 11:06:16 +03:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
tmp = rb_str_new(RSTRING_PTR(fname), ext - RSTRING_PTR(fname));
|
|
|
|
#ifdef DLEXT2
|
|
|
|
OBJ_FREEZE(tmp);
|
|
|
|
if (rb_find_file_ext(&tmp, loadable_ext + 1)) {
|
|
|
|
tmp = rb_file_expand_path(tmp, Qnil);
|
|
|
|
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
|
2007-12-24 11:06:16 +03:00
|
|
|
if (!rb_feature_p(ftptr, ext, Qfalse, Qtrue, 0))
|
2006-12-31 18:02:22 +03:00
|
|
|
*path = tmp;
|
|
|
|
return 's';
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
rb_str_cat2(tmp, DLEXT);
|
|
|
|
OBJ_FREEZE(tmp);
|
* 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
|
|
|
if ((tmp = rb_find_file(tmp)) != 0) {
|
2006-12-31 18:02:22 +03:00
|
|
|
tmp = rb_file_expand_path(tmp, Qnil);
|
|
|
|
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
|
2007-12-24 11:06:16 +03:00
|
|
|
if (!rb_feature_p(ftptr, ext, Qfalse, Qtrue, 0))
|
2006-12-31 18:02:22 +03:00
|
|
|
*path = tmp;
|
|
|
|
return 's';
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if (IS_DLEXT(ext)) {
|
2007-12-24 11:06:16 +03:00
|
|
|
if (rb_feature_p(ftptr, ext, Qfalse, Qfalse, &loading)) {
|
|
|
|
if (loading) *path = rb_str_new2(loading);
|
2006-12-31 18:02:22 +03:00
|
|
|
return 's';
|
2007-12-24 11:06:16 +03:00
|
|
|
}
|
* 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
|
|
|
if ((tmp = rb_find_file(fname)) != 0) {
|
2006-12-31 18:02:22 +03:00
|
|
|
tmp = rb_file_expand_path(tmp, Qnil);
|
|
|
|
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
|
2007-12-24 11:06:16 +03:00
|
|
|
if (!rb_feature_p(ftptr, ext, Qfalse, Qtrue, 0))
|
2006-12-31 18:02:22 +03:00
|
|
|
*path = tmp;
|
|
|
|
return 's';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-12-24 11:06:16 +03:00
|
|
|
else if ((ft = rb_feature_p(ftptr, 0, Qfalse, Qfalse, &loading)) == 'r') {
|
|
|
|
if (loading) *path = rb_str_new2(loading);
|
2006-12-31 18:02:22 +03:00
|
|
|
return 'r';
|
|
|
|
}
|
|
|
|
tmp = fname;
|
|
|
|
type = rb_find_file_ext(&tmp, loadable_ext);
|
|
|
|
tmp = rb_file_expand_path(tmp, Qnil);
|
|
|
|
switch (type) {
|
2007-05-03 17:19:11 +04:00
|
|
|
case 0:
|
2006-12-31 18:02:22 +03:00
|
|
|
if (ft)
|
|
|
|
break;
|
2007-12-24 11:06:16 +03:00
|
|
|
ftptr = RSTRING_PTR(tmp);
|
|
|
|
return rb_feature_p(ftptr, 0, Qfalse, Qtrue, 0);
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
default:
|
2006-12-31 18:02:22 +03:00
|
|
|
if (ft)
|
|
|
|
break;
|
2007-05-03 17:19:11 +04:00
|
|
|
case 1:
|
2006-12-31 18:02:22 +03:00
|
|
|
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
|
2007-12-24 11:06:16 +03:00
|
|
|
if (rb_feature_p(ftptr, ext, !--type, Qtrue, &loading) && !loading)
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
*path = tmp;
|
|
|
|
}
|
|
|
|
return type ? 's' : 'r';
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
load_failed(VALUE fname)
|
|
|
|
{
|
|
|
|
rb_raise(rb_eLoadError, "no such file to load -- %s",
|
|
|
|
RSTRING_PTR(fname));
|
|
|
|
}
|
|
|
|
|
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);
|
2007-06-19 05:53:31 +04: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)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2007-12-24 11:06:16 +03:00
|
|
|
FilePathValue(fname);
|
|
|
|
RB_GC_GUARD(fname) = rb_str_new4(fname);
|
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);
|
|
|
|
found = search_required(fname, &path);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_set_safe_level_force(0);
|
|
|
|
switch (found) {
|
2007-05-03 17:19:11 +04:00
|
|
|
case 'r':
|
2006-12-31 18:02:22 +03:00
|
|
|
rb_load(path, 0);
|
|
|
|
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,
|
2007-06-19 05:53:31 +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();
|
2007-05-03 17:19:11 +04:00
|
|
|
load_unlock(ftptr);
|
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;
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2007-06-18 12:02:30 +04:00
|
|
|
static VALUE
|
|
|
|
init_ext_call(VALUE arg)
|
|
|
|
{
|
|
|
|
SCOPE_SET(NOEX_PUBLIC);
|
|
|
|
(*(void (*)(void))arg)();
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2007-05-03 17:19:11 +04:00
|
|
|
void
|
|
|
|
ruby_init_ext(const char *name, void (*init)(void))
|
|
|
|
{
|
|
|
|
if (load_lock(name)) {
|
* 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_vm_call_cfunc(rb_vm_top_self(), init_ext_call, (VALUE)init,
|
* 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
|
|
|
0, rb_str_new2(name));
|
2007-05-03 17:19:11 +04:00
|
|
|
rb_provide(name);
|
|
|
|
load_unlock(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mod.autoload(name, filename) => nil
|
|
|
|
*
|
|
|
|
* 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_.
|
|
|
|
*
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
Check_SafeStr(file);
|
|
|
|
rb_autoload(mod, id, RSTRING_PTR(file));
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MISSING: documentation
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_mod_autoload_p(VALUE mod, VALUE sym)
|
|
|
|
{
|
|
|
|
return rb_autoload_p(mod, rb_to_id(sym));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* autoload(module, filename) => nil
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* autoload(:MyModule, "/usr/local/lib/modules/my_module.rb")
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_f_autoload(VALUE obj, VALUE sym, VALUE file)
|
|
|
|
{
|
|
|
|
VALUE klass = ruby_cbase();
|
|
|
|
if (NIL_P(klass)) {
|
|
|
|
rb_raise(rb_eTypeError, "Can not set autoload on singleton class");
|
|
|
|
}
|
|
|
|
return rb_mod_autoload(klass, sym, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MISSING: documentation
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_f_autoload_p(VALUE obj, VALUE sym)
|
|
|
|
{
|
|
|
|
/* use ruby_cbase() as same as rb_f_autoload. */
|
|
|
|
VALUE klass = ruby_cbase();
|
|
|
|
if (NIL_P(klass)) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
return rb_mod_autoload_p(klass, sym);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Init_load()
|
|
|
|
{
|
|
|
|
rb_define_readonly_variable("$:", &rb_load_path);
|
|
|
|
rb_define_readonly_variable("$-I", &rb_load_path);
|
|
|
|
rb_define_readonly_variable("$LOAD_PATH", &rb_load_path);
|
2007-06-14 12:35:20 +04:00
|
|
|
rb_load_path = rb_ary_new();
|
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);
|
|
|
|
GET_VM()->loaded_features = rb_ary_new();
|
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);
|
|
|
|
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);
|
|
|
|
|
|
|
|
ruby_dln_librefs = rb_ary_new();
|
|
|
|
rb_register_mark_object(ruby_dln_librefs);
|
|
|
|
}
|