1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* variable.c (rb_obj_classname): new function.

* string.c (rb_str_dup): should preserve original's class (but not
  hidden singleton class).

* string.c (rb_str_substr): ditto.

* parse.y: backout EXPR_CMDARG removal.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3427 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2003-01-31 04:00:17 +00:00
parent e474ae6338
commit 74d5623029
19 changed files with 92 additions and 64 deletions

View file

@ -1,3 +1,14 @@
Fri Jan 31 12:45:11 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* variable.c (rb_obj_classname): new function.
* string.c (rb_str_dup): should preserve original's class (but not
hidden singleton class).
* string.c (rb_str_substr): ditto.
* parse.y: backout EXPR_CMDARG removal.
Fri Jan 31 09:40:07 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* lib/optparse.rb (OptionParser::List::accept): default
@ -82,10 +93,6 @@ Sun Jan 26 03:37:18 2003 Akinori MUSHA <knu@iDaemons.org>
is used with extra arguments given. Tested with FreeBSD and
Linux by me and mswin32, bccwin32 and mingw by usa.
Sat Jan 25 21:04:57 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (yylex): remove EXPR_CMDARG according to the RHG book.
Fri Jan 24 18:15:33 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y: tMINUS should have lower precedence than tPOW.

View file

@ -1704,7 +1704,7 @@ rb_big_coerce(x, y)
}
else {
rb_raise(rb_eTypeError, "Can't coerce %s to Bignum",
rb_class2name(CLASS_OF(y)));
rb_obj_classname(y));
}
/* not reached */
return Qnil;

View file

@ -293,7 +293,7 @@ rb_define_module(name)
module = rb_const_get(rb_cObject, id);
if (TYPE(module) == T_MODULE)
return module;
rb_raise(rb_eTypeError, "%s is not a module", rb_class2name(CLASS_OF(module)));
rb_raise(rb_eTypeError, "%s is not a module", rb_obj_classname(module));
}
module = rb_define_module_id(id);
st_add_direct(rb_class_tbl, id, module);
@ -315,7 +315,7 @@ rb_define_module_under(outer, name)
if (TYPE(module) == T_MODULE)
return module;
rb_raise(rb_eTypeError, "%s::%s is not a module",
rb_class2name(outer), rb_class2name(CLASS_OF(module)));
rb_class2name(outer), rb_obj_classname(module));
}
module = rb_define_module_id(id);
rb_const_set(outer, id, module);

View file

@ -230,7 +230,7 @@ rb_check_type(x, t)
etype = RSTRING(rb_obj_as_string(x))->ptr;
}
else {
etype = rb_class2name(CLASS_OF(x));
etype = rb_obj_classname(x);
}
rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
etype, type->name);
@ -724,7 +724,7 @@ void
rb_check_frozen(obj)
VALUE obj;
{
if (OBJ_FROZEN(obj)) rb_error_frozen(rb_class2name(CLASS_OF(obj)));
if (OBJ_FROZEN(obj)) rb_error_frozen(rb_obj_classname(obj));
}
static void

28
eval.c
View file

