* eval.c (return_jump): set return value to the return

destination.  separated from localjump_destination().

* eval.c (break_jump): break innermost loop (or thread or proc).

* eval.c (rb_yield_0): set exit_value for block break.

* eval.c (eval): Only print backtrace if generating the backtrace
  doesn't generate an exception.  [ruby-core:02621]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@5936 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2004-03-10 08:21:07 +00:00
parent f3615ecc42
commit 9603e28844
10 changed files with 245 additions and 100 deletions

View file

@ -1,3 +1,22 @@
Wed Mar 10 16:28:42 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (return_jump): set return value to the return
destination. separated from localjump_destination().
* eval.c (break_jump): break innermost loop (or thread or proc).
* eval.c (rb_yield_0): set exit_value for block break.
Wed Mar 10 15:58:43 2004 Ryan Davis <ryand@zenspider.com>
* eval.c (eval): Only print backtrace if generating the backtrace
doesn't generate an exception. [ruby-core:02621]
Tue Mar 9 13:04:26 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (rb_io_ungetc): raise IOError instead of calling
rb_sys_fail(). [ruby-talk:23181]
Mon Mar 8 19:32:28 2004 akira yamada <akira@ruby-lang.org> Mon Mar 8 19:32:28 2004 akira yamada <akira@ruby-lang.org>
* lib/uri/common.rb (URI::REGEXP::PATTERN::HOSTPORT): (?:#{PORT}) * lib/uri/common.rb (URI::REGEXP::PATTERN::HOSTPORT): (?:#{PORT})
@ -149,6 +168,11 @@ Sat Feb 21 11:12:15 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* missing/os2.c, missing/x68.c: typo fix. pointed out by greentea. * missing/os2.c, missing/x68.c: typo fix. pointed out by greentea.
Fri Feb 20 18:59:47 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/irb/init.rb (IRB::IRB.parse_opts): add -I option to
irb. [ruby-dev:39243]
Thu Feb 19 23:24:16 2004 Dave Thomas <dave@pragprog.com> Thu Feb 19 23:24:16 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/generators/html_generator.rb (Generators::HtmlClass::build_attribute_list): * lib/rdoc/generators/html_generator.rb (Generators::HtmlClass::build_attribute_list):
@ -201,6 +225,16 @@ Wed Feb 18 17:18:01 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* ext/win32ole/win32ole.c: need to include <olectl.h> on Cygwin. * ext/win32ole/win32ole.c: need to include <olectl.h> on Cygwin.
Wed Feb 18 10:40:38 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* sprintf.c (rb_f_sprintf): do not prepend dots for negative
numbers if FZERO is specified. [ruby-dev:39218]
Tue Feb 17 23:40:34 2004 Guy Decoux <ts@moulon.inra.fr>
* sprintf.c (rb_f_sprintf): preserve original val for
format_integer. [ruby-talk:92975]
Tue Feb 17 23:28:45 2004 NAKAMURA, Hiroshi <nakahiro@sarion.co.jp> Tue Feb 17 23:28:45 2004 NAKAMURA, Hiroshi <nakahiro@sarion.co.jp>
* test/ruby/marshaltestlib.rb: common marshal testcase added. * test/ruby/marshaltestlib.rb: common marshal testcase added.

View file

@ -115,7 +115,7 @@ can be cast to retrieve the pointer to the struct. The casting macro
will be of the form RXXXX for each data type; for instance, RARRAY(obj). will be of the form RXXXX for each data type; for instance, RARRAY(obj).
See "ruby.h". See "ruby.h".
For example, `RSTRING(size)->len' is the way to get the size of the For example, `RSTRING(str)->len' is the way to get the size of the
Ruby String object. The allocated region can be accessed by Ruby String object. The allocated region can be accessed by
`RSTRING(str)->ptr'. For arrays, use `RARRAY(ary)->len' and `RSTRING(str)->ptr'. For arrays, use `RARRAY(ary)->len' and
`RARRAY(ary)->ptr' respectively. `RARRAY(ary)->ptr' respectively.

261
eval.c
View file

@ -681,6 +681,7 @@ struct BLOCK {
int iter; int iter;
int vmode; int vmode;
int flags; int flags;
int uniq;
struct RVarmap *dyna_vars; struct RVarmap *dyna_vars;
VALUE orig_thread; VALUE orig_thread;
VALUE wrapper; VALUE wrapper;
@ -693,11 +694,12 @@ struct BLOCK {
#define BLOCK_LAMBDA 2 #define BLOCK_LAMBDA 2
static struct BLOCK *ruby_block; static struct BLOCK *ruby_block;
static unsigned long block_unique = 0;
#define PUSH_BLOCK(v,b) do { \ #define PUSH_BLOCK(v,b) do { \
struct BLOCK _block; \ struct BLOCK _block; \
_block.var = v; \ _block.var = (v); \
_block.body = b; \ _block.body = (b); \
_block.self = self; \ _block.self = self; \
_block.frame = *ruby_frame; \ _block.frame = *ruby_frame; \
_block.klass = ruby_class; \ _block.klass = ruby_class; \
@ -712,6 +714,10 @@ static struct BLOCK *ruby_block;
_block.dyna_vars = ruby_dyna_vars; \ _block.dyna_vars = ruby_dyna_vars; \
_block.wrapper = ruby_wrapper; \ _block.wrapper = ruby_wrapper; \
_block.block_obj = 0; \ _block.block_obj = 0; \
_block.uniq = (b)?block_unique++:0; \
if (b) { \
prot_tag->blkid = _block.uniq; \
} \
ruby_block = &_block ruby_block = &_block
#define POP_BLOCK() \ #define POP_BLOCK() \
@ -892,6 +898,7 @@ struct tag {
struct SCOPE *scope; struct SCOPE *scope;
VALUE dst; VALUE dst;
struct tag *prev; struct tag *prev;
int blkid;
}; };
static struct tag *prot_tag; static struct tag *prot_tag;
@ -904,14 +911,15 @@ static struct tag *prot_tag;
_tag.scope = ruby_scope; \ _tag.scope = ruby_scope; \
_tag.tag = ptag; \ _tag.tag = ptag; \
_tag.dst = 0; \ _tag.dst = 0; \
_tag.blkid = 0; \
prot_tag = &_tag prot_tag = &_tag
#define PROT_NONE Qfalse /* 0 */ #define PROT_NONE Qfalse /* 0 */
#define PROT_THREAD Qtrue /* 2 */ #define PROT_THREAD Qtrue /* 2 */
#define PROT_FUNC INT2FIX(0) /* 1 */ #define PROT_FUNC INT2FIX(0) /* 1 */
#define PROT_ITER INT2FIX(1) /* 3 */ #define PROT_LOOP INT2FIX(1) /* 3 */
#define PROT_CALL INT2FIX(2) /* 5 */ #define PROT_LAMBDA INT2FIX(2) /* 5 */
#define PROT_PCALL INT2FIX(3) /* 7 */ #define PROT_YIELD INT2FIX(3) /* 7 */
#define EXEC_TAG() (FLUSH_REGISTER_WINDOWS, setjmp(prot_tag->buf)) #define EXEC_TAG() (FLUSH_REGISTER_WINDOWS, setjmp(prot_tag->buf))
@ -992,8 +1000,9 @@ static NODE *compile _((VALUE, char*, int));
static VALUE rb_yield_0 _((VALUE, VALUE, VALUE, int, int)); static VALUE rb_yield_0 _((VALUE, VALUE, VALUE, int, int));
#define YIELD_PROC_CALL 1 #define YIELD_LAMBDA_CALL 1
#define YIELD_PUBLIC_DEF 2 #define YIELD_PROC_CALL 2
#define YIELD_PUBLIC_DEF 4
#define YIELD_FUNC_AVALUE 1 #define YIELD_FUNC_AVALUE 1
#define YIELD_FUNC_SVALUE 2 #define YIELD_FUNC_SVALUE 2
@ -1256,6 +1265,7 @@ ruby_init()
} }
POP_SCOPE(); POP_SCOPE();
ruby_scope = top_scope; ruby_scope = top_scope;
top_scope->flags &= ~SCOPE_NOSTACK;
ruby_running = 1; ruby_running = 1;
} }
@ -1561,6 +1571,7 @@ rb_eval_string_wrap(str, state)
return val; return val;
} }
NORETURN(static void localjump_error(const char*, VALUE, int));
static void static void
localjump_error(mesg, value, reason) localjump_error(mesg, value, reason)
const char *mesg; const char *mesg;
@ -1617,15 +1628,14 @@ localjump_reason(exc)
return rb_iv_get(exc, "@reason"); return rb_iv_get(exc, "@reason");
} }
NORETURN(static void jump_tag_but_local_jump _((int))); NORETURN(static void jump_tag_but_local_jump _((int,VALUE)));
static void static void
jump_tag_but_local_jump(state) jump_tag_but_local_jump(state, val)
int state; int state;
{
VALUE val; VALUE val;
{
if (prot_tag) val = prot_tag->retval; if (val == Qundef) val = prot_tag->retval;
else val = Qnil;
switch (state) { switch (state) {
case 0: case 0:
break; break;
@ -1691,7 +1701,7 @@ rb_eval_cmd(cmd, arg, tcheck)
POP_TAG(); POP_TAG();
POP_FRAME(); POP_FRAME();
jump_tag_but_local_jump(state); jump_tag_but_local_jump(state, val);
return val; return val;
} }
@ -2665,7 +2675,8 @@ class_prefix(self, cpath)
}\ }\
} while (0) } while (0)
NORETURN(static void localjump_destination _((int, VALUE))); NORETURN(static void return_jump _((VALUE)));
NORETURN(static void break_jump _((VALUE)));
static VALUE static VALUE
rb_eval(self, n) rb_eval(self, n)
@ -2686,6 +2697,11 @@ rb_eval(self, n)
if (!node) RETURN(Qnil); if (!node) RETURN(Qnil);
ruby_current_node = node; ruby_current_node = node;
if (trace_func && FL_TEST(node, NODE_NEWLINE)) {
call_trace_func("line", node, self,
ruby_frame->last_func,
ruby_frame->last_class);
}
switch (nd_type(node)) { switch (nd_type(node)) {
case NODE_BLOCK: case NODE_BLOCK:
if (contnode) { if (contnode) {
@ -2737,7 +2753,7 @@ rb_eval(self, n)
/* node for speed-up(top-level loop for -n/-p) */ /* node for speed-up(top-level loop for -n/-p) */
case NODE_OPT_N: case NODE_OPT_N:
PUSH_TAG(PROT_ITER); PUSH_TAG(PROT_LOOP);
switch (state = EXEC_TAG()) { switch (state = EXEC_TAG()) {
case 0: case 0:
opt_n_next: opt_n_next:
@ -2869,7 +2885,7 @@ rb_eval(self, n)
RETURN(Qnil); RETURN(Qnil);
case NODE_WHILE: case NODE_WHILE:
PUSH_TAG(PROT_ITER); PUSH_TAG(PROT_LOOP);
result = Qnil; result = Qnil;
switch (state = EXEC_TAG()) { switch (state = EXEC_TAG()) {
case 0: case 0:
@ -2904,7 +2920,7 @@ rb_eval(self, n)
RETURN(result); RETURN(result);
case NODE_UNTIL: case NODE_UNTIL:
PUSH_TAG(PROT_ITER); PUSH_TAG(PROT_LOOP);
result = Qnil; result = Qnil;
switch (state = EXEC_TAG()) { switch (state = EXEC_TAG()) {
case 0: case 0:
@ -2945,7 +2961,7 @@ rb_eval(self, n)
case NODE_ITER: case NODE_ITER:
case NODE_FOR: case NODE_FOR:
{ {
PUSH_TAG(PROT_ITER); PUSH_TAG(PROT_LOOP);
PUSH_BLOCK(node->nd_var, node->nd_body); PUSH_BLOCK(node->nd_var, node->nd_body);
state = EXEC_TAG(); state = EXEC_TAG();
@ -2988,7 +3004,7 @@ rb_eval(self, n)
break; break;
case NODE_BREAK: case NODE_BREAK:
localjump_destination(TAG_BREAK, rb_eval(self, node->nd_stts)); break_jump(rb_eval(self, node->nd_stts));
break; break;
case NODE_NEXT: case NODE_NEXT:
@ -3177,7 +3193,7 @@ rb_eval(self, n)
break; break;
case NODE_RETURN: case NODE_RETURN:
localjump_destination(TAG_RETURN, rb_eval(self, node->nd_stts)); return_jump(rb_eval(self, node->nd_stts));
break; break;
case NODE_ARGSCAT: case NODE_ARGSCAT:
@ -3293,14 +3309,13 @@ rb_eval(self, n)
{ {
struct FRAME frame; struct FRAME frame;
NODE *saved_cref = 0; NODE *saved_cref = 0;
int jump_chain = Qfalse;
frame = *ruby_frame; frame = *ruby_frame;
frame.tmp = ruby_frame; frame.tmp = ruby_frame;
ruby_frame = &frame; ruby_frame = &frame;
PUSH_SCOPE(); PUSH_SCOPE();
PUSH_TAG(PROT_PCALL); PUSH_TAG(PROT_NONE);
if (node->nd_rval) { if (node->nd_rval) {
saved_cref = ruby_cref; saved_cref = ruby_cref;
ruby_cref = (NODE*)node->nd_rval; ruby_cref = (NODE*)node->nd_rval;
@ -3319,24 +3334,12 @@ rb_eval(self, n)
if ((state = EXEC_TAG()) == 0) { if ((state = EXEC_TAG()) == 0) {
result = rb_eval(self, node->nd_next); result = rb_eval(self, node->nd_next);
} }
else if (TAG_DST()) {
result = prot_tag->retval;
jump_chain = Qtrue;
}
POP_TAG(); POP_TAG();
POP_SCOPE(); POP_SCOPE();
ruby_frame = frame.tmp; ruby_frame = frame.tmp;
if (saved_cref) if (saved_cref)
ruby_cref = saved_cref; ruby_cref = saved_cref;
switch (state) { if (state) JUMP_TAG(state);
case 0:
break;
case TAG_RETURN:
case TAG_BREAK:
localjump_destination(state, result);
default:
JUMP_TAG(state);
}
} }
break; break;
@ -4290,7 +4293,7 @@ rb_f_abort(argc, argv)
void void
rb_iter_break() rb_iter_break()
{ {
localjump_destination(TAG_BREAK, Qnil); break_jump(Qnil);
} }
NORETURN(static void rb_longjmp _((int, VALUE))); NORETURN(static void rb_longjmp _((int, VALUE)));
@ -4512,29 +4515,84 @@ rb_f_block_given_p()
static VALUE rb_eThreadError; static VALUE rb_eThreadError;
NORETURN(static void proc_jump_error(int, VALUE));
static void static void
localjump_destination(state, retval) proc_jump_error(state, result)
int state; int state;
VALUE result;
{
char mesg[32];
char *statement;
switch (state) {
case TAG_BREAK:
statement = "break"; break;
case TAG_RETURN:
statement = "return"; break;
case TAG_RETRY:
statement = "retry"; break;
default:
statement = "local-jump"; break; /* should not happen */
}
snprintf(mesg, sizeof mesg, "%s from proc-closure", statement);
localjump_error(mesg, result, state);
}
static void
return_jump(retval)
VALUE retval; VALUE retval;
{ {
struct tag *tt = prot_tag; struct tag *tt = prot_tag;
VALUE tag = (state == TAG_BREAK) ? PROT_ITER : PROT_FUNC; int yield = Qfalse;
if (retval == Qundef) retval = Qnil; if (retval == Qundef) retval = Qnil;
while (tt) { while (tt) {
if (tt->tag == PROT_PCALL || (tt->tag == PROT_THREAD && state == TAG_BREAK) || if (tt->tag == PROT_YIELD) {
(tt->tag == PROT_CALL || tt->tag == tag) && tt->frame->uniq == ruby_frame->uniq) { yield = Qtrue;
tt = tt->prev;
}
if (tt->tag == PROT_FUNC && tt->frame->uniq == ruby_frame->uniq) {
tt->dst = (VALUE)ruby_frame->uniq; tt->dst = (VALUE)ruby_frame->uniq;
tt->retval = retval; tt->retval = retval;
JUMP_TAG(state); JUMP_TAG(TAG_RETURN);
}
if (tt->tag == PROT_LAMBDA && !yield) {
tt->dst = (VALUE)tt->frame->uniq;
tt->retval = retval;
JUMP_TAG(TAG_RETURN);
} }
if (tt->tag == PROT_FUNC && tt->frame->uniq == ruby_frame->uniq) break;
if (tt->tag == PROT_THREAD) { if (tt->tag == PROT_THREAD) {
rb_raise(rb_eThreadError, "return jump can't across threads"); rb_raise(rb_eThreadError, "return jump can't across threads");
} }
tt = tt->prev; tt = tt->prev;
} }
jump_tag_but_local_jump(state); proc_jump_error(TAG_RETURN, retval);
}
static void
break_jump(retval)
VALUE retval;
{
struct tag *tt = prot_tag;
int yield = Qfalse;
if (retval == Qundef) retval = Qnil;
while (tt) {
switch (tt->tag) {
case PROT_THREAD:
case PROT_YIELD:
case PROT_LOOP:
case PROT_LAMBDA:
tt->dst = (VALUE)tt->frame->uniq;
tt->retval = retval;
JUMP_TAG(TAG_BREAK);
break;
default:
break;
}
tt = tt->prev;
}
proc_jump_error(TAG_BREAK, retval);
} }
static VALUE static VALUE
@ -4551,6 +4609,7 @@ rb_yield_0(val, self, klass, flags, avalue)
int old_vmode; int old_vmode;
struct FRAME frame; struct FRAME frame;
NODE *cnode = ruby_current_node; NODE *cnode = ruby_current_node;
int lambda = flags & YIELD_LAMBDA_CALL;
int state; int state;
if (!rb_block_given_p()) { if (!rb_block_given_p()) {
@ -4589,7 +4648,7 @@ rb_yield_0(val, self, klass, flags, avalue)
PUSH_TAG(PROT_NONE); PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) { if ((state = EXEC_TAG()) == 0) {
if (block->var == (NODE*)1) { /* no parameter || */ if (block->var == (NODE*)1) { /* no parameter || */
if ((flags & YIELD_PROC_CALL) && RARRAY(val)->len != 0) { if (lambda && RARRAY(val)->len != 0) {
rb_raise(rb_eArgError, "wrong number of arguments (%ld for 0)", rb_raise(rb_eArgError, "wrong number of arguments (%ld for 0)",
RARRAY(val)->len); RARRAY(val)->len);
} }
@ -4604,7 +4663,7 @@ rb_yield_0(val, self, klass, flags, avalue)
if (!avalue) { if (!avalue) {
val = svalue_to_mrhs(val, block->var->nd_head); val = svalue_to_mrhs(val, block->var->nd_head);
} }
massign(self, block->var, val, flags&YIELD_PROC_CALL); massign(self, block->var, val, lambda);
} }
else { else {
int len = 0; int len = 0;
@ -4631,7 +4690,7 @@ rb_yield_0(val, self, klass, flags, avalue)
ruby_current_node = cnode; ruby_current_node = cnode;
} }
} }
assign(self, block->var, val, flags&YIELD_PROC_CALL); assign(self, block->var, val, lambda);
} }
} }
POP_TAG(); POP_TAG();
@ -4644,7 +4703,7 @@ rb_yield_0(val, self, klass, flags, avalue)
ruby_current_node = node; ruby_current_node = node;
PUSH_ITER(block->iter); PUSH_ITER(block->iter);
PUSH_TAG(PROT_NONE); PUSH_TAG(lambda ? PROT_NONE : PROT_YIELD);
if ((state = EXEC_TAG()) == 0) { if ((state = EXEC_TAG()) == 0) {
redo: redo:
if (nd_type(node) == NODE_CFUNC || nd_type(node) == NODE_IFUNC) { if (nd_type(node) == NODE_CFUNC || nd_type(node) == NODE_IFUNC) {
@ -4676,6 +4735,11 @@ rb_yield_0(val, self, klass, flags, avalue)
state = 0; state = 0;
result = prot_tag->retval; result = prot_tag->retval;
break; break;
case TAG_BREAK:
if (TAG_DST()) {
result = prot_tag->retval;
}
break;
default: default:
break; break;
} }
@ -4707,7 +4771,28 @@ rb_yield_0(val, self, klass, flags, avalue)
scope_dup(old_scope); scope_dup(old_scope);
ruby_scope = old_scope; ruby_scope = old_scope;
scope_vmode = old_vmode; scope_vmode = old_vmode;
if (state) JUMP_TAG(state); switch (state) {
case 0:
break;
case TAG_BREAK:
if (!lambda) {
struct tag *tt = prot_tag;
while (tt) {
if (tt->tag == PROT_LOOP && tt->blkid == ruby_block->uniq) {
tt->dst = (VALUE)tt->frame->uniq;
tt->retval = result;
JUMP_TAG(TAG_BREAK);
}
tt = tt->prev;
}
proc_jump_error(TAG_BREAK, result);
}
/* fall through */
default:
JUMP_TAG(state);
break;
}
ruby_current_node = cnode; ruby_current_node = cnode;
return result; return result;
} }
@ -4716,7 +4801,7 @@ VALUE
rb_yield(val) rb_yield(val)
VALUE val; VALUE val;
{ {
return rb_yield_0(val, 0, 0, Qfalse, Qfalse); return rb_yield_0(val, 0, 0, 0, Qfalse);
} }
VALUE VALUE
@ -4732,7 +4817,7 @@ rb_yield_values(n, va_alist)
VALUE ary; VALUE ary;
if (n == 0) { if (n == 0) {
return rb_yield_0(Qundef, 0, 0, Qfalse, Qfalse); return rb_yield_0(Qundef, 0, 0, 0, Qfalse);
} }
ary = rb_ary_new2(n); ary = rb_ary_new2(n);
va_init_list(args, n); va_init_list(args, n);
@ -4740,7 +4825,7 @@ rb_yield_values(n, va_alist)
rb_ary_push(ary, va_arg(args, VALUE)); rb_ary_push(ary, va_arg(args, VALUE));
} }
va_end(args); va_end(args);
return rb_yield_0(ary, 0, 0, Qfalse, Qtrue); return rb_yield_0(ary, 0, 0, 0, Qtrue);
} }
VALUE VALUE
@ -4757,7 +4842,7 @@ rb_yield_splat(values)
avalue = Qtrue; avalue = Qtrue;
} }
} }
return rb_yield_0(values, 0, 0, Qfalse, avalue); return rb_yield_0(values, 0, 0, 0, avalue);
} }
/* /*
@ -4778,7 +4863,7 @@ static VALUE
rb_f_loop() rb_f_loop()
{ {
for (;;) { for (;;) {
rb_yield_0(Qundef, 0, 0, Qfalse, Qfalse); rb_yield_0(Qundef, 0, 0, 0, Qfalse);
CHECK_INTS; CHECK_INTS;
} }
return Qnil; /* dummy */ return Qnil; /* dummy */
@ -4940,9 +5025,8 @@ rb_iterate(it_proc, data1, bl_proc, data2)
VALUE self = ruby_top_self; VALUE self = ruby_top_self;
PUSH_ITER(ITER_PRE); PUSH_ITER(ITER_PRE);
PUSH_TAG(PROT_LOOP);
PUSH_BLOCK(0, node); PUSH_BLOCK(0, node);
PUSH_TAG(PROT_ITER);
state = EXEC_TAG(); state = EXEC_TAG();
if (state == 0) { if (state == 0) {
iter_retry: iter_retry:
@ -4956,8 +5040,8 @@ rb_iterate(it_proc, data1, bl_proc, data2)
state = 0; state = 0;
goto iter_retry; goto iter_retry;
} }
POP_TAG();
POP_BLOCK(); POP_BLOCK();
POP_TAG();
POP_ITER(); POP_ITER();
switch (state) { switch (state) {
@ -5581,7 +5665,7 @@ rb_call0(klass, recv, id, oid, argc, argv, body, nosuper)
if (rb_block_given_p()) JUMP_TAG(state); if (rb_block_given_p()) JUMP_TAG(state);
/* fall through */ /* fall through */
default: default:
jump_tag_but_local_jump(state); jump_tag_but_local_jump(state, result);
break; break;
} }
} }
@ -6047,11 +6131,13 @@ eval(self, src, scope, file, line)
errat = get_backtrace(ruby_errinfo); errat = get_backtrace(ruby_errinfo);
mesg = rb_attr_get(ruby_errinfo, rb_intern("mesg")); mesg = rb_attr_get(ruby_errinfo, rb_intern("mesg"));
if (!NIL_P(mesg) && TYPE(mesg) == T_STRING) { if (!NIL_P(errat) && TYPE(errat) == T_ARRAY) {
if (!NIL_P(mesg) && TYPE(mesg) == T_STRING) {
rb_str_update(mesg, 0, 0, rb_str_new2(": ")); rb_str_update(mesg, 0, 0, rb_str_new2(": "));
rb_str_update(mesg, 0, 0, RARRAY(errat)->ptr[0]); rb_str_update(mesg, 0, 0, RARRAY(errat)->ptr[0]);
}
RARRAY(errat)->ptr[0] = RARRAY(backtrace(-2))->ptr[0];
} }
RARRAY(errat)->ptr[0] = RARRAY(backtrace(-2))->ptr[0];
} }
rb_exc_raise(ruby_errinfo); rb_exc_raise(ruby_errinfo);
} }
@ -6420,7 +6506,7 @@ rb_load(fname, wrap)
ruby_nerrs = 0; ruby_nerrs = 0;
rb_exc_raise(ruby_errinfo); rb_exc_raise(ruby_errinfo);
} }
if (state) jump_tag_but_local_jump(state); if (state) jump_tag_but_local_jump(state, Qundef);
if (!NIL_P(ruby_errinfo)) /* exception during load */ if (!NIL_P(ruby_errinfo)) /* exception during load */
rb_exc_raise(ruby_errinfo); rb_exc_raise(ruby_errinfo);
} }
@ -6991,6 +7077,9 @@ rb_mod_modfunc(argc, argv, module)
id = rb_to_id(argv[i]); id = rb_to_id(argv[i]);
for (;;) { for (;;) {
body = search_method(m, id, &m); body = search_method(m, id, &m);
if (body == 0) {
body = search_method(rb_cObject, id, &m);
}
if (body == 0 || body->nd_body == 0) { if (body == 0 || body->nd_body == 0) {
rb_bug("undefined method `%s'; can't happen", rb_id2name(id)); rb_bug("undefined method `%s'; can't happen", rb_id2name(id));
} }
@ -7462,8 +7551,7 @@ Init_eval()
rb_define_global_function("catch", rb_f_catch, 1); rb_define_global_function("catch", rb_f_catch, 1);
rb_define_global_function("throw", rb_f_throw, -1); rb_define_global_function("throw", rb_f_throw, -1);
rb_define_global_function("global_variables", rb_define_global_function("global_variables", rb_f_global_variables, 0); /* in variable.c */
rb_f_global_variables, 0); /* in variable.c */
rb_define_global_function("local_variables", rb_f_local_variables, 0); rb_define_global_function("local_variables", rb_f_local_variables, 0);
rb_define_method(rb_mKernel, "send", rb_f_send, -1); rb_define_method(rb_mKernel, "send", rb_f_send, -1);
@ -7502,10 +7590,8 @@ Init_eval()
rb_define_method(rb_mKernel, "extend", rb_obj_extend, -1); rb_define_method(rb_mKernel, "extend", rb_obj_extend, -1);
rb_define_global_function("trace_var", rb_define_global_function("trace_var", rb_f_trace_var, -1); /* in variable.c */
rb_f_trace_var, -1); /* in variable.c */ rb_define_global_function("untrace_var", rb_f_untrace_var, -1); /* in variable.c */
rb_define_global_function("untrace_var",
rb_f_untrace_var, -1); /* in variable.c */
rb_define_global_function("set_trace_func", set_trace_func, 1); rb_define_global_function("set_trace_func", set_trace_func, 1);
rb_global_variable(&trace_func); rb_global_variable(&trace_func);
@ -7942,6 +8028,8 @@ static int
block_orphan(data) block_orphan(data)
struct BLOCK *data; struct BLOCK *data;
{ {
struct tag *tt;
if (data->scope->flags & SCOPE_NOSTACK) { if (data->scope->flags & SCOPE_NOSTACK) {
return 1; return 1;
} }
@ -7976,8 +8064,8 @@ proc_invoke(proc, args, self, klass)
} }
Data_Get_Struct(proc, struct BLOCK, data); Data_Get_Struct(proc, struct BLOCK, data);
orphan = block_orphan(data); pcall = (data->flags & BLOCK_LAMBDA) ? YIELD_LAMBDA_CALL : 0;
pcall = data->flags & BLOCK_LAMBDA ? YIELD_PROC_CALL : 0; // orphan = pcall ? 0 : block_orphan(data);
if (!pcall && RARRAY(args)->len == 1) { if (!pcall && RARRAY(args)->len == 1) {
avalue = Qfalse; avalue = Qfalse;
args = RARRAY(args)->ptr[0]; args = RARRAY(args)->ptr[0];
@ -7994,13 +8082,13 @@ proc_invoke(proc, args, self, klass)
PUSH_ITER(ITER_CUR); PUSH_ITER(ITER_CUR);
ruby_frame->iter = ITER_CUR; ruby_frame->iter = ITER_CUR;
PUSH_TAG((pcall || orphan) ? PROT_PCALL : PROT_CALL); PUSH_TAG(pcall ? PROT_LAMBDA : PROT_NONE);
state = EXEC_TAG(); state = EXEC_TAG();
if (state == 0) { if (state == 0) {
proc_set_safe_level(proc); proc_set_safe_level(proc);
result = rb_yield_0(args, self, (self!=Qundef)?CLASS_OF(self):0, pcall, avalue); result = rb_yield_0(args, self, (self!=Qundef)?CLASS_OF(self):0, pcall, avalue);
} }
else if (pcall || orphan || TAG_DST()) { else if (TAG_DST()) {
result = prot_tag->retval; result = prot_tag->retval;
} }
POP_TAG(); POP_TAG();
@ -8014,21 +8102,17 @@ proc_invoke(proc, args, self, klass)
case 0: case 0:
break; break;
case TAG_RETRY: case TAG_RETRY:
if (pcall || orphan) { proc_jump_error(TAG_RETRY, Qnil); /* xxx */
localjump_error("retry from proc-closure", Qnil, state); JUMP_TAG(state);
} break;
/* fall through */
case TAG_BREAK: case TAG_BREAK:
case TAG_RETURN: if (!pcall && result != Qundef) {
if (pcall) break; proc_jump_error(state, result);
if (orphan) { /* orphan block */
char mesg[32];
snprintf(mesg, sizeof mesg, "%s from proc-closure",
state == TAG_BREAK ? "break" : "return");
localjump_error(mesg, result, state);
} }
case TAG_RETURN:
if (result != Qundef) { if (result != Qundef) {
localjump_destination(state, result); if (pcall) break;
return_jump(result);
} }
default: default:
JUMP_TAG(state); JUMP_TAG(state);
@ -8154,9 +8238,12 @@ proc_eq(self, other)
if (CLASS_OF(self) != CLASS_OF(other)) return Qfalse; if (CLASS_OF(self) != CLASS_OF(other)) return Qfalse;
Data_Get_Struct(self, struct BLOCK, data); Data_Get_Struct(self, struct BLOCK, data);
Data_Get_Struct(other, struct BLOCK, data2); Data_Get_Struct(other, struct BLOCK, data2);
if (data->dyna_vars != data2->dyna_vars) return Qfalse; if (data->body != data2->body) return Qfalse;
if (data->body == data2->body) return Qtrue; if (data->var != data2->var) return Qfalse;
return Qfalse; if (data->frame.uniq != data2->frame.uniq) return Qfalse;
if (data->flags != data2->flags) return Qfalse;
return Qtrue;
} }
/* /*
@ -8305,7 +8392,7 @@ block_pass(self, node)
if (ruby_frame->iter == ITER_NOT) if (ruby_frame->iter == ITER_NOT)
ruby_frame->iter = ITER_PRE; ruby_frame->iter = ITER_PRE;
PUSH_TAG(PROT_ITER); PUSH_TAG(PROT_LOOP);
state = EXEC_TAG(); state = EXEC_TAG();
if (state == 0) { if (state == 0) {
retry: retry:
@ -8332,7 +8419,7 @@ block_pass(self, node)
break; break;
case TAG_RETURN: case TAG_RETURN:
if (orphan) { if (orphan) {
localjump_error("return from proc-closure", prot_tag->retval, state); proc_jump_error(state, prot_tag->retval);
} }
default: default:
JUMP_TAG(state); JUMP_TAG(state);

View file

@ -651,6 +651,23 @@ sock_addrinfo(host, port, socktype, flags)
rb_raise(rb_eSocket, "getaddrinfo: %s", gai_strerror(error)); rb_raise(rb_eSocket, "getaddrinfo: %s", gai_strerror(error));
} }
#if defined(__APPLE__) && defined(__MACH__)
{
struct addrinfo *r;
r = res;
while (r) {
if (! r->ai_socktype) r->ai_socktype = hints.ai_socktype;
if (! r->ai_protocol) {
if (r->ai_socktype == SOCK_DGRAM) {
r->ai_protocol = IPPROTO_UDP;
} else if (r->ai_socktype == SOCK_STREAM) {
r->ai_protocol = IPPROTO_TCP;
}
}
r = r->ai_next;
}
}
#endif
return res; return res;
} }

5
io.c
View file

@ -1691,8 +1691,9 @@ rb_io_ungetc(io, c)
rb_raise(rb_eIOError, "unread stream"); rb_raise(rb_eIOError, "unread stream");
rb_io_check_readable(fptr); rb_io_check_readable(fptr);
if (ungetc(cc, fptr->f) == EOF && cc != EOF) if (ungetc(cc, fptr->f) == EOF && cc != EOF) {
rb_sys_fail(fptr->path); rb_raise(rb_eIOError, "ungetc failed");
}
return Qnil; return Qnil;
} }

View file

@ -182,7 +182,7 @@ module IRB
end end
if Readline.respond_to?("basic_word_break_characters=") if Readline.respond_to?("basic_word_break_characters=")
Readline.basic_word_break_characters= "\t\n\"\\'`><=;|&{(" Readline.basic_word_break_characters= " \t\n\"\\'`><=;|&{("
end end
Readline.completion_append_character = nil Readline.completion_append_character = nil
Readline.completion_proc = IRB::InputCompletor::CompletionProc Readline.completion_proc = IRB::InputCompletor::CompletionProc

View file

@ -126,6 +126,9 @@ module IRB
when "-r" when "-r"
opt = ARGV.shift opt = ARGV.shift
@CONF[:LOAD_MODULES].push opt if opt @CONF[:LOAD_MODULES].push opt if opt
when "-I"
opt = ARGV.shift
$LOAD_PATH.push opt if opt
when /^-K(.)/ when /^-K(.)/
$KCODE = $1 $KCODE = $1
when "--inspect" when "--inspect"

View file

@ -14,6 +14,7 @@ Usage: irb.rb [options] [programfile] [arguments]
-m Bc mode (load mathn, fraction or matrix are available) -m Bc mode (load mathn, fraction or matrix are available)
-d Set $DEBUG to true (same as `ruby -d') -d Set $DEBUG to true (same as `ruby -d')
-r load-module Same as `ruby -r' -r load-module Same as `ruby -r'
-I path Specify $LOAD_PATH directory
--inspect Use `inspect' for output (default except for bc mode) --inspect Use `inspect' for output (default except for bc mode)
--noinspect Don't use inspect for output --noinspect Don't use inspect for output
--readline Use Readline extension module --readline Use Readline extension module

View file

@ -14,6 +14,7 @@ Usage: irb.rb [options] [programfile] [arguments]
-m bc$B%b!<%I(B($BJ,?t(B, $B9TNs$N7W;;$,$G$-$k(B) -m bc$B%b!<%I(B($BJ,?t(B, $B9TNs$N7W;;$,$G$-$k(B)
-d $DEBUG $B$r(Btrue$B$K$9$k(B(ruby -d $B$HF1$8(B) -d $DEBUG $B$r(Btrue$B$K$9$k(B(ruby -d $B$HF1$8(B)
-r load-module ruby -r $B$HF1$8(B. -r load-module ruby -r $B$HF1$8(B.
-I path $LOAD_PATH $B$K(B path $B$rDI2C$9$k(B.
--inspect $B7k2L=PNO$K(Binspect$B$rMQ$$$k(B(bc$B%b!<%I0J30$O%G%U%)%k%H(B). --inspect $B7k2L=PNO$K(Binspect$B$rMQ$$$k(B(bc$B%b!<%I0J30$O%G%U%)%k%H(B).
--noinspect $B7k2L=PNO$K(Binspect$B$rMQ$$$J$$(B. --noinspect $B7k2L=PNO$K(Binspect$B$rMQ$$$J$$(B.
--readline readline$B%i%$%V%i%j$rMxMQ$9$k(B. --readline readline$B%i%$%V%i%j$rMxMQ$9$k(B.

View file

@ -444,6 +444,7 @@ rb_f_sprintf(argc, argv)
long v = 0; long v = 0;
int base, bignum = 0; int base, bignum = 0;
int len, pos; int len, pos;
VALUE tmp;
switch (*p) { switch (*p) {
case 'd': case 'd':
@ -544,7 +545,7 @@ rb_f_sprintf(argc, argv)
if (base == 10) { if (base == 10) {
rb_warning("negative number for %%u specifier"); rb_warning("negative number for %%u specifier");
} }
else if (!(flags&FPREC)) { if (!(flags&(FPREC|FZERO))) {
strcpy(s, ".."); strcpy(s, "..");
s += 2; s += 2;
} }
@ -571,8 +572,8 @@ rb_f_sprintf(argc, argv)
} }
if (sign) { if (sign) {
val = rb_big2str(val, base); tmp = rb_big2str(val, base);
s = RSTRING(val)->ptr; s = RSTRING(tmp)->ptr;
if (s[0] == '-') { if (s[0] == '-') {
s++; s++;
sc = '-'; sc = '-';
@ -592,8 +593,8 @@ rb_f_sprintf(argc, argv)
val = rb_big_clone(val); val = rb_big_clone(val);
rb_big_2comp(val); rb_big_2comp(val);
} }
val = rb_big2str(val, base); tmp = rb_big2str(val, base);
s = RSTRING(val)->ptr; s = RSTRING(tmp)->ptr;
if (*s == '-') { if (*s == '-') {
if (base == 10) { if (base == 10) {
rb_warning("negative number for %%u specifier"); rb_warning("negative number for %%u specifier");
@ -601,9 +602,9 @@ rb_f_sprintf(argc, argv)
} }
else { else {
remove_sign_bits(++s, base); remove_sign_bits(++s, base);
val = rb_str_new(0, 3+strlen(s)); tmp = rb_str_new(0, 3+strlen(s));
t = RSTRING(val)->ptr; t = RSTRING(tmp)->ptr;
if (!(flags&FPREC)) { if (!(flags&(FPREC|FZERO))) {
strcpy(t, ".."); strcpy(t, "..");
t += 2; t += 2;
} }
@ -619,7 +620,7 @@ rb_f_sprintf(argc, argv)
bignum = 2; bignum = 2;
} }
} }
s = RSTRING(val)->ptr; s = RSTRING(tmp)->ptr;
format_integer: format_integer:
pos = -1; pos = -1;