mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* eval.c (is_defined): call is_defined() before invoking
rb_eval(). [ruby-talk:107867] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6723 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b079f859b9
commit
d21727bdc5
2 changed files with 15 additions and 5 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Sat Jul 31 01:25:11 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* eval.c (is_defined): call is_defined() before invoking
|
||||||
|
rb_eval(). [ruby-talk:107867]
|
||||||
|
|
||||||
Fri Jul 30 16:10:54 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
Fri Jul 30 16:10:54 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
||||||
|
|
||||||
* ext/tcltklib/tcltklib.c (lib_fromUTF8_core): raise ArgumentError when
|
* ext/tcltklib/tcltklib.c (lib_fromUTF8_core): raise ArgumentError when
|
||||||
|
|
15
eval.c
15
eval.c
|
@ -2159,7 +2159,7 @@ copy_node_scope(node, rval)
|
||||||
|
|
||||||
#define MATCH_DATA *rb_svar(node->nd_cnt)
|
#define MATCH_DATA *rb_svar(node->nd_cnt)
|
||||||
|
|
||||||
static char* is_defined _((VALUE, NODE*, char*));
|
static const char* is_defined _((VALUE, NODE*, char*));
|
||||||
|
|
||||||
static char*
|
static char*
|
||||||
arg_defined(self, node, buf, type)
|
arg_defined(self, node, buf, type)
|
||||||
|
@ -2200,7 +2200,7 @@ search_iclass(self, klass)
|
||||||
return k;
|
return k;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char*
|
static const char*
|
||||||
is_defined(self, node, buf)
|
is_defined(self, node, buf)
|
||||||
VALUE self;
|
VALUE self;
|
||||||
NODE *node; /* OK */
|
NODE *node; /* OK */
|
||||||
|
@ -2208,9 +2208,10 @@ is_defined(self, node, buf)
|
||||||
{
|
{
|
||||||
VALUE val; /* OK */
|
VALUE val; /* OK */
|
||||||
int state;
|
int state;
|
||||||
|
static const char *ex = "expression";
|
||||||
|
|
||||||
again:
|
again:
|
||||||
if (!node) return "expression";
|
if (!node) return ex;
|
||||||
switch (nd_type(node)) {
|
switch (nd_type(node)) {
|
||||||
case NODE_SUPER:
|
case NODE_SUPER:
|
||||||
case NODE_ZSUPER:
|
case NODE_ZSUPER:
|
||||||
|
@ -2238,6 +2239,7 @@ is_defined(self, node, buf)
|
||||||
val = self;
|
val = self;
|
||||||
if (node->nd_recv == (NODE *)1) goto check_bound;
|
if (node->nd_recv == (NODE *)1) goto check_bound;
|
||||||
case NODE_CALL:
|
case NODE_CALL:
|
||||||
|
if (!is_defined(self, node->nd_recv, buf)) return 0;
|
||||||
val = rb_eval(self, node->nd_recv);
|
val = rb_eval(self, node->nd_recv);
|
||||||
check_bound:
|
check_bound:
|
||||||
{
|
{
|
||||||
|
@ -2329,6 +2331,7 @@ is_defined(self, node, buf)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NODE_COLON2:
|
case NODE_COLON2:
|
||||||
|
if (!is_defined(self, node->nd_recv, buf)) return 0;
|
||||||
val = rb_eval(self, node->nd_head);
|
val = rb_eval(self, node->nd_head);
|
||||||
switch (TYPE(val)) {
|
switch (TYPE(val)) {
|
||||||
case T_CLASS:
|
case T_CLASS:
|
||||||
|
@ -2351,6 +2354,7 @@ is_defined(self, node, buf)
|
||||||
|
|
||||||
case NODE_NTH_REF:
|
case NODE_NTH_REF:
|
||||||
if (RTEST(rb_reg_nth_defined(node->nd_nth, MATCH_DATA))) {
|
if (RTEST(rb_reg_nth_defined(node->nd_nth, MATCH_DATA))) {
|
||||||
|
if (!buf) return ex;
|
||||||
sprintf(buf, "$%d", (int)node->nd_nth);
|
sprintf(buf, "$%d", (int)node->nd_nth);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
@ -2358,6 +2362,7 @@ is_defined(self, node, buf)
|
||||||
|
|
||||||
case NODE_BACK_REF:
|
case NODE_BACK_REF:
|
||||||
if (RTEST(rb_reg_nth_defined(0, MATCH_DATA))) {
|
if (RTEST(rb_reg_nth_defined(0, MATCH_DATA))) {
|
||||||
|
if (!buf) return ex;
|
||||||
sprintf(buf, "$%c", (char)node->nd_nth);
|
sprintf(buf, "$%c", (char)node->nd_nth);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
@ -2370,7 +2375,7 @@ is_defined(self, node, buf)
|
||||||
}
|
}
|
||||||
POP_TAG();
|
POP_TAG();
|
||||||
if (!state) {
|
if (!state) {
|
||||||
return "expression";
|
return ex;
|
||||||
}
|
}
|
||||||
ruby_errinfo = Qnil;
|
ruby_errinfo = Qnil;
|
||||||
break;
|
break;
|
||||||
|
@ -3865,7 +3870,7 @@ rb_eval(self, n)
|
||||||
case NODE_DEFINED:
|
case NODE_DEFINED:
|
||||||
{
|
{
|
||||||
char buf[20];
|
char buf[20];
|
||||||
char *desc = is_defined(self, node->nd_head, buf);
|
const char *desc = is_defined(self, node->nd_head, buf);
|
||||||
|
|
||||||
if (desc) result = rb_str_new2(desc);
|
if (desc) result = rb_str_new2(desc);
|
||||||
else result = Qnil;
|
else result = Qnil;
|
||||||
|
|
Loading…
Add table
Reference in a new issue