@ -154,7 +154,7 @@ rb_check_safe_str(x)
rb_secure(4);
if (TYPE(x)!= T_STRING) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected String)",
rb_class2name(CLASS_OF(x)));
rb_obj_classname(x));
}
}
@ -1555,7 +1555,7 @@ superclass(self, node)
}
if (TYPE(val) != T_CLASS) {
rb_raise(rb_eTypeError, "superclass must be a Class (%s given)",
rb_class2name(CLASS_OF(val)));
rb_obj_classname(val));
}
if (FL_TEST(val, FL_SINGLETON)) {
rb_raise(rb_eTypeError, "can't make subclass of virtual class");
@ -3255,7 +3255,7 @@ rb_eval(self, n)
rb_raise(rb_eTypeError,
"can't define singleton method \"%s\" for %s",
rb_id2name(node->nd_mid),
rb_class2name(CLASS_OF(recv)));
rb_obj_classname(recv));
}
if (OBJ_FROZEN(recv)) rb_error_frozen("object");
@ -3389,7 +3389,7 @@ rb_eval(self, n)
result = rb_eval(self, node->nd_recv);
if (FIXNUM_P(result) || SYMBOL_P(result)) {
rb_raise(rb_eTypeError, "no virtual class for %s",
rb_class2name(CLASS_OF(result)));
rb_obj_classname(result));
}
if (ruby_safe_level >= 4 && !OBJ_TAINTED(result))
rb_raise(rb_eSecurityError, "Insecure: can't extend object");
@ -3678,7 +3678,7 @@ rb_longjmp(tag, mesg)
StringValue(e);
fprintf(stderr, "Exception `%s' at %s:%d - %s\n",
rb_class2name(CLASS_OF(ruby_errinfo)),
rb_obj_classname(ruby_errinfo),
ruby_sourcefile, ruby_sourceline,
RSTRING(e)->ptr);
fflush(stderr);
@ -4425,7 +4425,7 @@ rb_f_missing(argc, argv, obj)
snprintf(buf, BUFSIZ, format, rb_id2name(id),
desc, noclass ? "" : ":",
noclass ? "" : rb_class2name(CLASS_OF(obj)));
noclass ? "" : rb_obj_classname(obj));
exc = rb_exc_new2(exc, buf);
rb_iv_set(exc, "name", argv[0]);
rb_iv_set(exc, "args", rb_ary_new4(argc-1, argv+1));
@ -5076,7 +5076,7 @@ eval(self, src, scope, file, line)
if (!NIL_P(scope)) {
if (!rb_obj_is_block(scope)) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected Proc/Binding)",
rb_class2name(CLASS_OF(scope)));
rb_obj_classname(scope));
}
Data_Get_Struct(scope, struct BLOCK, data);
@ -6607,7 +6607,7 @@ proc_invoke(proc, args, pcall, self)
if (rb_block_given_p() && ruby_frame->last_func) {
rb_warning("block for %s#%s is useless",
rb_class2name(CLASS_OF(proc)),
rb_obj_classname(proc),
rb_id2name(ruby_frame->last_func));
}
@ -6727,7 +6727,7 @@ proc_to_s(self, other)
{
struct BLOCK *data;
NODE *node;
char *cname = rb_class2name(CLASS_OF(self));
char *cname = rb_obj_classname(self);
const int w = (SIZEOF_LONG * CHAR_BIT) / 4;
long len = strlen(cname)+6+w; /* 6:tags 16:addr */
VALUE str;
@ -6803,7 +6803,7 @@ block_pass(self, node)
b = rb_check_convert_type(block, T_DATA, "Proc", "to_proc");
if (!rb_obj_is_proc(b)) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected Proc)",
rb_class2name(CLASS_OF(block)));
rb_obj_classname(block));
}
block = b;
}
@ -7119,7 +7119,7 @@ method_inspect(method)
Data_Get_Struct(method, struct METHOD, data);
str = rb_str_buf_new2("#<");
s = rb_class2name(CLASS_OF(method));
s = rb_obj_classname(method);
rb_str_buf_cat2(str, s);
rb_str_buf_cat2(str, ": ");
@ -7228,7 +7228,7 @@ rb_mod_define_method(argc, argv, mod)
body = argv[1];
if (!rb_obj_is_kind_of(body, rb_cMethod) && !rb_obj_is_proc(body)) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected Proc/Method)",
rb_class2name(CLASS_OF(body)));
rb_obj_classname(body));
}
}
else {
@ -7698,7 +7698,7 @@ rb_thread_check(data)
{
if (TYPE(data) != T_DATA || RDATA(data)->dmark != (RUBY_DATA_FUNC)thread_mark) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected Thread)",
rb_class2name(CLASS_OF(data)));
rb_obj_classname(data));
}
return (rb_thread_t)RDATA(data)->data;
}
@ -9320,7 +9320,7 @@ static VALUE
rb_thread_inspect(thread)
VALUE thread;
{
char *cname = rb_class2name(CLASS_OF(thread));
char *cname = rb_obj_classname(thread);
rb_thread_t th = rb_thread_check(thread);
const char *status = thread_status_name(th->status);
VALUE str;

2
file.c
View file

@ -307,7 +307,7 @@ rb_stat_inspect(self)
};
str = rb_str_buf_new2("#<");
rb_str_buf_cat2(str, rb_class2name(CLASS_OF(self)));
rb_str_buf_cat2(str, rb_obj_classname(self));
rb_str_buf_cat2(str, " ");
for (i = 0; i < sizeof(member)/sizeof(member[0]); i++) {

4
gc.c
View file

@ -1380,7 +1380,7 @@ add_final(os, proc)
rb_warn("ObjectSpace::add_finalizer is deprecated; use define_finalizer");
if (!rb_obj_is_kind_of(proc, rb_cProc)) {
rb_raise(rb_eArgError, "wrong type argument %s (Proc required)",
rb_class2name(CLASS_OF(proc)));
rb_obj_classname(proc));
}
rb_ary_push(finalizers, proc);
return proc;
@ -1436,7 +1436,7 @@ define_final(argc, argv, os)
}
else if (!rb_obj_is_kind_of(proc, rb_cProc)) {
rb_raise(rb_eArgError, "wrong type argument %s (Proc required)",
rb_class2name(CLASS_OF(proc)));
rb_obj_classname(proc));
}
need_call_final = 1;
FL_SET(obj, FL_FINALIZE);

