summaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-07-19 07:59:48 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-07-19 07:59:48 +0000
commit9be18f77bb6b3e332c4357443ee7514e471a32cf (patch)
tree2076484889834374b990ab072c386f3ce5355bc0 /eval.c
parentde3b3d59af90ad14ce2c868d74e0030e651d2031 (diff)
back port from 1.7
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@1634 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c155
1 files changed, 73 insertions, 82 deletions
diff --git a/eval.c b/eval.c
index c050507829..ff69ab028d 100644
--- a/eval.c
+++ b/eval.c
@@ -5142,8 +5142,8 @@ rb_load(fname, wrap)
VALUE fname;
int wrap;
{
+ VALUE tmp;
int state;
- char *file;
volatile ID last_func;
volatile VALUE wrapper = 0;
volatile VALUE self = ruby_top_self;
@@ -5156,10 +5156,11 @@ rb_load(fname, wrap)
else {
Check_SafeStr(fname);
}
- file = rb_find_file(RSTRING(fname)->ptr);
- if (!file) {
+ tmp = rb_find_file(fname);
+ if (!tmp) {
rb_raise(rb_eLoadError, "No such file to load -- %s", RSTRING(fname)->ptr);
}
+ fname = tmp;
ruby_errinfo = Qnil; /* ensure */
PUSH_VARS();
@@ -5184,19 +5185,8 @@ rb_load(fname, wrap)
ruby_frame->self = self;
ruby_frame->cbase = (VALUE)rb_node_newnode(NODE_CREF,ruby_class,0,0);
PUSH_SCOPE();
- if (ruby_class == rb_cObject && top_scope->local_tbl) {
- int len = top_scope->local_tbl[0]+1;
- ID *tbl = ALLOC_N(ID, len);
- VALUE *vars = TMP_ALLOC(len);
- *vars++ = 0;
- MEMCPY(tbl, top_scope->local_tbl, ID, len);
- MEMCPY(vars, top_scope->local_vars, VALUE, len-1);
- ruby_scope->local_tbl = tbl; /* copy toplevel scope */
- ruby_scope->local_vars = vars; /* will not alter toplevel variables */
- }
/* default visibility is private at loading toplevel */
SCOPE_SET(SCOPE_PRIVATE);
-
PUSH_TAG(PROT_NONE);
state = EXEC_TAG();
last_func = ruby_frame->last_func;
@@ -5205,7 +5195,7 @@ rb_load(fname, wrap)
DEFER_INTS;
ruby_in_eval++;
- rb_load_file(file);
+ rb_load_file(RSTRING(fname)->ptr);
ruby_in_eval--;
node = ruby_eval_tree;
ALLOW_INTS;
@@ -5271,18 +5261,16 @@ rb_feature_p(feature, wait)
const char *feature;
int wait;
{
- VALUE *p, *pend;
+ VALUE v;
char *f;
- int len;
+ int i, len = strlen(feature);
- p = RARRAY(rb_features)->ptr;
- pend = p + RARRAY(rb_features)->len;
- while (p < pend) {
- f = STR2CSTR(*p);
+ for (i = 0; i < RARRAY(rb_features)->len; ++i) {
+ v = RARRAY(rb_features)->ptr[i];
+ f = STR2CSTR(v);
if (strcmp(f, feature) == 0) {
goto load_wait;
}
- len = strlen(feature);
if (strncmp(f, feature, len) == 0) {
if (strcmp(f+len, ".so") == 0) {
return Qtrue;
@@ -5292,7 +5280,6 @@ rb_feature_p(feature, wait)
return Qtrue;
}
}
- p++;
}
return Qfalse;
@@ -5321,33 +5308,39 @@ rb_provided(feature)
return rb_feature_p(feature, Qfalse);
}
-void
-rb_provide(feature)
- const char *feature;
+static void
+rb_provide_feature(feature)
+ VALUE feature;
{
- char *buf, *ext;
+ char *ext;
+ char *f = RSTRING(feature)->ptr;
- ext = strrchr(feature, '.');
+ ext = strrchr(f, '.');
if (ext && (strcmp(DLEXT, ext) == 0
#ifdef DLEXT2
|| strcmp(DLEXT2, ext) == 0
#endif
)) {
- buf = ALLOCA_N(char, strlen(feature)+4);
- strcpy(buf, feature);
- ext = strrchr(buf, '.');
- strcpy(ext, ".so");
- feature = buf;
+ feature = rb_str_new(RSTRING(feature)->ptr, ext-RSTRING(feature)->ptr);
+ rb_str_cat2(feature, ".so");
}
- if (rb_feature_p(feature, Qtrue)) return;
- rb_ary_push(rb_features, rb_str_new2(feature));
+ if (rb_feature_p(RSTRING(feature)->ptr, Qtrue)) return;
+ rb_ary_push(rb_features, feature);
+}
+
+void
+rb_provide(feature)
+ const char *feature;
+{
+ rb_provide_feature(rb_str_new2(feature));
}
VALUE
rb_f_require(obj, fname)
VALUE obj, fname;
{
- char *ext, *file, *feature, *buf; /* OK */
+ VALUE feature, tmp;
+ char *ext, *ftptr; /* OK */
volatile VALUE load;
int state;
volatile int safe = ruby_safe_level;
@@ -5357,83 +5350,79 @@ rb_f_require(obj, fname)
return Qfalse;
ext = strrchr(RSTRING(fname)->ptr, '.');
if (ext) {
- feature = file = RSTRING(fname)->ptr;
if (strcmp(".rb", ext) == 0) {
- file = rb_find_file(file);
- if (file) goto load_rb;
+ feature = rb_str_dup(fname);
+ tmp = rb_find_file(fname);
+ if (tmp) {
+ fname = tmp;
+ goto load_rb;
+ }
}
else if (strcmp(".so", ext) == 0 || strcmp(".o", ext) == 0) {
- if (strcmp(ext, DLEXT) != 0) {
- buf = ALLOCA_N(char, strlen(file)+sizeof(DLEXT)+4);
- strcpy(buf, feature);
- ext = strrchr(buf, '.');
- strcpy(ext, DLEXT);
- file = feature = buf;
+ fname = rb_str_new(RSTRING(fname)->ptr, ext-RSTRING(fname)->ptr);
+ tmp = rb_str_dup(fname);
+ rb_str_cat2(tmp, DLEXT);
+ tmp = rb_find_file(tmp);
+ if (tmp) {
+ feature = fname = tmp;
+ goto load_dyna;
}
- file = rb_find_file(file);
- if (file) goto load_dyna;
#ifdef DLEXT2
- file = feature = RSTRING(fname)->ptr;
- if (strcmp(ext, DLEXT2) != 0) {
- buf = ALLOCA_N(char, strlen(file)+sizeof(DLEXT2)+4);
- strcpy(buf, feature);
- ext = strrchr(buf, '.');
- strcpy(ext, DLEXT2);
- file = feature = buf;
+ tmp = rb_str_dup(fname);
+ rb_str_cat2(tmp, DLEXT);
+ tmp = rb_find_file(tmp);
+ if (tmp) {
+ feature = fname = tmp;
+ goto load_dyna;
}
- file = rb_find_file(file);
- if (file) goto load_dyna;
#endif
}
else if (strcmp(DLEXT, ext) == 0) {
- feature = RSTRING(fname)->ptr;
- file = rb_find_file(feature);
- if (file) goto load_dyna;
+ tmp = rb_find_file(fname);
+ if (tmp) {
+ feature = fname = tmp;
+ goto load_dyna;
+ }
}
#ifdef DLEXT2
else if (strcmp(DLEXT2, ext) == 0) {
- feature = RSTRING(fname)->ptr;
- file = rb_find_file(feature);
- if (file) goto load_dyna;
+ tmp = rb_find_file(fname);
+ if (tmp) {
+ feature = fname = tmp;
+ goto load_dyna;
+ }
}
#endif
}
- obj = fname;
- if (RSTRING(fname)->ptr[0] == '~') {
- obj = rb_file_s_expand_path(1, &fname);
- }
- buf = ALLOCA_N(char, strlen(RSTRING(obj)->ptr) + 5);
- strcpy(buf, RSTRING(fname)->ptr);
- switch (rb_find_file_noext(buf)) {
+ tmp = fname;
+ switch (rb_find_file_noext(&tmp)) {
case 0:
break;
case 1:
- fname = rb_str_new2(buf);
- file = feature = buf;
+ feature = fname;
+ fname = tmp;
goto load_rb;
default:
- feature = buf;
- file = rb_find_file(buf);
+ feature = fname;
+ fname = rb_find_file(tmp);
goto load_dyna;
}
rb_raise(rb_eLoadError, "No such file to load -- %s",
RSTRING(fname)->ptr);
load_dyna:
- rb_provide(feature);
+ rb_provide_feature(feature);
{
- int old_vmode = scope_vmode;
+ int volatile old_vmode = scope_vmode;
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
void *handle;
SCOPE_SET(SCOPE_PUBLIC);
- load = rb_str_new2(file);
- file = RSTRING(load)->ptr;
- handle = dln_load(file);
+ handle = dln_load(RSTRING(fname)->ptr);
rb_ary_push(ruby_dln_librefs, INT2NUM((long)handle));
}
POP_TAG();
@@ -5445,21 +5434,22 @@ rb_f_require(obj, fname)
load_rb:
ruby_safe_level = 0;
- rb_provide(feature);
+ rb_provide_feature(feature);
/* loading ruby library should be serialized. */
if (!loading_tbl) {
loading_tbl = st_init_strtable();
}
/* partial state */
- st_insert(loading_tbl, strdup(feature), curr_thread);
+ ftptr = ruby_strdup(RSTRING(feature)->ptr);
+ st_insert(loading_tbl, ftptr, curr_thread);
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
rb_load(fname, 0);
}
POP_TAG();
- st_delete(loading_tbl, &feature, 0); /* loading done */
- free(feature);
+ st_delete(loading_tbl, &ftptr, 0); /* loading done */
+ free(ftptr);
ruby_safe_level = safe;
if (state) JUMP_TAG(state);
@@ -5643,6 +5633,7 @@ rb_mod_include(argc, argv, module)
for (i=0; i<argc; i++) {
Check_Type(argv[i], T_MODULE);
rb_funcall(argv[i], rb_intern("append_features"), 1, module);
+ rb_funcall(argv[i], rb_intern("included"), 1, module);
}
return module;
}