Skip to content

Commit

Permalink
* eval.c: remove ruby_current_node and change eval() prototype.
Browse files Browse the repository at this point in the history
  fix to use rb_sourcefile/line() instead of ruby_sourcefile/line.
* error.c, eval_error.ci, eval_load.c, eval_safe.ci, gc.c,
  include/ruby/intern.h, parse.y, process.c, ruby.c: ditto.
* vm.c: fix spaces.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
ko1 committed Jun 24, 2007
1 parent 6bd0345 commit f58eb1e
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 82 deletions.
10 changes: 10 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
Mon Jun 25 05:27:54 2007 Koichi Sasada <ko1@atdot.net>

* eval.c: remove ruby_current_node and change eval() prototype.
fix to use rb_sourcefile/line() instead of ruby_sourcefile/line.

* error.c, eval_error.ci, eval_load.c, eval_safe.ci, gc.c,
include/ruby/intern.h, parse.y, process.c, ruby.c: ditto.

* vm.c: fix spaces.

Mon Jun 25 04:20:14 2007 Koichi Sasada <ko1@atdot.net>

* eval_*.h: rename to eval_*.ci.
Expand Down
5 changes: 1 addition & 4 deletions error.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
extern const char ruby_version[], ruby_release_date[], ruby_platform[];
int ruby_nerrs;

const char *rb_sourcefile(void);
int rb_sourceline(void);