4
io.c
View file

@ -647,7 +647,7 @@ rb_io_inspect(obj)
fptr = RFILE(rb_io_taint_check(obj))->fptr;
if (!fptr || !(fptr->f || fptr->f2) || !fptr->path) return rb_any_to_s(obj);
cname = rb_class2name(CLASS_OF(obj));
cname = rb_obj_classname(obj);
buf = ALLOCA_N(char, strlen(cname) + strlen(fptr->path) + 5);
sprintf(buf, "#<%s:%s>", cname, fptr->path);
return rb_str_new2(buf);
@ -2677,7 +2677,7 @@ rb_io_defset(val, id)
{
if (!rb_respond_to(val, id_write)) {
rb_raise(rb_eTypeError, "$> must have write method, %s given",
rb_class2name(CLASS_OF(val)));
rb_obj_classname(val));
}
rb_defout = val;
}

View file

@ -313,7 +313,7 @@ w_uclass(obj, base_klass, arg)
w_extended(klass, arg);
if (klass != base_klass) {
w_byte(TYPE_UCLASS, arg);
w_unique(rb_class2name(CLASS_OF(obj)), arg);
w_unique(rb_obj_classname(obj), arg);
}
}
@ -518,7 +518,7 @@ w_object(obj, arg, limit)
VALUE mem;
long i;
w_unique(rb_class2name(CLASS_OF(obj)), arg);
w_unique(rb_obj_classname(obj), arg);
w_long(len, arg);
mem = rb_struct_iv_get(rb_obj_class(obj), "__member__");
if (mem == Qnil) {
@ -544,7 +544,7 @@ w_object(obj, arg, limit)
if (!rb_respond_to(obj, s_dump_data)) {
rb_raise(rb_eTypeError,
"class %s needs to have instance method `_dump_data'",
rb_class2name(CLASS_OF(obj)));
rb_obj_classname(obj));
}
v = rb_funcall(obj, s_dump_data, 0);
w_object(v, arg, limit);
@ -553,7 +553,7 @@ w_object(obj, arg, limit)
default:
rb_raise(rb_eTypeError, "can't dump %s",
rb_class2name(CLASS_OF(obj)));
rb_obj_classname(obj));
break;
}
}

View file

