2006-12-31 10:02:22 -05: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-22 20: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-17 18: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-22 20:20:28 -04:00
|
|
|
#include "dln.h"
|
2006-12-31 10:02:22 -05:00
|
|
|
#include "eval_intern.h"
|
|
|
|
|
|
|
|
VALUE ruby_dln_librefs;
|
|
|
|
|
2011-05-22 08: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 10:02:22 -05:00
|
|
|
#ifdef DLEXT2
|
2011-05-22 08:52:18 -04:00
|
|
|
#define IS_DLEXT(e) (strcmp((e), DLEXT) == 0 || strcmp((e), DLEXT2) == 0)
|
2006-12-31 10:02:22 -05:00
|
|
|
#else
|
2011-05-22 08:52:18 -04:00
|
|
|
#define IS_DLEXT(e) (strcmp((e), DLEXT) == 0)
|
2006-12-31 10:02:22 -05:00
|
|
|
#endif
|
|
|
|
|
2007-05-03 09:19:11 -04:00
|
|
|
|
|
|
|
static const char *const loadable_ext[] = {
|
|
|
|
".rb", DLEXT,
|
|
|
|
#ifdef DLEXT2
|
|
|
|
DLEXT2,
|
|
|
|
#endif
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2008-04-30 05:03:03 -04:00
|
|
|
VALUE
|
|
|
|
rb_get_load_path(void)
|
2007-11-06 02:37:49 -05:00
|
|
|
{
|
2008-04-30 05:03:03 -04:00
|
|
|
VALUE load_path = GET_VM()->load_path;
|
2008-12-04 13:29:20 -05:00
|
|
|
return load_path;
|
2007-11-06 02:37:49 -05:00
|
|
|
}
|
2007-11-06 01:52:01 -05:00
|
|
|
|
2008-12-11 21:00:55 -05:00
|
|
|
VALUE
|
|
|
|
rb_get_expanded_load_path(void)
|
|
|
|
{
|
|
|
|
VALUE load_path = rb_get_load_path();
|
2010-03-12 20:34:38 -05:00
|
|
|
VALUE ary;
|
2008-12-11 21:00:55 -05:00
|
|
|
long i;
|
|
|
|
|
2010-03-12 20:34:38 -05:00
|
|
|
ary = rb_ary_new2(RARRAY_LEN(load_path));
|
2008-12-11 21:00:55 -05:00
|
|
|
for (i = 0; i < RARRAY_LEN(load_path); ++i) {
|
|
|
|
VALUE path = rb_file_expand_path(RARRAY_PTR(load_path)[i], Qnil);
|
|
|
|
rb_str_freeze(path);
|
|
|
|
rb_ary_push(ary, path);
|
|
|
|
}
|
|
|
|
rb_obj_freeze(ary);
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
2008-04-30 05:03:03 -04:00
|
|
|
static VALUE
|
|
|
|
load_path_getter(ID id, rb_vm_t *vm)
|
|
|
|
{
|
|
|
|
return vm->load_path;
|
|
|
|
}
|
|
|
|
|
2007-02-13 21:19:02 -05:00
|
|
|
static VALUE
|
|
|
|
get_loaded_features(void)
|
|
|
|
{
|
|
|
|
return GET_VM()->loaded_features;
|
|
|
|
}
|
|
|
|
|
2007-05-03 09:19:11 -04:00
|
|
|
static st_table *
|
|
|
|
get_loading_table(void)
|
|
|
|
{
|
|
|
|
return GET_VM()->loading_table;
|
|
|
|
}
|
|
|
|
|
2007-11-06 01:52:01 -05:00
|
|
|
static VALUE
|
2007-11-06 02:37:49 -05:00
|
|
|
loaded_feature_path(const char *name, long vlen, const char *feature, long len,
|
2007-11-08 22:56:38 -05:00
|
|
|
int type, VALUE load_path)
|
2007-11-06 01:52:01 -05:00
|
|
|
{
|
|
|
|
long i;
|
2011-05-31 17:56:01 -04:00
|
|
|
long plen;
|
|
|
|
const char *e;
|
|
|
|
|
|
|
|
if(vlen < len) return 0;
|
|
|
|
if (!strncmp(name+(vlen-len),feature,len)){
|
|
|
|
plen = vlen - len - 1;
|
|
|
|
} else {
|
|
|
|
for (e = name + vlen; name != e && *e != '.' && *e != '/'; --e);
|
|
|
|
if (*e!='.' ||
|
|
|
|
e-name < len ||
|
|
|
|
strncmp(e-len,feature,len) )
|
|
|
|
return 0;
|
|
|
|
plen = e - name - len - 1;
|
|
|
|
}
|
2007-11-06 02:37:49 -05:00
|
|
|
for (i = 0; i < RARRAY_LEN(load_path); ++i) {
|
|
|
|
VALUE p = RARRAY_PTR(load_path)[i];
|
2007-11-06 01:52:01 -05:00
|
|
|
const char *s = StringValuePtr(p);
|
|
|
|
long n = RSTRING_LEN(p);
|
|
|
|
|
2011-05-31 17:56:01 -04:00
|
|
|
if (n != plen ) continue;
|
2011-05-22 08:52:18 -04:00
|
|
|
if (n && (strncmp(name, s, n) || name[n] != '/')) continue;
|
2007-11-08 22:56:38 -05: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 01:52:01 -05:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct loaded_feature_searching {
|
|
|
|
const char *name;
|
|
|
|
long len;
|
2007-11-08 22:56:38 -05:00
|
|
|
int type;
|
2007-11-06 02:37:49 -05:00
|
|
|
VALUE load_path;
|
2007-11-06 01:52:01 -05: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-08 22:56:38 -05:00
|
|
|
VALUE p = loaded_feature_path(s, strlen(s), fp->name, fp->len,
|
|
|
|
fp->type, fp->load_path);
|
2007-11-06 01:52:01 -05:00
|
|
|
if (!p) return ST_CONTINUE;
|
|
|
|
fp->result = s;
|
|
|
|
return ST_STOP;
|
|
|
|
}
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
static int
|
2007-12-24 03:06:16 -05:00
|
|
|
rb_feature_p(const char *feature, const char *ext, int rb, int expanded, const char **fn)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
2007-11-06 02:37:49 -05:00
|
|
|
VALUE v, features, p, load_path = 0;
|
2007-05-03 09:19:11 -04:00
|
|
|
const char *f, *e;
|
2007-11-06 01:52:01 -05:00
|
|
|
long i, len, elen, n;
|
2007-05-03 09:19:11 -04:00
|
|
|
st_table *loading_tbl;
|
2007-12-24 03:06:16 -05:00
|
|
|
st_data_t data;
|
2007-11-08 22:56:38 -05:00
|
|
|
int type;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2007-12-24 03:06:16 -05:00
|
|
|
if (fn) *fn = 0;
|
2006-12-31 10:02:22 -05:00
|
|
|
if (ext) {
|
|
|
|
elen = strlen(ext);
|
2009-01-29 02:32:07 -05:00
|
|
|
len = strlen(feature) - elen;
|
2007-11-08 22:56:38 -05:00
|
|
|
type = rb ? 'r' : 's';
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
len = strlen(feature);
|
|
|
|
elen = 0;
|
2007-11-08 22:56:38 -05:00
|
|
|
type = 0;
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
2007-05-03 09:19:11 -04:00
|
|
|
features = get_loaded_features();
|
|
|
|
for (i = 0; i < RARRAY_LEN(features); ++i) {
|
|
|
|
v = RARRAY_PTR(features)[i];
|
2006-12-31 10:02:22 -05:00
|
|
|
f = StringValuePtr(v);
|
2007-11-06 01:52:01 -05:00
|
|
|
if ((n = RSTRING_LEN(v)) < len) continue;
|
2011-05-22 08:52:18 -04:00
|
|
|
if (strncmp(f, feature, len) != 0) {
|
2007-11-06 02:37:49 -05:00
|
|
|
if (expanded) continue;
|
2008-12-11 21:00:55 -05:00
|
|
|
if (!load_path) load_path = rb_get_expanded_load_path();
|
2007-11-08 22:56:38 -05:00
|
|
|
if (!(p = loaded_feature_path(f, n, feature, len, type, load_path)))
|
2007-11-06 01:52:01 -05:00
|
|
|
continue;
|
2008-12-11 21:00:55 -05:00
|
|
|
expanded = 1;
|
2007-11-06 01:52:01 -05:00
|
|
|
f += RSTRING_LEN(p) + 1;
|
|
|
|
}
|
2006-12-31 10:02:22 -05:00
|
|
|
if (!*(e = f + len)) {
|
2007-05-03 09:19:11 -04:00
|
|
|
if (ext) continue;
|
2006-12-31 10:02:22 -05:00
|
|
|
return 'u';
|
|
|
|
}
|
2007-05-03 09:19:11 -04:00
|
|
|
if (*e != '.') continue;
|
2006-12-31 10:02:22 -05:00
|
|
|
if ((!rb || !ext) && (IS_SOEXT(e) || IS_DLEXT(e))) {
|
|
|
|
return 's';
|
|
|
|
}
|
2007-11-08 22:56:38 -05:00
|
|
|
if ((rb || !ext) && (IS_RBEXT(e))) {
|
2006-12-31 10:02:22 -05:00
|
|
|
return 'r';
|
|
|
|
}
|
|
|
|
}
|
2007-05-03 09:19:11 -04:00
|
|
|
loading_tbl = get_loading_table();
|
|
|
|
if (loading_tbl) {
|
2007-12-24 03:06:16 -05:00
|
|
|
f = 0;
|
2007-11-06 01:52:01 -05:00
|
|
|
if (!expanded) {
|
|
|
|
struct loaded_feature_searching fs;
|
|
|
|
fs.name = feature;
|
|
|
|
fs.len = len;
|
2007-11-08 22:56:38 -05:00
|
|
|
fs.type = type;
|
2011-12-12 03:26:54 -05:00
|
|
|
fs.load_path = load_path ? load_path : rb_get_expanded_load_path();
|
2007-11-06 01:52:01 -05:00
|
|
|
fs.result = 0;
|
|
|
|
st_foreach(loading_tbl, loaded_feature_path_i, (st_data_t)&fs);
|
2007-12-24 03:06:16 -05:00
|
|
|
if ((f = fs.result) != 0) {
|
|
|
|
if (fn) *fn = f;
|
|
|
|
goto loading;
|
|
|
|
}
|
2007-11-06 01:52:01 -05:00
|
|
|
}
|
2007-12-24 03:06:16 -05:00
|
|
|
if (st_get_key(loading_tbl, (st_data_t)feature, &data)) {
|
|
|
|
if (fn) *fn = (const char*)data;
|
2007-11-06 01:52:01 -05:00
|
|
|
loading:
|
2007-05-03 09:19:11 -04:00
|
|
|
if (!ext) return 'u';
|
2007-11-08 22:56:38 -05:00
|
|
|
return !IS_RBEXT(ext) ? 's' : 'r';
|
2007-05-03 09:19:11 -04:00
|
|
|
}
|
|
|
|
else {
|
2008-01-16 01:26:33 -05:00
|
|
|
VALUE bufstr;
|
2007-05-03 09:19:11 -04:00
|
|
|
char *buf;
|
|
|
|
|
|
|
|
if (ext && *ext) return 0;
|
2008-01-16 01:26:33 -05:00
|
|
|
bufstr = rb_str_tmp_new(len + DLEXT_MAXLEN);
|
|
|
|
buf = RSTRING_PTR(bufstr);
|
2007-05-03 09:19:11 -04:00
|
|
|
MEMCPY(buf, feature, char, len);
|
|
|
|
for (i = 0; (e = loadable_ext[i]) != 0; i++) {
|
2008-12-15 21:37:45 -05:00
|
|
|
strlcpy(buf + len, e, DLEXT_MAXLEN + 1);
|
2007-12-24 03:06:16 -05:00
|
|
|
if (st_get_key(loading_tbl, (st_data_t)buf, &data)) {
|
2008-01-16 01:26:33 -05:00
|
|
|
rb_str_resize(bufstr, 0);
|
2007-12-24 03:06:16 -05:00
|
|
|
if (fn) *fn = (const char*)data;
|
2007-05-03 09:19:11 -04:00
|
|
|
return i ? 's' : 'r';
|
|
|
|
}
|
|
|
|
}
|
2008-01-16 01:26:33 -05:00
|
|
|
rb_str_resize(bufstr, 0);
|
2007-05-03 09:19:11 -04:00
|
|
|
}
|
|
|
|
}
|
2006-12-31 10:02:22 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rb_provided(const char *feature)
|
2008-12-04 13:29:20 -05:00
|
|
|
{
|
|
|
|
return rb_feature_provided(feature, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rb_feature_provided(const char *feature, const char **loading)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
2007-05-03 09:19:11 -04:00
|
|
|
const char *ext = strrchr(feature, '.');
|
2008-04-07 14:39:28 -04:00
|
|
|
volatile VALUE fullpath = 0;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2008-04-07 14:39:28 -04:00
|
|
|
if (*feature == '.' &&
|
|
|
|
(feature[1] == '/' || strncmp(feature+1, "./", 2) == 0)) {
|
|
|
|
fullpath = rb_file_expand_path(rb_str_new2(feature), Qnil);
|
|
|
|
feature = RSTRING_PTR(fullpath);
|
|
|
|
}
|
2007-05-03 09:19:11 -04:00
|
|
|
if (ext && !strchr(ext, '/')) {
|
2007-11-08 22:56:38 -05:00
|
|
|
if (IS_RBEXT(ext)) {
|
2009-08-18 07:18:25 -04:00
|
|
|
if (rb_feature_p(feature, ext, TRUE, FALSE, loading)) return TRUE;
|
2009-07-18 04:05:32 -04:00
|
|
|
return FALSE;
|
2007-05-03 09:19:11 -04:00
|
|
|
}
|
|
|
|
else if (IS_SOEXT(ext) || IS_DLEXT(ext)) {
|
2009-08-18 07:18:25 -04:00
|
|
|
if (rb_feature_p(feature, ext, FALSE, FALSE, loading)) return TRUE;
|
2009-07-18 04:05:32 -04:00
|
|
|
return FALSE;
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
}
|
2009-09-09 02:46:31 -04:00
|
|
|
if (rb_feature_p(feature, 0, TRUE, FALSE, loading))
|
2009-07-18 04:05:32 -04:00
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rb_provide_feature(VALUE feature)
|
|
|
|
{
|
2010-08-28 23:51:39 -04:00
|
|
|
if (OBJ_FROZEN(get_loaded_features())) {
|
|
|
|
rb_raise(rb_eRuntimeError,
|
|
|
|
"$LOADED_FEATURES is frozen; cannot append feature");
|
|
|
|
}
|
2007-02-13 21:19:02 -05:00
|
|
|
rb_ary_push(get_loaded_features(), feature);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_provide(const char *feature)
|
|
|
|
{
|
2009-06-13 02:00:45 -04:00
|
|
|
rb_provide_feature(rb_usascii_str_new2(feature));
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
|
2007-12-24 23:17:06 -05: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-06 20:25:05 -05:00
|
|
|
|
2009-06-23 03:05:04 -04:00
|
|
|
static void
|
|
|
|
rb_load_internal(VALUE fname, int wrap)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
|
|
|
int state;
|
2007-02-25 11:29:26 -05:00
|
|
|
rb_thread_t *th = GET_THREAD();
|
2007-11-06 01:52:01 -05:00
|
|
|
volatile VALUE wrapper = th->top_wrapper;
|
|
|
|
volatile VALUE self = th->top_self;
|
2009-07-18 04:05:32 -04:00
|
|
|
volatile int loaded = FALSE;
|
2008-07-01 12:55:30 -04:00
|
|
|
volatile int mild_compile_error;
|
2007-11-06 01:52:01 -05:00
|
|
|
#ifndef __GNUC__
|
|
|
|
rb_thread_t *volatile th0 = th;
|
|
|
|
#endif
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2007-02-25 11:29:26 -05:00
|
|
|
th->errinfo = Qnil; /* ensure */
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
if (!wrap) {
|
|
|
|
rb_secure(4); /* should alter global state */
|
2007-02-25 11:29:26 -05:00
|
|
|
th->top_wrapper = 0;
|
2006-12-31 10:02:22 -05: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 00:25:46 -04:00
|
|
|
th->top_self = rb_obj_clone(rb_vm_top_self());
|
2007-02-25 11:29:26 -05:00
|
|
|
th->top_wrapper = rb_module_new();
|
|
|
|
rb_extend_object(th->top_self, th->top_wrapper);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
|
2008-07-01 12:55:30 -04:00
|
|
|
mild_compile_error = th->mild_compile_error;
|
2007-04-24 21:35:13 -04:00
|
|
|
PUSH_TAG();
|
2006-12-31 10:02:22 -05: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 04:12:18 -04:00
|
|
|
NODE *node;
|
|
|
|
VALUE iseq;
|
|
|
|
|
2008-07-01 12:55:30 -04:00
|
|
|
th->mild_compile_error++;
|
* 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 04:12:18 -04:00
|
|
|
node = (NODE *)rb_load_file(RSTRING_PTR(fname));
|
2009-07-18 04:05:32 -04:00
|
|
|
loaded = TRUE;
|
2010-06-17 10: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 12: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 00:25:46 -04:00
|
|
|
rb_iseq_eval(iseq);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
POP_TAG();
|
|
|
|
|
2007-11-06 01:52:01 -05:00
|
|
|
#ifndef __GNUC__
|
|
|
|
th = th0;
|
|
|
|
fname = RB_GC_GUARD(fname);
|
|
|
|
#endif
|
2008-07-01 12:55:30 -04:00
|
|
|
th->mild_compile_error = mild_compile_error;
|
2007-02-25 11:29:26 -05: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 04:12:18 -04:00
|
|
|
if (!loaded) {
|
2006-12-31 10:02:22 -05:00
|
|
|
rb_exc_raise(GET_THREAD()->errinfo);
|
|
|
|
}
|
|
|
|
if (state) {
|
* vm.c: add a prefix "rb_" to exposed functions
vm_get_ruby_level_next_cfp(), rb_vm_make_env_object(),
vm_stack_to_heap(), vm_make_proc(), vm_invoke_proc(),
vm_get_sourceline(), vm_cref(), vm_localjump_error(),
vm_make_jump_tag_but_local_jump(), vm_jump_tag_but_local_jump().
This changes may affect only core because most of renamed functions
require a pointer of not-exposed struct such as rb_thread_t or NODE.
In short, they are core functions.
* cont.c, eval.c, eval_intern.h, load.c, proc.c, thread.c,
vm_core.h, vm_dump.c, vm_eval.c, vm_exec.c, vm_insnhelper.c:
ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-01-18 21:38:11 -05:00
|
|
|
rb_vm_jump_tag_but_local_jump(state, Qundef);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!NIL_P(GET_THREAD()->errinfo)) {
|
|
|
|
/* exception during load */
|
2007-02-25 11:29:26 -05:00
|
|
|
rb_exc_raise(th->errinfo);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-23 03: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 10:02:22 -05:00
|
|
|
void
|
|
|
|
rb_load_protect(VALUE fname, int wrap, int *state)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
2007-04-24 21:35:13 -04:00
|
|
|
PUSH_TAG();
|
2006-12-31 10:02:22 -05:00
|
|
|
if ((status = EXEC_TAG()) == 0) {
|
|
|
|
rb_load(fname, wrap);
|
|
|
|
}
|
2007-04-24 21:35:13 -04:00
|
|
|
POP_TAG();
|
2006-12-31 10:02:22 -05:00
|
|
|
if (state)
|
|
|
|
*state = status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-17 17:31:22 -04:00
|
|
|
* load(filename, wrap=false) -> true
|
2009-02-22 09:23:33 -05:00
|
|
|
*
|
2006-12-31 10:02:22 -05: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 02:52:39 -05:00
|
|
|
rb_f_load(int argc, VALUE *argv)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
2009-06-23 03:05:04 -04:00
|
|
|
VALUE fname, wrap, path;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "11", &fname, &wrap);
|
2009-06-23 03:05:04 -04:00
|
|
|
path = rb_find_file(FilePathValue(fname));
|
|
|
|
if (!path) {
|
|
|
|
if (!rb_file_load_ok(RSTRING_PTR(fname)))
|
|
|
|
load_failed(fname);
|
|
|
|
path = fname;
|
|
|
|
}
|
|
|
|
rb_load_internal(path, RTEST(wrap));
|
2006-12-31 10:02:22 -05:00
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
2007-05-03 09:19:11 -04:00
|
|
|
static char *
|
|
|
|
load_lock(const char *ftptr)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
2007-05-03 09: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 08:52:18 -04:00
|
|
|
GET_VM()->loading_table = loading_tbl = st_init_strtable();
|
2007-05-03 09:19:11 -04:00
|
|
|
}
|
|
|
|
/* 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 10:02:22 -05:00
|
|
|
}
|
2009-06-13 02:03:44 -04:00
|
|
|
if (RTEST(ruby_verbose)) {
|
|
|
|
rb_warning("loading in progress, circular require considered harmful - %s", ftptr);
|
|
|
|
rb_backtrace();
|
|
|
|
}
|
2007-12-24 03:59:31 -05:00
|
|
|
return RTEST(rb_barrier_wait((VALUE)data)) ? (char *)ftptr : 0;
|
2007-05-03 09:19:11 -04:00
|
|
|
}
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2007-05-03 09:19:11 -04:00
|
|
|
static void
|
2008-11-11 13:28:47 -05:00
|
|
|
load_unlock(const char *ftptr, int done)
|
2007-05-03 09:19:11 -04:00
|
|
|
{
|
|
|
|
if (ftptr) {
|
|
|
|
st_data_t key = (st_data_t)ftptr;
|
|
|
|
st_data_t data;
|
|
|
|
st_table *loading_tbl = get_loading_table();
|
2011-12-13 02:13:31 -05:00
|
|
|
VALUE barrier;
|
2007-05-03 09:19:11 -04:00
|
|
|
|
2011-12-13 02:13:31 -05:00
|
|
|
if (!st_lookup(loading_tbl, key, &data)) return;
|
|
|
|
barrier = (VALUE)data;
|
|
|
|
if (rb_barrier_waiting(barrier) ||
|
|
|
|
(st_delete(loading_tbl, &key, &data) && (xfree((char *)key), 1))) {
|
2008-11-11 13:28:47 -05:00
|
|
|
if (done)
|
|
|
|
rb_barrier_destroy(barrier);
|
|
|
|
else
|
|
|
|
rb_barrier_release(barrier);
|
2007-05-03 09:19:11 -04:00
|
|
|
}
|
|
|
|
}
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
|
2007-05-03 09:19:11 -04:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2011-08-23 02:26:11 -04:00
|
|
|
* require(name) -> true or false
|
2009-02-22 09:23:33 -05:00
|
|
|
*
|
2011-08-23 02:26:11 -04:00
|
|
|
* Loads the given +name+, returning +true+ if successful and +false+ if the
|
|
|
|
* feature is already loaded.
|
2009-02-22 09:23:33 -05:00
|
|
|
*
|
2011-08-23 02: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"
|
2006-12-31 10:02:22 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_f_require(VALUE obj, VALUE fname)
|
|
|
|
{
|
|
|
|
return rb_require_safe(fname, rb_safe_level());
|
|
|
|
}
|
|
|
|
|
2010-12-24 21:07:13 -05: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-24 22:48:57 -05:00
|
|
|
VALUE
|
2010-03-16 13:40:00 -04:00
|
|
|
rb_f_require_relative(VALUE obj, VALUE fname)
|
|
|
|
{
|
|
|
|
VALUE base = rb_current_realfilepath();
|
|
|
|
if (NIL_P(base)) {
|
|
|
|
rb_raise(rb_eLoadError, "cannot infer basepath");
|
|
|
|
}
|
2010-03-30 05: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 13:40:00 -04:00
|
|
|
}
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
static int
|
2009-06-23 03:05:04 -04:00
|
|
|
search_required(VALUE fname, volatile VALUE *path, int safe_level)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
|
|
|
VALUE tmp;
|
|
|
|
char *ext, *ftptr;
|
|
|
|
int type, ft = 0;
|
2007-12-24 03:06:16 -05:00
|
|
|
const char *loading;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
*path = 0;
|
|
|
|
ext = strrchr(ftptr = RSTRING_PTR(fname), '.');
|
|
|
|
if (ext && !strchr(ext, '/')) {
|
2007-11-08 22:56:38 -05:00
|
|
|
if (IS_RBEXT(ext)) {
|
2009-07-18 04:05:32 -04:00
|
|
|
if (rb_feature_p(ftptr, ext, TRUE, FALSE, &loading)) {
|
2007-12-24 03:06:16 -05:00
|
|
|
if (loading) *path = rb_str_new2(loading);
|
2006-12-31 10:02:22 -05:00
|
|
|
return 'r';
|
2007-12-24 03:06:16 -05:00
|
|
|
}
|
2009-06-23 03:05:04 -04:00
|
|
|
if ((tmp = rb_find_file_safe(fname, safe_level)) != 0) {
|
2006-12-31 10:02:22 -05:00
|
|
|
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
|
2009-07-18 04:05:32 -04:00
|
|
|
if (!rb_feature_p(ftptr, ext, TRUE, TRUE, &loading) || loading)
|
2006-12-31 10:02:22 -05:00
|
|
|
*path = tmp;
|
|
|
|
return 'r';
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (IS_SOEXT(ext)) {
|
2009-07-18 04:05:32 -04:00
|
|
|
if (rb_feature_p(ftptr, ext, FALSE, FALSE, &loading)) {
|
2007-12-24 03:06:16 -05:00
|
|
|
if (loading) *path = rb_str_new2(loading);
|
2006-12-31 10:02:22 -05:00
|
|
|
return 's';
|
2007-12-24 03:06:16 -05:00
|
|
|
}
|
2006-12-31 10:02:22 -05:00
|
|
|
tmp = rb_str_new(RSTRING_PTR(fname), ext - RSTRING_PTR(fname));
|
|
|
|
#ifdef DLEXT2
|
|
|
|
OBJ_FREEZE(tmp);
|
2009-06-23 03:05:04 -04:00
|
|
|
if (rb_find_file_ext_safe(&tmp, loadable_ext + 1, safe_level)) {
|
2006-12-31 10:02:22 -05:00
|
|
|
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
|
2009-09-09 02:46:31 -04:00
|
|
|
if (!rb_feature_p(ftptr, ext, FALSE, TRUE, &loading) || loading)
|
2006-12-31 10:02:22 -05:00
|
|
|
*path = tmp;
|
|
|
|
return 's';
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
rb_str_cat2(tmp, DLEXT);
|
|
|
|
OBJ_FREEZE(tmp);
|
2009-06-23 03:05:04 -04:00
|
|
|
if ((tmp = rb_find_file_safe(tmp, safe_level)) != 0) {
|
2006-12-31 10:02:22 -05:00
|
|
|
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
|
2009-07-18 04:05:32 -04:00
|
|
|
if (!rb_feature_p(ftptr, ext, FALSE, TRUE, &loading) || loading)
|
2006-12-31 10:02:22 -05:00
|
|
|
*path = tmp;
|
|
|
|
return 's';
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if (IS_DLEXT(ext)) {
|
2009-07-18 04:05:32 -04:00
|
|
|
if (rb_feature_p(ftptr, ext, FALSE, FALSE, &loading)) {
|
2007-12-24 03:06:16 -05:00
|
|
|
if (loading) *path = rb_str_new2(loading);
|
2006-12-31 10:02:22 -05:00
|
|
|
return 's';
|
2007-12-24 03:06:16 -05:00
|
|
|
}
|
2009-06-23 03:05:04 -04:00
|
|
|
if ((tmp = rb_find_file_safe(fname, safe_level)) != 0) {
|
2006-12-31 10:02:22 -05:00
|
|
|
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
|
2009-07-18 04:05:32 -04:00
|
|
|
if (!rb_feature_p(ftptr, ext, FALSE, TRUE, &loading) || loading)
|
2006-12-31 10:02:22 -05:00
|
|
|
*path = tmp;
|
|
|
|
return 's';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-18 04:05:32 -04:00
|
|
|
else if ((ft = rb_feature_p(ftptr, 0, FALSE, FALSE, &loading)) == 'r') {
|
2007-12-24 03:06:16 -05:00
|
|
|
if (loading) *path = rb_str_new2(loading);
|
2006-12-31 10:02:22 -05:00
|
|
|
return 'r';
|
|
|
|
}
|
|
|
|
tmp = fname;
|
2009-06-23 03:05:04 -04:00
|
|
|
type = rb_find_file_ext_safe(&tmp, loadable_ext, safe_level);
|
2006-12-31 10:02:22 -05:00
|
|
|
switch (type) {
|
2007-05-03 09:19:11 -04:00
|
|
|
case 0:
|
2006-12-31 10:02:22 -05:00
|
|
|
if (ft)
|
|
|
|
break;
|
2007-12-24 03:06:16 -05:00
|
|
|
ftptr = RSTRING_PTR(tmp);
|
2009-07-18 04:05:32 -04:00
|
|
|
return rb_feature_p(ftptr, 0, FALSE, TRUE, 0);
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2007-05-03 09:19:11 -04:00
|
|
|
default:
|
2006-12-31 10:02:22 -05:00
|
|
|
if (ft)
|
|
|
|
break;
|
2007-05-03 09:19:11 -04:00
|
|
|
case 1:
|
2006-12-31 10:02:22 -05:00
|
|
|
ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
|
2009-07-18 04:05:32 -04:00
|
|
|
if (rb_feature_p(ftptr, ext, !--type, TRUE, &loading) && !loading)
|
2006-12-31 10:02:22 -05:00
|
|
|
break;
|
|
|
|
*path = tmp;
|
|
|
|
}
|
|
|
|
return type ? 's' : 'r';
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
load_failed(VALUE fname)
|
|
|
|
{
|
2010-08-28 23:20:04 -04:00
|
|
|
VALUE mesg = rb_str_buf_new_cstr("cannot load such file -- ");
|
|
|
|
rb_str_append(mesg, fname); /* should be ASCII compatible */
|
|
|
|
rb_exc_raise(rb_exc_new3(rb_eLoadError, mesg));
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
|
2007-06-18 04:02:30 -04:00
|
|
|
static VALUE
|
2007-06-18 21:53:31 -04:00
|
|
|
load_ext(VALUE path)
|
2007-06-18 04:02:30 -04:00
|
|
|
{
|
|
|
|
SCOPE_SET(NOEX_PUBLIC);
|
2010-02-23 21:52:08 -05:00
|
|
|
return (VALUE)dln_load(RSTRING_PTR(path));
|
2007-06-18 04:02:30 -04:00
|
|
|
}
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
VALUE
|
|
|
|
rb_require_safe(VALUE fname, int safe)
|
|
|
|
{
|
2009-06-13 01: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 01:37:46 -05:00
|
|
|
rb_thread_t *th = GET_THREAD();
|
2007-05-03 09:19:11 -04:00
|
|
|
volatile VALUE errinfo = th->errinfo;
|
2006-12-31 10:02:22 -05:00
|
|
|
int state;
|
2007-02-20 19:14:07 -05:00
|
|
|
struct {
|
|
|
|
int safe;
|
|
|
|
} volatile saved;
|
2006-12-31 10:02:22 -05:00
|
|
|
char *volatile ftptr = 0;
|
|
|
|
|
2007-04-24 21:35:13 -04:00
|
|
|
PUSH_TAG();
|
2007-02-20 19:14:07 -05:00
|
|
|
saved.safe = rb_safe_level();
|
2006-12-31 10:02:22 -05:00
|
|
|
if ((state = EXEC_TAG()) == 0) {
|
|
|
|
VALUE path;
|
|
|
|
long handle;
|
|
|
|
int found;
|
|
|
|
|
|
|
|
rb_set_safe_level_force(safe);
|
2008-04-07 21:40:49 -04:00
|
|
|
FilePathValue(fname);
|
2009-01-31 05:07:49 -05:00
|
|
|
rb_set_safe_level_force(0);
|
2009-06-23 03:05:04 -04:00
|
|
|
found = search_required(fname, &path, safe);
|
2006-12-31 10:02:22 -05:00
|
|
|
if (found) {
|
2007-05-03 09:19:11 -04:00
|
|
|
if (!path || !(ftptr = load_lock(RSTRING_PTR(path)))) {
|
2006-12-31 10:02:22 -05:00
|
|
|
result = Qfalse;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (found) {
|
2007-05-03 09:19:11 -04:00
|
|
|
case 'r':
|
2009-06-23 03:05:04 -04:00
|
|
|
rb_load_internal(path, 0);
|
2006-12-31 10:02:22 -05:00
|
|
|
break;
|
|
|
|
|
2007-05-03 09: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 00:25:46 -04:00
|
|
|
handle = (long)rb_vm_call_cfunc(rb_vm_top_self(), load_ext,
|
2010-06-17 10:32:20 -04:00
|
|
|
path, 0, path);
|
2006-12-31 10:02:22 -05:00
|
|
|
rb_ary_push(ruby_dln_librefs, LONG2NUM(handle));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rb_provide_feature(path);
|
|
|
|
result = Qtrue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
POP_TAG();
|
2008-11-11 13:28:47 -05:00
|
|
|
load_unlock(ftptr, !state);
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2007-02-20 19:14:07 -05:00
|
|
|
rb_set_safe_level_force(saved.safe);
|
2006-12-31 10:02:22 -05: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 04:02:30 -04:00
|
|
|
static VALUE
|
|
|
|
init_ext_call(VALUE arg)
|
|
|
|
{
|
|
|
|
SCOPE_SET(NOEX_PUBLIC);
|
|
|
|
(*(void (*)(void))arg)();
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2010-09-03 21:41:04 -04:00
|
|
|
RUBY_FUNC_EXPORTED void
|
2007-05-03 09:19:11 -04:00
|
|
|
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 00:25:46 -04:00
|
|
|
rb_vm_call_cfunc(rb_vm_top_self(), init_ext_call, (VALUE)init,
|
2010-06-17 10:32:20 -04:00
|
|
|
0, rb_str_new2(name));
|
2007-05-03 09:19:11 -04:00
|
|
|
rb_provide(name);
|
2008-11-11 13:28:47 -05:00
|
|
|
load_unlock(name, 1);
|
2007-05-03 09:19:11 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-17 17:31:22 -04:00
|
|
|
* mod.autoload(module, filename) -> nil
|
2009-02-22 09:23:33 -05:00
|
|
|
*
|
2006-12-31 10:02:22 -05: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 09:23:33 -05:00
|
|
|
*
|
2006-12-31 10:02:22 -05: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 01:57:41 -04:00
|
|
|
FilePathValue(file);
|
2006-12-31 10:02:22 -05:00
|
|
|
rb_autoload(mod, id, RSTRING_PTR(file));
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2009-09-23 15:45:37 -04:00
|
|
|
* call-seq:
|
2010-05-17 17:31:22 -04:00
|
|
|
* mod.autoload?(name) -> String or nil
|
2009-09-23 15: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-17 17:07:33 -04:00
|
|
|
* A.autoload?(:B) #=> "b"
|
2006-12-31 10:02:22 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_mod_autoload_p(VALUE mod, VALUE sym)
|
|
|
|
{
|
2011-07-26 12:05:35 -04:00
|
|
|
ID id = rb_check_id(&sym);
|
|
|
|
if (!id) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
return rb_autoload_p(mod, id);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq:
|
2010-05-17 17:31:22 -04:00
|
|
|
* autoload(module, filename) -> nil
|
2009-02-22 09:23:33 -05:00
|
|
|
*
|
2006-12-31 10:02:22 -05: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 09:23:33 -05:00
|
|
|
*
|
2006-12-31 10:02:22 -05:00
|
|
|
* autoload(:MyModule, "/usr/local/lib/modules/my_module.rb")
|
|
|
|
*/
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_f_autoload(VALUE obj, VALUE sym, VALUE file)
|
|
|
|
{
|
2011-07-10 02:32:06 -04:00
|
|
|
VALUE klass = rb_class_real(rb_vm_cbase());
|
2006-12-31 10:02:22 -05: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 15:45:37 -04:00
|
|
|
* call-seq:
|
2010-05-17 17:31:22 -04:00
|
|
|
* autoload?(name) -> String or nil
|
2009-09-23 15:45:37 -04:00
|
|
|
*
|
|
|
|
* Returns _filename_ to be loaded if _name_ is registered as
|
|
|
|
* +autoload+.
|
|
|
|
*
|
|
|
|
* autoload(:B, "b")
|
2010-05-17 17:07:33 -04:00
|
|
|
* autoload?(:B) #=> "b"
|
2006-12-31 10:02:22 -05: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-18 23:08:50 -04:00
|
|
|
/* use rb_vm_cbase() as same as rb_f_autoload. */
|
|
|
|
VALUE klass = rb_vm_cbase();
|
2006-12-31 10:02:22 -05:00
|
|
|
if (NIL_P(klass)) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
return rb_mod_autoload_p(klass, sym);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Init_load()
|
|
|
|
{
|
2008-08-15 20:20:31 -04:00
|
|
|
#undef rb_intern
|
2010-12-18 00:43:01 -05:00
|
|
|
#define rb_intern(str) rb_intern2((str), strlen(str))
|
2008-04-30 05:03:03 -04:00
|
|
|
rb_vm_t *vm = GET_VM();
|
2008-08-15 20: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 05:03:03 -04:00
|
|
|
|
2009-06-21 09:35:41 -04:00
|
|
|
rb_define_hooked_variable(var_load_path, (VALUE*)vm, load_path_getter, rb_gvar_readonly_setter);
|
2008-08-15 20: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 05:03:03 -04:00
|
|
|
vm->load_path = rb_ary_new();
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2007-02-13 21:19:02 -05:00
|
|
|
rb_define_virtual_variable("$\"", get_loaded_features, 0);
|
|
|
|
rb_define_virtual_variable("$LOADED_FEATURES", get_loaded_features, 0);
|
2008-04-30 05:03:03 -04:00
|
|
|
vm->loaded_features = rb_ary_new();
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
rb_define_global_function("load", rb_f_load, -1);
|
|
|
|
rb_define_global_function("require", rb_f_require, 1);
|
2010-03-16 13:40:00 -04:00
|
|
|
rb_define_global_function("require_relative", rb_f_require_relative, 1);
|
2006-12-31 10:02:22 -05: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);
|
|
|
|
|
|
|
|
ruby_dln_librefs = rb_ary_new();
|
* 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 10:59:14 -04:00
|
|
|
rb_gc_register_mark_object(ruby_dln_librefs);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|