static int
err_position_0(char *buf, long len, const char *file, long line)
{
Expand All @@ -52,7 +49,7 @@ err_position(char *buf, long len)
static int
compile_position(char *buf, long len)
{
return err_position_0(buf, len, ruby_sourcefile, ruby_sourceline);
return err_position_0(buf, len, rb_sourcefile(), rb_sourceline());
}

static void
Expand Down
59 changes: 9 additions & 50 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ VALUE rb_f_block_given_p(void);
ID rb_frame_callee(void);
static VALUE rb_frame_self(void);

NODE *ruby_current_node;

static ID removed, singleton_removed, undefined, singleton_undefined;
static ID init, eqq, each, aref, aset, match, missing;
static ID added, singleton_added;
Expand All @@ -35,7 +33,7 @@ VALUE rb_eSysStackError;
extern int ruby_nerrs;
extern VALUE ruby_top_self;

static VALUE eval(VALUE, VALUE, VALUE, char *, int);
static VALUE eval(VALUE, VALUE, VALUE, const char *, int);

static inline VALUE rb_yield_0(int argc, VALUE *argv);
static VALUE rb_call(VALUE, VALUE, ID, int, const VALUE *, int);
Expand Down Expand Up @@ -270,15 +268,7 @@ ruby_run(void)
VALUE
rb_eval_string(const char *str)
{
VALUE v;
NODE *oldsrc = ruby_current_node;

ruby_current_node = 0;
ruby_sourcefile = rb_source_filename("(eval)");
v = eval(ruby_top_self, rb_str_new2(str), Qnil, 0, 0);
ruby_current_node = oldsrc;

return v;
return eval(ruby_top_self, rb_str_new2(str), Qnil, "(eval)", 0);
}

VALUE
Expand Down Expand Up @@ -324,14 +314,13 @@ rb_eval_cmd(VALUE cmd, VALUE arg, int level)
if (OBJ_TAINTED(cmd)) {
level = 4;
}
if (TYPE(cmd) != T_STRING) {

if (TYPE(cmd) != T_STRING) {
PUSH_TAG();
rb_set_safe_level_force(level);
if ((state = EXEC_TAG()) == 0) {
val =
rb_funcall2(cmd, rb_intern("call"), RARRAY_LEN(arg),
RARRAY_PTR(arg));
val = rb_funcall2(cmd, rb_intern("call"), RARRAY_LEN(arg),
RARRAY_PTR(arg));
}
POP_TAG();

Expand Down Expand Up @@ -712,7 +701,7 @@ rb_longjmp(int tag, VALUE mesg)
e = rb_obj_as_string(e);
warn_printf("Exception `%s' at %s:%d - %s\n",
rb_obj_classname(GET_THREAD()->errinfo),
ruby_sourcefile, ruby_sourceline, RSTRING_PTR(e));
rb_sourcefile(), rb_sourceline(), RSTRING_PTR(e));
}
POP_TAG();
if (status == TAG_FATAL && GET_THREAD()->errinfo == exception_error) {
Expand Down Expand Up @@ -1295,7 +1284,6 @@ rb_method_missing(int argc, const VALUE *argv, VALUE obj)
ID id;
VALUE exc = rb_eNoMethodError;
char *format = 0;
NODE *cnode = ruby_current_node;
rb_thread_t *th = GET_THREAD();
int last_call_status = th->method_missing_reason;
if (argc == 0 || !SYMBOL_P(argv[0])) {
Expand Down Expand Up @@ -1323,7 +1311,6 @@ rb_method_missing(int argc, const VALUE *argv, VALUE obj)
format = "undefined method `%s' for %s";
}

ruby_current_node = cnode;
{
int n = 0;
VALUE args[3];
Expand Down Expand Up @@ -1667,36 +1654,8 @@ rb_frame_self(void)
return GET_THREAD()->cfp->self;
}

const char *
rb_sourcefile(void)
{
rb_thread_t *th = GET_THREAD();
rb_control_frame_t *cfp = vm_get_ruby_level_cfp(th, th->cfp);

if (cfp) {
return RSTRING_PTR(cfp->iseq->filename);
}
else {
return "";
}
}

int
rb_sourceline(void)
{
rb_thread_t *th = GET_THREAD();
rb_control_frame_t *cfp = vm_get_ruby_level_cfp(th, th->cfp);

if (cfp) {
return vm_get_sourceline(cfp);
}
else {
return 0;
}
}

static VALUE
eval(VALUE self, VALUE src, VALUE scope, char *file, int line)
eval(VALUE self, VALUE src, VALUE scope, const char *file, int line)
{
int state;
VALUE result = Qundef;
Expand All @@ -1707,8 +1666,8 @@ eval(VALUE self, VALUE src, VALUE scope, char *file, int line)
NODE *stored_cref_stack = 0;

if (file == 0) {
file = ruby_sourcefile;
line = ruby_sourceline;
file = rb_sourcefile();
line = rb_sourceline();
}

PUSH_TAG();
Expand Down
47 changes: 39 additions & 8 deletions eval_error.ci
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@
* included by eval.c
*/

const char *
rb_sourcefile(void)
{
rb_thread_t *th = GET_THREAD();
rb_control_frame_t *cfp = vm_get_ruby_level_cfp(th, th->cfp);

if (cfp) {
return RSTRING_PTR(cfp->iseq->filename);
}
else {
return 0;
}
}

int
rb_sourceline(void)
{
rb_thread_t *th = GET_THREAD();
rb_control_frame_t *cfp = vm_get_ruby_level_cfp(th, th->cfp);

if (cfp) {
return vm_get_sourceline(cfp);
}
else {
return 0;
}
}

static void
warn_printf(const char *fmt, ...)
{
Expand All @@ -20,16 +48,19 @@ warn_printf(const char *fmt, ...)
static void
error_pos(void)
{
if (ruby_sourcefile) {
if (ruby_sourceline == 0) {
warn_printf("%s", ruby_sourcefile);
const char *sourcefile = rb_sourcefile();
int sourceline = rb_sourceline();

if (sourcefile) {
if (sourceline == 0) {
warn_printf("%s", sourcefile);
}
else if (rb_frame_callee()) {
warn_printf("%s:%d:in `%s'", ruby_sourcefile, ruby_sourceline,
warn_printf("%s:%d:in `%s'", sourcefile, sourceline,
rb_id2name(rb_frame_callee()));
}
else {
warn_printf("%s:%d", ruby_sourcefile, ruby_sourceline);
warn_printf("%s:%d", sourcefile, sourceline);
}
}
}
Expand Down Expand Up @@ -72,10 +103,10 @@ error_print(void)
if (EXEC_TAG())
goto error;
if (NIL_P(errat)) {
if (ruby_sourcefile)
warn_printf("%s:%d", ruby_sourcefile, ruby_sourceline);
if (rb_sourcefile())
warn_printf("%s:%d", rb_sourcefile(), rb_sourceline());
else
warn_printf("%d", ruby_sourceline);
warn_printf("%d", rb_sourceline());
}
else if (RARRAY_LEN(errat) == 0) {
error_pos();
Expand Down
3 changes: 0 additions & 3 deletions eval_intern.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,6 @@ extern VALUE sysstack_error;
void rb_thread_cleanup _((void));
void rb_thread_wait_other_threads _((void));

int rb_sourceline(void);
const char *rb_sourcefile(void);

int thread_set_raised(rb_thread_t *th);
int thread_reset_raised(rb_thread_t *th);

Expand Down
6 changes: 1 addition & 5 deletions eval_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,11 @@ rb_require_safe(VALUE fname, int safe)
volatile VALUE errinfo = th->errinfo;
int state;
struct {
NODE *node;
int safe;
} volatile saved;
char *volatile ftptr = 0;

PUSH_TAG();
saved.node = ruby_current_node;
saved.safe = rb_safe_level();
if ((state = EXEC_TAG()) == 0) {
VALUE path;
Expand All @@ -452,7 +450,6 @@ rb_require_safe(VALUE fname, int safe)
break;

case 's':
ruby_current_node = 0;
ruby_sourcefile = rb_source_filename(RSTRING_PTR(path));
ruby_sourceline = 0;
handle = (long)rb_vm_call_cfunc(ruby_top_self, load_ext,
Expand All @@ -468,7 +465,6 @@ rb_require_safe(VALUE fname, int safe)
POP_TAG();
load_unlock(ftptr);

ruby_current_node = saved.node;
rb_set_safe_level_force(saved.safe);
if (state) {
JUMP_TAG(state);
Expand Down Expand Up @@ -502,9 +498,9 @@ init_ext_call(VALUE arg)
void
ruby_init_ext(const char *name, void (*init)(void))
{
ruby_current_node = 0;
ruby_sourcefile = rb_source_filename(name);
ruby_sourceline = 0;

if (load_lock(name)) {
rb_vm_call_cfunc(ruby_top_self, init_ext_call, (VALUE)init, 0, rb_str_new2(name));
rb_provide(name);
Expand Down
3 changes: 2 additions & 1 deletion eval_safe.ci
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#define SAFE_LEVEL_MAX 4

/* $SAFE accessor */

int
rb_safe_level(void)
{
Expand All @@ -24,7 +26,6 @@ rb_set_safe_level_force(int safe)
GET_THREAD()->safe_level = safe;
}

/* $SAFE accessor */
void
rb_set_safe_level(int level)
{
Expand Down
6 changes: 2 additions & 4 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,8 @@ rb_newobj_from_heap(void)

MEMZERO((void*)obj, RVALUE, 1);
#ifdef GC_DEBUG
RANY(obj)->file = ruby_sourcefile;
RANY(obj)->line = ruby_sourceline;
RANY(obj)->file = rb_sourcefile();
RANY(obj)->line = rb_sourceline();
#endif
return obj;
}
Expand Down Expand Up @@ -1376,8 +1376,6 @@ garbage_collect(void)

init_mark_stack();

gc_mark((VALUE)ruby_current_node, 0);

th->vm->self ? rb_gc_mark(th->vm->self) : rb_vm_mark(th->vm);

if (finalizer_table) {
Expand Down
3 changes: 3 additions & 0 deletions include/ruby/intern.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ NORETURN(void rb_load_fail(const char*));
NORETURN(void rb_error_frozen(const char*));
void rb_check_frozen(VALUE);
/* eval.c */
int rb_sourceline(void);
const char *rb_sourcefile(void);

#if defined(NFDBITS) && defined(HAVE_RB_FD_INIT)
typedef struct {
int maxfd;
Expand Down
1 change: 0 additions & 1 deletion parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -4622,7 +4622,6 @@ yycompile(struct parser_params *parser, const char *f, int line)
}

kcode_save = rb_get_kcode();
ruby_current_node = 0;
ruby_sourcefile = rb_source_filename(f);
ruby_sourceline = line - 1;
parser_prepare(parser);
Expand Down
2 changes: 1 addition & 1 deletion process.c
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ rb_exec(const struct rb_exec_arg *e)
#ifndef FD_CLOEXEC
preserving_errno({
fprintf(stderr, "%s:%d: command not found: %s\n",
ruby_sourcefile, ruby_sourceline, prog);
rb_sourcefile(), rb_sourceline(), prog);
});
#endif
return -1;
Expand Down
5 changes: 0 additions & 5 deletions ruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,27 +373,22 @@ require_libraries(void)
save[0] = ruby_eval_tree;
save[1] = NEW_BEGIN(0);
ruby_eval_tree = 0;
ruby_current_node = 0;
Init_ext(); /* should be called here for some reason :-( */
ruby_current_node = save[1];
req_list_last = 0;
while (list) {
int state;

ruby_current_node = 0;
rb_protect((VALUE (*)(VALUE))rb_require, (VALUE)list->name, &state);
if (state)
rb_jump_tag(state);
tmp = list->next;
free(list->name);
free(list);
list = tmp;
ruby_current_node = save[1];
}
req_list_head.next = 0;
ruby_eval_tree = save[0];
rb_gc_force_recycle((VALUE)save[1]);
ruby_current_node = 0;
}

static void
Expand Down
1 change: 1 addition & 0 deletions vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,7 @@ rb_vm_call_cfunc(VALUE recv, VALUE (*func)(VALUE), VALUE arg, rb_block_t *blockp
vm_push_frame(th, DATA_PTR(iseq), FRAME_MAGIC_TOP,
recv, (VALUE)blockptr, 0, reg_cfp->sp, 0, 1);
val = (*func)(arg);

vm_pop_frame(th);
return val;
}

0 comments on commit f58eb1e

Please sign in to comment.