@ -96,8 +96,8 @@ coerce_rescue(x)
rb_raise(rb_eTypeError, "%s can't be coerced into %s",
rb_special_const_p(x[1])?
RSTRING(rb_inspect(x[1]))->ptr:
rb_class2name(CLASS_OF(x[1])),
rb_class2name(CLASS_OF(x[0])));
rb_obj_classname(x[1]),
rb_obj_classname(x[0]));
return Qnil; /* dummy */
}
@ -146,7 +146,7 @@ num_copy_object(x, y)
VALUE x, y;
{
/* Numerics are immutable values, which should not be copied */
rb_raise(rb_eTypeError, "can't copy %s", rb_class2name(CLASS_OF(x)));
rb_raise(rb_eTypeError, "can't copy %s", rb_obj_classname(x));
return Qnil; /* not reached */
}
@ -1127,7 +1127,7 @@ rb_int_induced_from(klass, x)
return rb_funcall(x, id_to_i, 0);
default:
rb_raise(rb_eTypeError, "failed to convert %s into Integer",
rb_class2name(CLASS_OF(x)));
rb_obj_classname(x));
}
}
@ -1143,7 +1143,7 @@ rb_flo_induced_from(klass, x)
return x;
default:
rb_raise(rb_eTypeError, "failed to convert %s into Float",
rb_class2name(CLASS_OF(x)));
rb_obj_classname(x));
}
}

View file

@ -110,7 +110,7 @@ copy_object(dest, obj)
VALUE dest, obj;
{
if (OBJ_FROZEN(dest)) {
rb_raise(rb_eTypeError, "[bug] frozen object (%s) allocated", rb_class2name(CLASS_OF(dest)));
rb_raise(rb_eTypeError, "[bug] frozen object (%s) allocated", rb_obj_classname(dest));
}
RBASIC(dest)->flags &= ~(T_MASK|FL_EXIVAR);
RBASIC(dest)->flags |= RBASIC(obj)->flags & (T_MASK|FL_EXIVAR|FL_TAINT);
@ -140,7 +140,7 @@ rb_obj_clone(obj)
VALUE clone;
if (rb_special_const_p(obj)) {
rb_raise(rb_eTypeError, "can't clone %s", rb_class2name(CLASS_OF(obj)));
rb_raise(rb_eTypeError, "can't clone %s", rb_obj_classname(obj));
}
clone = rb_obj_alloc(rb_obj_class(obj));
copy_object(clone, obj);
@ -157,7 +157,7 @@ rb_obj_dup(obj)
VALUE dup;
if (rb_special_const_p(obj)) {
rb_raise(rb_eTypeError, "can't dup %s", rb_class2name(CLASS_OF(obj)));
rb_raise(rb_eTypeError, "can't dup %s", rb_obj_classname(obj));
}
dup = rb_obj_alloc(rb_obj_class(obj));
copy_object(dup, obj);
@ -189,7 +189,7 @@ VALUE
rb_any_to_s(obj)
VALUE obj;
{
char *cname = rb_class2name(CLASS_OF(obj));
char *cname = rb_obj_classname(obj);
VALUE str;
str = rb_str_new(0, strlen(cname)+6+16+1); /* 6:tags 16:addr 1:nul */
@ -258,7 +258,7 @@ rb_obj_inspect(obj)
VALUE str;
char *c;
c = rb_class2name(CLASS_OF(obj));
c = rb_obj_classname(obj);
if (rb_inspecting_p(obj)) {
str = rb_str_new(0, strlen(c)+10+16+1); /* 10:tags 16:addr 1:nul */
sprintf(RSTRING(str)->ptr, "#<%s:0x%lx ...>", c, obj);
@ -429,7 +429,7 @@ nil_plus(x, y)
default:
rb_raise(rb_eTypeError, "tried to add %s(%s) to nil",
RSTRING(rb_inspect(y))->ptr,
rb_class2name(CLASS_OF(y)));
rb_obj_classname(y));
}
/* not reached */
}
@ -940,7 +940,7 @@ convert_type(val, tname, method, raise)
NIL_P(val) ? "nil" :
val == Qtrue ? "true" :
val == Qfalse ? "false" :
rb_class2name(CLASS_OF(val)),
rb_obj_classname(val),
tname);
}
else {
@ -962,7 +962,7 @@ rb_convert_type(val, type, tname, method)
v = convert_type(val, tname, method, Qtrue);
if (TYPE(v) != type) {
rb_raise(rb_eTypeError, "%s#%s should return %s",
rb_class2name(CLASS_OF(val)), method, tname);
rb_obj_classname(val), method, tname);
}
return v;
}
@ -981,7 +981,7 @@ rb_check_convert_type(val, type, tname, method)
if (NIL_P(v)) return Qnil;
if (TYPE(v) != type) {
rb_raise(rb_eTypeError, "%s#%s should return %s",
rb_class2name(CLASS_OF(val)), method, tname);
rb_obj_classname(val), method, tname);
}
return v;
}
@ -995,7 +995,7 @@ rb_to_integer(val, method)
VALUE v = convert_type(val, "Integer", method, Qtrue);
if (!rb_obj_is_kind_of(v, rb_cInteger)) {
rb_raise(rb_eTypeError, "%s#%s should return Integer",
rb_class2name(CLASS_OF(val)), method);
rb_obj_classname(val), method);
}
return v;
}

