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"
|
|
|
|
#include "dln.h"
|
2006-12-31 18:02:22 +03:00
|
|
|
#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
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2008-12-12 05:00:55 +03:00
|
|
|
VALUE
|
|
|
|
rb_get_expanded_load_path(void)
|
|
|
|
{
|
|
|
|
VALUE load_path = rb_get_load_path();
|
2010-03-13 04:34:38 +03:00
|
|
|
VALUE ary;
|
2008-12-12 05:00:55 +03:00
|
|
|
long i;
|
|
|
|
|
2010-03-13 04:34:38 +03:00
|
|
|
for (i = 0; i < RARRAY_LEN(load_path); ++i) {
|
2010-03-13 05:16:20 +03:00
|
|
|
VALUE str = rb_check_string_type(RARRAY_PTR(load_path)[i]);
|
|
|
|
if (NIL_P(str) || !rb_is_absolute_path(RSTRING_PTR(str)))
|
2010-03-13 04:34:38 +03:00
|
|
|
goto relative_path_found;
|
|
|
|
}
|
|
|
|
return load_path;
|
|
|
|
|
|
|
|
relative_path_found:
|
|
|
|
ary = rb_ary_new2(RARRAY_LEN(load_path));
|
2008-12-12 05:00:55 +03: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 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;
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
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();
|
|
|
|
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;
|
2008-12-12 05:00:55 +03:00
|
|
|
if (!load_path) load_path = rb_get_expanded_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;
|
2008-12-12 05:00:55 +03:00
|
|
|
expanded = 1;
|
2007-11-06 09:52:01 +03:00
|
|
|
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;
|
2008-04-30 13:03:03 +04:00
|
|
|
fs.load_path = load_path ? load_path : rb_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++) {
|
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';
|
|
|
|
}
|
|
|
|
}
|
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)) {
|
|
|
|
fullpath = rb_file_expand_path(rb_str_new2(feature), Qnil);
|
|
|
|
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)
|
|
|
|
{
|
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)
|
|
|
|
{
|
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
|
|
|
|
2009-06-23 11:05:04 +04:00
|
|
|
static void
|
|
|
|
rb_load_internal(VALUE fname, int wrap)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
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;
|
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;
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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++;
|
* 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 *)rb_load_file(RSTRING_PTR(fname));
|
2009-07-18 12:05:32 +04:00
|
|
|
loaded = TRUE;
|
2010-03-16 20:40:00 +03:00
|
|
|
iseq = rb_iseq_new_top(node, rb_str_new2("<top (required)>"), fname, fname, 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();
|
|
|
|
|
2007-11-06 09:52:01 +03:00
|
|
|
#ifndef __GNUC__
|
|
|
|
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;
|
|
|
|
|
* 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: 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-19 05:38:11 +03:00
|
|
|
rb_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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
* 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
|
|
|
{
|
2009-06-23 11:05:04 +04:00
|
|
|
VALUE fname, wrap, path;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "11", &fname, &wrap);
|
2009-06-23 11: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 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) {
|
|
|
|
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
|
|
|
}
|
2009-06-13 10:03:44 +04:00
|
|
|
if (RTEST(ruby_verbose)) {
|
|
|
|
rb_warning("loading in progress, circular require considered harmful - %s", ftptr);
|
|
|
|
rb_backtrace();
|
|
|
|
}
|
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
|
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_data_t data;
|
|
|
|
st_table *loading_tbl = get_loading_table();
|
|
|
|
|
|
|
|
if (st_delete(loading_tbl, &key, &data)) {
|
2008-11-11 21:28:47 +03:00
|
|
|
VALUE barrier = (VALUE)data;
|
* array.c, bignum.c, cont.c, dir.c, dln.c, encoding.c, enumerator.c,
enumerator.c (enumerator_allocate), eval_jump.c, file.c, hash.c,
io.c, load.c, pack.c, proc.c, random.c, re.c, ruby.c, st.c,
string.c, thread.c, thread_pthread.c, time.c, util.c, variable.c,
vm.c, gc.c:
allocated memory objects by xmalloc (ruby_xmalloc) should be
freed by xfree (ruby_xfree).
* ext/curses/curses.c, ext/dbm/dbm.c, ext/digest/digest.c,
ext/gdbm/gdbm.c, ext/json/ext/parser/parser.c,
ext/json/ext/parser/unicode.c, ext/openssl/ossl_cipher.c,
ext/openssl/ossl_hmac.c, ext/openssl/ossl_pkey_ec.c,
ext/sdbm/init.c, ext/strscan/strscan.c, ext/zlib/zlib.c:
ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-08 14:01:40 +04:00
|
|
|
xfree((char *)key);
|
2008-11-11 21:28:47 +03:00
|
|
|
if (done)
|
|
|
|
rb_barrier_destroy(barrier);
|
|
|
|
else
|
|
|
|
rb_barrier_release(barrier);
|
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:
|
|
|
|
* require(string) => true or false
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* 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
|
2009-06-17 11:59:26 +04:00
|
|
|
* <code>$"</code>. A feature will not be loaded if its name already
|
|
|
|
* appears in <code>$"</code>. The file name is converted to an absolute
|
|
|
|
* path, so ``<code>require 'a'; require './a'</code>'' will not load
|
|
|
|
* <code>a.rb</code> twice.
|
2009-02-22 17:23:33 +03:00
|
|
|
*
|
2006-12-31 18:02:22 +03:00
|
|
|
* require "my-library.rb"
|
|
|
|
* require "db-driver"
|
|
|
|
*/
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_f_require(VALUE obj, VALUE fname)
|
|
|
|
{
|
|
|
|
return rb_require_safe(fname, rb_safe_level());
|
|
|
|
}
|
|
|
|
|
2010-03-16 20:40:00 +03:00
|
|
|
VALUE
|
|
|
|
rb_f_require_relative(VALUE obj, VALUE fname)
|
|
|
|
{
|
|
|
|
VALUE rb_current_realfilepath(void);
|
|
|
|
VALUE base = rb_current_realfilepath();
|
|
|
|
if (NIL_P(base)) {
|
|
|
|
rb_raise(rb_eLoadError, "cannot infer basepath");
|
|
|
|
}
|
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)) {
|
2007-12-24 11:06:16 +03:00
|
|
|
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
|
|
|
}
|
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)) {
|
2007-12-24 11:06:16 +03:00
|
|
|
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);
|
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)) {
|
2007-12-24 11:06:16 +03:00
|
|
|
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
|
|
|
}
|
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') {
|
2007-12-24 11:06:16 +03:00
|
|
|
if (loading) *path = rb_str_new2(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)
|
|
|
|
break;
|
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:
|
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), '.');
|
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)
|
|
|
|
{
|
|
|
|
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);
|
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;
|
|
|
|
|
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);
|
2009-06-23 11:05:04 +04:00
|
|
|
found = search_required(fname, &path, safe);
|
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;
|
|
|
|
}
|
|
|
|
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,
|
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();
|
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;
|
|
|
|
|
|
|
|
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);
|
2008-11-11 21:28:47 +03:00
|
|
|
load_unlock(name, 1);
|
2007-05-03 17:19:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2009-06-17 11:59:26 +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:
|
|
|
|
* mod.autoload?(name) => String or nil
|
|
|
|
*
|
|
|
|
* Returns _filename_ to be loaded if _name_ is registered as
|
|
|
|
* +autoload+ in the namespace of _mod_.
|
|
|
|
*
|
|
|
|
* module A
|
|
|
|
* end
|
|
|
|
* A.autoload(:B, "b")
|
|
|
|
* A.autoload?(:B) # => "b"
|
2006-12-31 18:02:22 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
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
|
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)
|
|
|
|
{
|
* 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
|
|
|
VALUE klass = 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:
|
|
|
|
* autoload?(name) => String or nil
|
|
|
|
*
|
|
|
|
* Returns _filename_ to be loaded if _name_ is registered as
|
|
|
|
* +autoload+.
|
|
|
|
*
|
|
|
|
* autoload(:B, "b")
|
|
|
|
* 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
|
|
|
|
Init_load()
|
|
|
|
{
|
2008-08-16 04:20:31 +04:00
|
|
|
#undef rb_intern
|
|
|
|
#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();
|
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();
|
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);
|
|
|
|
|
|
|
|
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 18:59:14 +04:00
|
|
|
rb_gc_register_mark_object(ruby_dln_librefs);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|