* string.c (rb_str_upto): method result must be checked. [ruby-dev:24504]

* eval.c (error_print): ditto.  [ruby-dev:24519]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7065 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2004-10-18 23:47:32 +00:00
parent f2549e0bf7
commit 39324f819f
3 changed files with 64 additions and 56 deletions

View File

@ -1,3 +1,9 @@
Tue Oct 19 08:47:21 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (rb_str_upto): method result must be checked. [ruby-dev:24504]
* eval.c (error_print): ditto. [ruby-dev:24519]
Mon Oct 18 23:37:05 2004 Nobuyoshi Nakada <nobu@ruby-lang.org> Mon Oct 18 23:37:05 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* marshal.c (r_object0): check inheritance by the internal function. * marshal.c (r_object0): check inheritance by the internal function.

95
eval.c
View File

@ -455,7 +455,7 @@ rb_method_node(klass, id)
{ {
int noex; int noex;
struct cache_entry *ent; struct cache_entry *ent;
ent = cache + EXPR1(klass, id); ent = cache + EXPR1(klass, id);
if (ent->mid == id && ent->klass == klass && ent->method){ if (ent->mid == id && ent->klass == klass && ent->method){
return ent->method; return ent->method;
@ -733,9 +733,9 @@ struct RVarmap *ruby_dyna_vars;
ruby_dyna_vars = 0 ruby_dyna_vars = 0
#define POP_VARS() \ #define POP_VARS() \
if (_old && (ruby_scope->flags & SCOPE_DONT_RECYCLE)) {\ if (_old && (ruby_scope->flags & SCOPE_DONT_RECYCLE)) {\
if (RBASIC(_old)->flags) /* unless it's already recycled */ \ if (RBASIC(_old)->flags) /* unless it's already recycled */ \
FL_SET(_old, DVAR_DONT_RECYCLE); \ FL_SET(_old, DVAR_DONT_RECYCLE); \
}\ }\
ruby_dyna_vars = _old; \ ruby_dyna_vars = _old; \
} while (0) } while (0)
@ -983,15 +983,15 @@ static void scope_dup _((struct SCOPE *));
#define POP_SCOPE() \ #define POP_SCOPE() \
if (ruby_scope->flags & SCOPE_DONT_RECYCLE) {\ if (ruby_scope->flags & SCOPE_DONT_RECYCLE) {\
if (_old) scope_dup(_old); \ if (_old) scope_dup(_old); \
} \ } \
if (!(ruby_scope->flags & SCOPE_MALLOC)) {\ if (!(ruby_scope->flags & SCOPE_MALLOC)) {\
ruby_scope->local_vars = 0; \ ruby_scope->local_vars = 0; \
ruby_scope->local_tbl = 0; \ ruby_scope->local_tbl = 0; \
if (!(ruby_scope->flags & SCOPE_DONT_RECYCLE) && \ if (!(ruby_scope->flags & SCOPE_DONT_RECYCLE) && \
ruby_scope != top_scope) { \ ruby_scope != top_scope) { \
rb_gc_force_recycle((VALUE)ruby_scope);\ rb_gc_force_recycle((VALUE)ruby_scope);\
} \ } \
} \ } \
ruby_scope->flags |= SCOPE_NOSTACK; \ ruby_scope->flags |= SCOPE_NOSTACK; \
ruby_scope = _old; \ ruby_scope = _old; \
@ -1031,7 +1031,7 @@ void
ruby_set_current_source() ruby_set_current_source()
{ {
if (ruby_current_node) { if (ruby_current_node) {
ruby_sourcefile = ruby_current_node->nd_file; ruby_sourcefile = ruby_current_node->nd_file;
ruby_sourceline = nd_line(ruby_current_node); ruby_sourceline = nd_line(ruby_current_node);
} }
} }
@ -1130,6 +1130,7 @@ error_print()
eclass = CLASS_OF(ruby_errinfo); eclass = CLASS_OF(ruby_errinfo);
if (EXEC_TAG() == 0) { if (EXEC_TAG() == 0) {
e = rb_funcall(ruby_errinfo, rb_intern("message"), 0, 0); e = rb_funcall(ruby_errinfo, rb_intern("message"), 0, 0);
StringValue(e);
einfo = RSTRING(e)->ptr; einfo = RSTRING(e)->ptr;
elen = RSTRING(e)->len; elen = RSTRING(e)->len;
} }
@ -1209,7 +1210,7 @@ void Init_ext _((void));
#ifdef HAVE_NATIVETHREAD #ifdef HAVE_NATIVETHREAD
static rb_nativethread_t ruby_thid; static rb_nativethread_t ruby_thid;
int int
is_ruby_native_thread() { is_ruby_native_thread() {
return NATIVETHREAD_EQUAL(ruby_thid, NATIVETHREAD_CURRENT()); return NATIVETHREAD_EQUAL(ruby_thid, NATIVETHREAD_CURRENT());
} }
@ -1712,7 +1713,7 @@ rb_eval_cmd(cmd, arg, level)
val = eval(ruby_top_self, cmd, Qnil, 0, 0); val = eval(ruby_top_self, cmd, Qnil, 0, 0);
} }
if (ruby_scope->flags & SCOPE_DONT_RECYCLE) if (ruby_scope->flags & SCOPE_DONT_RECYCLE)
scope_dup(saved_scope); scope_dup(saved_scope);
ruby_scope = saved_scope; ruby_scope = saved_scope;
ruby_safe_level = safe; ruby_safe_level = safe;
POP_TAG(); POP_TAG();
@ -2093,25 +2094,25 @@ copy_node_scope(node, rval)
}\ }\
else if (nd_type(n) == NODE_ARRAY) {\ else if (nd_type(n) == NODE_ARRAY) {\
argc=alen;\ argc=alen;\
if (argc > 0) {\ if (argc > 0) {\
int i;\ int i;\
n = anode;\ n = anode;\
argv = TMP_ALLOC(argc);\ argv = TMP_ALLOC(argc);\
for (i=0;i<argc;i++) {\ for (i=0;i<argc;i++) {\
argv[i] = rb_eval(self,n->nd_head);\ argv[i] = rb_eval(self,n->nd_head);\
n=n->nd_next;\ n=n->nd_next;\
}\ }\
}\ }\
else {\ else {\
argc = 0;\ argc = 0;\
argv = 0;\ argv = 0;\
}\ }\
}\ }\
else {\ else {\
VALUE args = rb_eval(self,n);\ VALUE args = rb_eval(self,n);\
if (TYPE(args) != T_ARRAY)\ if (TYPE(args) != T_ARRAY)\
args = rb_ary_to_ary(args);\ args = rb_ary_to_ary(args);\
argc = RARRAY(args)->len;\ argc = RARRAY(args)->len;\
argv = ALLOCA_N(VALUE, argc);\ argv = ALLOCA_N(VALUE, argc);\
MEMCPY(argv, RARRAY(args)->ptr, VALUE, argc);\ MEMCPY(argv, RARRAY(args)->ptr, VALUE, argc);\
}\ }\
@ -2124,7 +2125,7 @@ copy_node_scope(node, rval)
int tmp_iter = ruby_iter->iter;\ int tmp_iter = ruby_iter->iter;\
if (tmp_iter == ITER_PRE) {\ if (tmp_iter == ITER_PRE) {\
ruby_block = ruby_block->outer;\ ruby_block = ruby_block->outer;\
tmp_iter = ITER_NOT;\ tmp_iter = ITER_NOT;\
}\ }\
PUSH_ITER(tmp_iter) PUSH_ITER(tmp_iter)
@ -2150,13 +2151,13 @@ arg_defined(self, node, buf, type)
if (!node) return type; /* no args */ if (!node) return type; /* no args */
if (nd_type(node) == NODE_ARRAY) { if (nd_type(node) == NODE_ARRAY) {
argc=node->nd_alen; argc=node->nd_alen;
if (argc > 0) { if (argc > 0) {
for (i=0;i<argc;i++) { for (i=0;i<argc;i++) {
if (!is_defined(self, node->nd_head, buf, 0)) if (!is_defined(self, node->nd_head, buf, 0))
return 0; return 0;
node = node->nd_next; node = node->nd_next;
} }
} }
} }
else if (!is_defined(self, node, buf, 0)) { else if (!is_defined(self, node, buf, 0)) {
return 0; return 0;
@ -2687,7 +2688,7 @@ rb_eval(self, n)
/* nodes for speed-up(literal match) */ /* nodes for speed-up(literal match) */
case NODE_MATCH3: case NODE_MATCH3:
{ {
VALUE r = rb_eval(self,node->nd_recv); VALUE r = rb_eval(self,node->nd_recv);
VALUE l = rb_eval(self,node->nd_value); VALUE l = rb_eval(self,node->nd_value);
if (TYPE(l) == T_STRING) { if (TYPE(l) == T_STRING) {
@ -3000,7 +3001,7 @@ rb_eval(self, n)
break; break;
case NODE_RESCUE: case NODE_RESCUE:
{ {
volatile VALUE e_info = ruby_errinfo; volatile VALUE e_info = ruby_errinfo;
volatile int rescuing = 0; volatile int rescuing = 0;
@ -3051,7 +3052,7 @@ rb_eval(self, n)
goto again; goto again;
} }
} }
break; break;
case NODE_ENSURE: case NODE_ENSURE:
PUSH_TAG(PROT_NONE); PUSH_TAG(PROT_NONE);
@ -3609,8 +3610,8 @@ rb_eval(self, n)
nd_set_type(node, NODE_LIT); nd_set_type(node, NODE_LIT);
node->nd_lit = result; node->nd_lit = result;
break; break;
case NODE_LIT: case NODE_LIT:
/* other thread may replace NODE_DREGX_ONCE to NODE_LIT */ /* other thread may replace NODE_DREGX_ONCE to NODE_LIT */
goto again; goto again;
case NODE_DXSTR: case NODE_DXSTR:
result = rb_funcall(self, '`', 1, str); result = rb_funcall(self, '`', 1, str);
@ -3747,8 +3748,8 @@ rb_eval(self, n)
rb_raise(rb_eTypeError, "no outer class/module"); rb_raise(rb_eTypeError, "no outer class/module");
} }
if (node->nd_super) { if (node->nd_super) {
super = rb_eval(self, node->nd_super); super = rb_eval(self, node->nd_super);
rb_check_inheritable(super); rb_check_inheritable(super);
} }
else { else {
super = 0; super = 0;
@ -4754,7 +4755,7 @@ rb_yield_0(val, self, klass, flags, avalue)
ruby_cref = (NODE*)old_cref; ruby_cref = (NODE*)old_cref;
ruby_wrapper = old_wrapper; ruby_wrapper = old_wrapper;
if (ruby_scope->flags & SCOPE_DONT_RECYCLE) if (ruby_scope->flags & SCOPE_DONT_RECYCLE)
scope_dup(old_scope); scope_dup(old_scope);
ruby_scope = old_scope; ruby_scope = old_scope;
scope_vmode = old_vmode; scope_vmode = old_vmode;
switch (state) { switch (state) {
@ -4835,7 +4836,7 @@ rb_yield_splat(values)
/* /*
* call-seq: * call-seq:
* loop {|| block } * loop {|| block }
* *
* Repeatedly executes the block. * Repeatedly executes the block.
* *
@ -7590,7 +7591,7 @@ Init_eval()
* call-seq: * call-seq:
* mod.autoload(name, filename) => nil * mod.autoload(name, filename) => nil
* *
* Registers _filename_ to be loaded (using <code>Kernel::require</code>) * Registers _filename_ to be loaded (using <code>Kernel::require</code>)
* the first time that _module_ (which may be a <code>String</code> or * the first time that _module_ (which may be a <code>String</code> or
* a symbol) is accessed in the namespace of _mod_. * a symbol) is accessed in the namespace of _mod_.
* *
@ -7628,7 +7629,7 @@ rb_mod_autoload_p(mod, sym)
* call-seq: * call-seq:
* autoload(module, filename) => nil * autoload(module, filename) => nil
* *
* Registers _filename_ to be loaded (using <code>Kernel::require</code>) * Registers _filename_ to be loaded (using <code>Kernel::require</code>)
* the first time that _module_ (which may be a <code>String</code> or * the first time that _module_ (which may be a <code>String</code> or
* a symbol) is accessed. * a symbol) is accessed.
* *
@ -7966,8 +7967,8 @@ proc_alloc(klass, proc)
/* /*
* call-seq: * call-seq:
* Proc.new {|...| block } => a_proc * Proc.new {|...| block } => a_proc
* Proc.new => a_proc * Proc.new => a_proc
* *
* Creates a new <code>Proc</code> object, bound to the current * Creates a new <code>Proc</code> object, bound to the current
* context. <code>Proc::new</code> may be called without a block only * context. <code>Proc::new</code> may be called without a block only
@ -8133,9 +8134,9 @@ proc_invoke(proc, args, self, klass)
* <i>params</i> using something close to method calling semantics. * <i>params</i> using something close to method calling semantics.
* Generates a warning if multiple values are passed to a proc that * Generates a warning if multiple values are passed to a proc that
* expects just one (previously this silently converted the parameters * expects just one (previously this silently converted the parameters
* to an array). * to an array).
* *
* For procs created using <code>Kernel.proc</code>, generates an * For procs created using <code>Kernel.proc</code>, generates an
* error if the wrong number of parameters * error if the wrong number of parameters
* are passed to a proc with multiple parameters. For procs created using * are passed to a proc with multiple parameters. For procs created using
* <code>Proc.new</code>, extra parameters are silently discarded. * <code>Proc.new</code>, extra parameters are silently discarded.
@ -8174,7 +8175,7 @@ static VALUE method_arity _((VALUE));
* is declared to take no arguments, returns 0. If the block is known * is declared to take no arguments, returns 0. If the block is known
* to take exactly n arguments, returns n. If the block has optional * to take exactly n arguments, returns n. If the block has optional
* arguments, return -n-1, where n is the number of mandatory * arguments, return -n-1, where n is the number of mandatory
* arguments. A <code>proc</code> with no argument declarations * arguments. A <code>proc</code> with no argument declarations
* returns -1, as it can accept (and ignore) an arbitrary number of * returns -1, as it can accept (and ignore) an arbitrary number of
* parameters. * parameters.
* *
@ -8934,7 +8935,7 @@ method_arity(method)
case NODE_IVAR: case NODE_IVAR:
return INT2FIX(0); return INT2FIX(0);
case NODE_BMETHOD: case NODE_BMETHOD:
return proc_arity(body->nd_cval); return proc_arity(body->nd_cval);
default: default:
body = body->nd_next; /* skip NODE_SCOPE */ body = body->nd_next; /* skip NODE_SCOPE */
if (nd_type(body) == NODE_BLOCK) if (nd_type(body) == NODE_BLOCK)
@ -9272,7 +9273,7 @@ Init_Proc()
/* /*
* Objects of class <code>Binding</code> encapsulate the execution * Objects of class <code>Binding</code> encapsulate the execution
* context at some particular place in the code and retain this context * context at some particular place in the code and retain this context
* for future use. The variables, methods, value of <code>self</code>, * for future use. The variables, methods, value of <code>self</code>,
* and possibly an iterator block that can be accessed in this context * and possibly an iterator block that can be accessed in this context
* are all retained. Binding objects can be created using * are all retained. Binding objects can be created using
@ -9305,8 +9306,8 @@ Init_Proc()
* *
*/ */
void void
Init_Binding() Init_Binding()
{ {
rb_cBinding = rb_define_class("Binding", rb_cObject); rb_cBinding = rb_define_class("Binding", rb_cObject);
rb_undef_alloc_func(rb_cBinding); rb_undef_alloc_func(rb_cBinding);
@ -9955,7 +9956,7 @@ rb_thread_restore_context(th, exit)
VALUE *base; VALUE *base;
#ifdef HAVE_UNWIND_H #ifdef HAVE_UNWIND_H
_Unwind_Context *unwctx = _UNW_createContextForSelf(); _Unwind_Context *unwctx = _UNW_createContextForSelf();
_UNW_currentContext(unwctx); _UNW_currentContext(unwctx);
base = (VALUE*)(long)_UNW_getAR(unwctx, _UNW_AR_BSP); base = (VALUE*)(long)_UNW_getAR(unwctx, _UNW_AR_BSP);
_UNW_destroyContext(unwctx); _UNW_destroyContext(unwctx);
@ -10270,9 +10271,9 @@ rb_thread_schedule()
th->wait_for = 0; th->wait_for = 0;
th->select_value = 0; th->select_value = 0;
found = 1; found = 1;
intersect_fds(&readfds, &th->readfds, max); intersect_fds(&readfds, &th->readfds, max);
intersect_fds(&writefds, &th->writefds, max); intersect_fds(&writefds, &th->writefds, max);
intersect_fds(&exceptfds, &th->exceptfds, max); intersect_fds(&exceptfds, &th->exceptfds, max);
} }
} }
END_FOREACH_FROM(curr, th); END_FOREACH_FROM(curr, th);
@ -12129,7 +12130,7 @@ static VALUE rb_cCont;
* cause the <code>callcc</code> to return (as will falling through the * cause the <code>callcc</code> to return (as will falling through the
* end of the block). The value returned by the <code>callcc</code> is * end of the block). The value returned by the <code>callcc</code> is
* the value of the block, or the value passed to * the value of the block, or the value passed to
* <em>cont</em><code>.call</code>. See class <code>Continuation</code> * <em>cont</em><code>.call</code>. See class <code>Continuation</code>
* for more details. Also see <code>Kernel::throw</code> for * for more details. Also see <code>Kernel::throw</code> for
* an alternative mechanism for unwinding a call stack. * an alternative mechanism for unwinding a call stack.
*/ */
@ -12168,7 +12169,7 @@ rb_callcc(self)
/* /*
* call-seq: * call-seq:
* cont.call(args, ...) * cont.call(args, ...)
* cont[args, ...] * cont[args, ...]
* *
* Invokes the continuation. The program continues from the end of the * Invokes the continuation. The program continues from the end of the
@ -12391,7 +12392,7 @@ thgroup_add(group, thread)
* execution, including the main thread of the Ruby script. * execution, including the main thread of the Ruby script.
* *
* In the descriptions of the methods in this class, the parameter _sym_ * In the descriptions of the methods in this class, the parameter _sym_
* refers to a symbol, which is either a quoted string or a * refers to a symbol, which is either a quoted string or a
* +Symbol+ (such as <code>:name</code>). * +Symbol+ (such as <code>:name</code>).
*/ */

View File

@ -627,7 +627,7 @@ rb_str_resize(str, len)
if (len < 0) { if (len < 0) {
rb_raise(rb_eArgError, "negative string size (or size too big)"); rb_raise(rb_eArgError, "negative string size (or size too big)");
} }
if (len != RSTRING(str)->len) { if (len != RSTRING(str)->len) {
rb_str_modify(str); rb_str_modify(str);
if (RSTRING(str)->len < len || RSTRING(str)->len - len > 1024) { if (RSTRING(str)->len < len || RSTRING(str)->len - len > 1024) {
@ -1281,7 +1281,7 @@ rb_str_match_m(argc, argv, str)
VALUE str; VALUE str;
{ {
VALUE re; VALUE re;
if (argc < 1) if (argc < 1)
rb_raise(rb_eArgError, "wrong number of arguments(%d for 1)", argc); rb_raise(rb_eArgError, "wrong number of arguments(%d for 1)", argc);
re = argv[0]; re = argv[0];
argv[0] = str; argv[0] = str;
@ -1418,6 +1418,7 @@ rb_str_upto(beg, end, excl)
rb_yield(current); rb_yield(current);
if (!excl && rb_str_equal(current, end)) break; if (!excl && rb_str_equal(current, end)) break;
current = rb_funcall(current, succ, 0, 0); current = rb_funcall(current, succ, 0, 0);
StringValue(current);
if (excl && rb_str_equal(current, end)) break; if (excl && rb_str_equal(current, end)) break;
if (RSTRING(current)->len > RSTRING(end)->len) if (RSTRING(current)->len > RSTRING(end)->len)
break; break;
@ -1464,7 +1465,7 @@ rb_str_subpat(str, re, nth)
} }
return Qnil; return Qnil;
} }
static VALUE static VALUE
rb_str_aref(str, indx) rb_str_aref(str, indx)
VALUE str; VALUE str;
@ -2027,7 +2028,7 @@ str_gsub(argc, argv, str, bang)
} }
pat = get_pat(argv[0], 1); pat = get_pat(argv[0], 1);
offset=0; n=0; offset=0; n=0;
beg = rb_reg_search(pat, str, 0, 0); beg = rb_reg_search(pat, str, 0, 0);
if (beg < 0) { if (beg < 0) {
if (bang) return Qnil; /* no match, no substitution */ if (bang) return Qnil; /* no match, no substitution */
@ -2064,7 +2065,7 @@ str_gsub(argc, argv, str, bang)
bp += len; bp += len;
memcpy(bp, RSTRING(val)->ptr, RSTRING(val)->len); memcpy(bp, RSTRING(val)->ptr, RSTRING(val)->len);
bp += RSTRING(val)->len; bp += RSTRING(val)->len;
offset = END(0); offset = END(0);
if (BEG(0) == END(0)) { if (BEG(0) == END(0)) {
/* /*
* Always consume at least one character of the input string * Always consume at least one character of the input string
@ -2214,7 +2215,7 @@ rb_str_replace(str, str2)
return str; return str;
} }
/* /*
* call-seq: * call-seq:
* string.clear -> string * string.clear -> string
* *
@ -2621,7 +2622,7 @@ rb_str_dump(str)
case '"': case '\\': case '"': case '\\':
case '\n': case '\r': case '\n': case '\r':
case '\t': case '\f': case '#': case '\t': case '\f': case '#':
case '\013': case '\007': case '\033': case '\013': case '\007': case '\033':
len += 2; len += 2;
break; break;
@ -4243,7 +4244,7 @@ rb_str_scan(str, pat)
rb_backref_set(match); rb_backref_set(match);
return ary; return ary;
} }
while (!NIL_P(result = scan_once(str, pat, &start))) { while (!NIL_P(result = scan_once(str, pat, &start))) {
match = rb_backref_get(); match = rb_backref_get();
rb_match_busy(match); rb_match_busy(match);
@ -4613,7 +4614,7 @@ Init_String()
rb_include_module(rb_cString, rb_mEnumerable); rb_include_module(rb_cString, rb_mEnumerable);
rb_define_alloc_func(rb_cString, str_alloc); rb_define_alloc_func(rb_cString, str_alloc);
rb_define_method(rb_cString, "initialize", rb_str_init, -1); rb_define_method(rb_cString, "initialize", rb_str_init, -1);
rb_define_method(rb_cString, "initialize_copy", rb_str_replace, 1); rb_define_method(rb_cString, "initialize_copy", rb_str_replace, 1);
rb_define_method(rb_cString, "<=>", rb_str_cmp_m, 1); rb_define_method(rb_cString, "<=>", rb_str_cmp_m, 1);
rb_define_method(rb_cString, "==", rb_str_equal, 1); rb_define_method(rb_cString, "==", rb_str_equal, 1);
rb_define_method(rb_cString, "eql?", rb_str_eql, 1); rb_define_method(rb_cString, "eql?", rb_str_eql, 1);