25
parse.y
View file

@ -68,6 +68,7 @@ static enum lex_state {
EXPR_BEG, /* ignore newline, +/- is a sign. */
EXPR_END, /* newline significant, +/- is a operator. */
EXPR_ARG, /* newline significant, +/- is a operator. */
EXPR_CMDARG, /* newline significant, +/- is a operator. */
EXPR_ENDARG, /* newline significant, +/- is a operator. */
EXPR_MID, /* newline significant, +/- is a operator. */
EXPR_FNAME, /* ignore newline, no reserved words. */
@ -3239,7 +3240,7 @@ arg_ambiguous()
rb_warning("ambiguous first argument; make sure");
}
#define IS_ARG() (lex_state == EXPR_ARG)
#define IS_ARG() (lex_state == EXPR_ARG || lex_state == EXPR_CMDARG)
static int
yylex()
@ -3463,7 +3464,10 @@ yylex()
return c;
}
if (lex_state == EXPR_DOT) {
lex_state = EXPR_ARG;
if (cmd_state)
lex_state = EXPR_CMDARG;
else
lex_state = EXPR_ARG;
return c;
}
lex_strterm = NEW_STRTERM(str_xquote, '`', 0);
@ -3994,7 +3998,10 @@ yylex()
c = tLPAREN;
}
else if (space_seen) {
if (lex_state == EXPR_ARG) {
if (lex_state == EXPR_CMDARG) {
c = tLPAREN_ARG;
}
else if (lex_state == EXPR_ARG) {
c = tLPAREN_ARG;
yylval.id = last_id;
}
@ -4343,7 +4350,7 @@ yylex()
}
if (kw->id[0] == kDO) {
if (COND_P()) return kDO_COND;
if (CMDARG_P())
if (CMDARG_P() && state != EXPR_CMDARG)
return kDO_BLOCK;
if (state == EXPR_ENDARG)
return kDO_BLOCK;
@ -4362,8 +4369,14 @@ yylex()
if (lex_state == EXPR_BEG ||
lex_state == EXPR_MID ||
lex_state == EXPR_DOT ||
lex_state == EXPR_ARG) {
lex_state = EXPR_ARG;
lex_state == EXPR_ARG ||
lex_state == EXPR_CMDARG) {
if (cmd_state) {
lex_state = EXPR_CMDARG;
}
else {
lex_state = EXPR_ARG;
}
}
else {
lex_state = EXPR_END;

2
prec.c
View file

@ -46,7 +46,7 @@ prec_induced_from(module, x)
VALUE module, x;
{
rb_raise(rb_eTypeError, "undefined conversion from %s into %s",
rb_class2name(CLASS_OF(x)), rb_class2name(module));
rb_obj_classname(x), rb_class2name(module));
return Qnil; /* not reached */
}

View file

@ -275,7 +275,7 @@ range_step(argc, argv, range)
if (!rb_respond_to(b, id_succ)) {
rb_raise(rb_eTypeError, "cannot iterate from %s",
rb_class2name(CLASS_OF(b)));
rb_obj_classname(b));
}
args[0] = 1;
@ -304,7 +304,7 @@ range_each(range)
if (!rb_respond_to(beg, id_succ)) {
rb_raise(rb_eTypeError, "cannot iterate from %s",
rb_class2name(CLASS_OF(beg)));
rb_obj_classname(beg));
}
if (FIXNUM_P(beg) && FIXNUM_P(end)) { /* fixnums are special */
long lim = FIX2LONG(end);
@ -471,7 +471,7 @@ range_member(range, val)
if (!rb_respond_to(beg, id_succ)) {
rb_raise(rb_eTypeError, "cannot iterate from %s",
rb_class2name(CLASS_OF(beg)));
rb_obj_classname(beg));
}
args[0] = val;
args[1] = Qfalse;

1
ruby.h
View file

@ -490,6 +490,7 @@ char *rb_id2name _((ID));
ID rb_to_id _((VALUE));
char *rb_class2name _((VALUE));
char *rb_obj_classname _((VALUE));
void rb_p _((VALUE));

View file

@ -240,7 +240,7 @@ rb_f_kill(argc, argv)
goto str_signal;
}
rb_raise(rb_eArgError, "bad signal type %s",
rb_class2name(CLASS_OF(argv[0])));
rb_obj_classname(argv[0]));
}
break;
}

View file

@ -282,7 +282,7 @@ VALUE
rb_str_dup(str)
VALUE str;
{
VALUE dup = str_alloc(rb_cString);
VALUE dup = str_alloc(rb_obj_class(str));
rb_str_replace(dup, str);
return dup;
}
@ -503,7 +503,7 @@ rb_str_substr(str, beg, len)
if (FL_TEST(str, ELTS_SHARED))
str = RSTRING(str)->aux.shared;
else
str = str_new4(CLASS_OF(str), str);
str = str_new4(rb_obj_class(str), str);
str2 = rb_str_new3(str);
RSTRING(str2)->ptr += RSTRING(str2)->len - len;
RSTRING(str2)->len = len;
@ -910,7 +910,7 @@ rb_str_index_m(argc, argv, str)
tmp = rb_check_string_type(sub);
if (NIL_P(tmp)) {
rb_raise(rb_eTypeError, "type mismatch: %s given",
rb_class2name(CLASS_OF(sub)));
rb_obj_classname(sub));
}
sub = tmp;
}
@ -1010,7 +1010,7 @@ rb_str_rindex_m(argc, argv, str)
default:
rb_raise(rb_eTypeError, "type mismatch: %s given",
rb_class2name(CLASS_OF(sub)));
rb_obj_classname(sub));
}
return Qnil;
}
@ -1710,7 +1710,7 @@ uscore_get()
line = rb_lastline_get();
if (TYPE(line) != T_STRING) {
rb_raise(rb_eTypeError, "$_ value need to be String (%s given)",
NIL_P(line) ? "nil" : rb_class2name(CLASS_OF(line)));
NIL_P(line) ? "nil" : rb_obj_classname(line));
}
return line;
}

2
time.c
View file

@ -158,7 +158,7 @@ time_timeval(time, interval)
default:
rb_raise(rb_eTypeError, "can't convert %s into %s",
rb_class2name(CLASS_OF(time)), tstr);
rb_obj_classname(time), tstr);
break;
}
return t;

View file

@ -311,6 +311,13 @@ rb_class2name(klass)
return RSTRING(rb_class_path(klass))->ptr;
}
char *
rb_obj_classname(obj)
VALUE obj;
{
return rb_obj_classname(obj);
}
struct trace_var {
int removed;
void (*func)();