summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-07-11 08:24:54 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-07-11 08:24:54 +0000
commitfefba453856ff9dfe5ecb0b1e04888c6f14b2383 (patch)
treee4ac3ce8b1d657c893ce2e79d40ca183e625c846
parent8e1d1358b689a13b4706754a2ab3fbcd7ef1d683 (diff)
* string.c (rb_str_slice_bang): if there's no corresponding
substring, slice! should return nil without exception. * string.c (rb_str_split_m): accept separator value nil as well. * class.c (include_class_new): module may be T_ICLASS; retrieve original module information. * re.c (rb_reg_expr_str): need to process backslashes properly. * parse.y (yylex): no here document after a dot. * parse.y (yylex): should have set lex_state properly after '`'. * parse.y (yylex): should have set lex_state properly after tOP_ASGN. * bignum.c (rb_big2dbl): return canonical HUGE_VAL for infinity. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@2633 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog31
-rw-r--r--bignum.c1
-rw-r--r--class.c19
-rw-r--r--parse.y64
-rw-r--r--range.c10
-rw-r--r--re.c23
-rw-r--r--string.c9
7 files changed, 124 insertions, 33 deletions
diff --git a/ChangeLog b/ChangeLog
index 0f1ec19dab..a27800f4f0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Thu Jul 11 09:00:43 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * string.c (rb_str_slice_bang): if there's no corresponding
+ substring, slice! should return nil without exception.
+
+Fri Jul 5 09:17:00 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * string.c (rb_str_split_m): accept separator value nil as well.
+
Fri Jul 5 05:00:40 2002 Wakou Aoyama <wakou@ruby-lang.org>
* lib/cgi.rb (CGI#initialize): improvement for mod_ruby.
@@ -8,6 +17,11 @@ Wed Jul 3 02:32:31 2002 Wakou Aoyama <wakou@ruby-lang.org>
* lib/cgi.rb (CGI#initialize): improvement for mod_ruby.
+Tue Jul 2 14:53:10 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * class.c (include_class_new): module may be T_ICLASS; retrieve
+ original module information.
+
Tue Jul 2 14:13:11 2002 Wakou Aoyama <wakou@ruby-lang.org>
* lib/cgi.rb (CGI#header): accept any type as value.
@@ -21,6 +35,10 @@ Fri Jun 28 00:51:19 2002 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (rb_w32_stat): fix buffer overflow. (ruby-bugs:PR#329)
+Thu Jun 27 03:42:04 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * re.c (rb_reg_expr_str): need to process backslashes properly.
+
Tue Jun 25 18:40:50 2002 KONISHI Hiromasa <konishih@fd6.so-net.ne.jp>
* dln.c: remove definition rb_loaderror().
@@ -55,6 +73,15 @@ Sat Jun 15 19:30:44 2002 Akinori MUSHA <knu@iDaemons.org>
it catches a dead symlink. Given a dead symlink named "a",
Dir.glob("?") did catch it but Dir.glob("a") somehow didn't.
+Sat Jun 15 01:59:05 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * parse.y (yylex): no here document after a dot.
+
+ * parse.y (yylex): should have set lex_state properly after '`'.
+
+ * parse.y (yylex): should have set lex_state properly after
+ tOP_ASGN.
+
Fri Jun 14 15:22:19 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* parse.y (read_escape): deny zero-width hexadecimal character.
@@ -64,6 +91,10 @@ Fri Jun 14 15:22:19 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* regex.c (re_compile_pattern): ditto.
+Fri Jun 14 00:49:54 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * bignum.c (rb_big2dbl): return canonical HUGE_VAL for infinity.
+
Thu Jun 13 00:33:49 2002 takuma ozawa <metal@mine.ne.jp>
* hash.c (rb_hash_s_create): use rb_hash_aset() instead of calling
diff --git a/bignum.c b/bignum.c
index 3c768fabf7..17e17b6647 100644
--- a/bignum.c
+++ b/bignum.c
@@ -537,6 +537,7 @@ rb_big2dbl(x)
while (i--) {
d = ds[i] + BIGRAD*d;
}
+ if (isinf(d)) d = HUGE_VAL;
if (!RBIGNUM(x)->sign) d = -d;
return d;
}
diff --git a/class.c b/class.c
index a7d2fed562..15f060d4e9 100644
--- a/class.c
+++ b/class.c
@@ -290,6 +290,9 @@ include_class_new(module, super)
NEWOBJ(klass, struct RClass);
OBJSETUP(klass, rb_cClass, T_ICLASS);
+ if (BUILTIN_TYPE(module) == T_ICLASS) {
+ module = RBASIC(module)->klass;
+ }
if (!RCLASS(module)->iv_tbl) {
RCLASS(module)->iv_tbl = st_init_numtable();
}
@@ -331,19 +334,27 @@ rb_include_module(klass, module)
c = klass;
while (module) {
+ int superclass_seen = Qfalse;
+
if (RCLASS(klass)->m_tbl == RCLASS(module)->m_tbl)
rb_raise(rb_eArgError, "cyclic include detected");
/* ignore if the module included already in superclasses */
for (p = RCLASS(klass)->super; p; p = RCLASS(p)->super) {
- if (BUILTIN_TYPE(p) == T_ICLASS) {
+ switch (BUILTIN_TYPE(p)) {
+ case T_ICLASS:
if (RCLASS(p)->m_tbl == RCLASS(module)->m_tbl) {
- c = p;
+ if (!superclass_seen) {
+ c = p; /* move insertion point */
+ }
goto skip;
}
+ break;
+ case T_CLASS:
+ superclass_seen = Qtrue;
+ break;
}
}
- RCLASS(c)->super = include_class_new(module, RCLASS(c)->super);
- c = RCLASS(c)->super;
+ c = RCLASS(c)->super = include_class_new(module, RCLASS(c)->super);
changed = 1;
skip:
module = RCLASS(module)->super;
diff --git a/parse.y b/parse.y
index 302bc5a981..8efd94f509 100644
--- a/parse.y
+++ b/parse.y
@@ -2973,8 +2973,8 @@ yylex()
case '*':
if ((c = nextc()) == '*') {
if ((c = nextc()) == '=') {
- lex_state = EXPR_BEG;
yylval.id = tPOW;
+ lex_state = EXPR_BEG;
return tOP_ASGN;
}
pushback(c);
@@ -3064,7 +3064,7 @@ yylex()
case '<':
c = nextc();
if (c == '<' &&
- lex_state != EXPR_END && lex_state != EXPR_CLASS &&
+ lex_state != EXPR_END && lex_state != EXPR_CLASS && lex_state != EXPR_DOT &&
(lex_state != EXPR_ARG || space_seen)) {
int c2 = nextc();
int indent = 0;
@@ -3095,8 +3095,8 @@ yylex()
}
if (c == '<') {
if (nextc() == '=') {
- lex_state = EXPR_BEG;
yylval.id = tLSHFT;
+ lex_state = EXPR_BEG;
return tOP_ASGN;
}
pushback(c);
@@ -3117,8 +3117,8 @@ yylex()
}
if (c == '>') {
if ((c = nextc()) == '=') {
- lex_state = EXPR_BEG;
yylval.id = tRSHFT;
+ lex_state = EXPR_BEG;
return tOP_ASGN;
}
pushback(c);
@@ -3130,8 +3130,14 @@ yylex()
case '"':
return parse_string(c,c,0);
case '`':
- if (lex_state == EXPR_FNAME) return c;
- if (lex_state == EXPR_DOT) return c;
+ if (lex_state == EXPR_FNAME) {
+ lex_state = EXPR_END;
+ return c;
+ }
+ if (lex_state == EXPR_DOT) {
+ lex_state = EXPR_ARG;
+ return c;
+ }
return parse_string(c,c,0);
case '\'':
@@ -3144,14 +3150,35 @@ yylex()
}
c = nextc();
if (c == -1) {
- rb_compile_error("incomplete character syntax");
- return 0;
- }
- if (lex_state == EXPR_ARG && ISSPACE(c)){
- pushback(c);
- lex_state = EXPR_BEG;
return '?';
}
+ if (ISSPACE(c)){
+ if (lex_state != EXPR_ARG){
+ int c = 0;
+ switch (c) {
+ case ' ':
+ c = 's';
+ break;
+ case '\n':
+ c = 'n';
+ break;
+ case '\t':
+ c = 't';
+ break;
+ case '\v':
+ c = 'v';
+ break;
+ }
+ if (c) {
+ rb_warn("invalid character syntax; use ?\\%c", c);
+ }
+ }
+ else {
+ pushback(c);
+ lex_state = EXPR_BEG;
+ return '?';
+ }
+ }
if (c == '\\') {
c = read_escape();
}
@@ -3165,6 +3192,7 @@ yylex()
lex_state = EXPR_BEG;
if ((c = nextc()) == '=') {
yylval.id = tANDOP;
+ lex_state = EXPR_BEG;
return tOP_ASGN;
}
pushback(c);
@@ -3199,14 +3227,15 @@ yylex()
lex_state = EXPR_BEG;
if ((c = nextc()) == '=') {
yylval.id = tOROP;
+ lex_state = EXPR_BEG;
return tOP_ASGN;
}
pushback(c);
return tOROP;
}
if (c == '=') {
- lex_state = EXPR_BEG;
yylval.id = '|';
+ lex_state = EXPR_BEG;
return tOP_ASGN;
}
if (lex_state == EXPR_FNAME || lex_state == EXPR_DOT) {
@@ -3229,8 +3258,8 @@ yylex()
return '+';
}
if (c == '=') {
- lex_state = EXPR_BEG;
yylval.id = '+';
+ lex_state = EXPR_BEG;
return tOP_ASGN;
}
if (lex_state == EXPR_BEG || lex_state == EXPR_MID ||
@@ -3259,8 +3288,8 @@ yylex()
return '-';
}
if (c == '=') {
- lex_state = EXPR_BEG;
yylval.id = '-';
+ lex_state = EXPR_BEG;
return tOP_ASGN;
}
if (lex_state == EXPR_BEG || lex_state == EXPR_MID ||
@@ -3513,8 +3542,8 @@ yylex()
return parse_regx('/', '/');
}
if ((c = nextc()) == '=') {
- lex_state = EXPR_BEG;
yylval.id = '/';
+ lex_state = EXPR_BEG;
return tOP_ASGN;
}
pushback(c);
@@ -3534,8 +3563,8 @@ yylex()
case '^':
if ((c = nextc()) == '=') {
- lex_state = EXPR_BEG;
yylval.id = '^';
+ lex_state = EXPR_BEG;
return tOP_ASGN;
}
switch (lex_state) {
@@ -3668,6 +3697,7 @@ yylex()
}
if ((c = nextc()) == '=') {
yylval.id = '%';
+ lex_state = EXPR_BEG;
return tOP_ASGN;
}
if (lex_state == EXPR_ARG && space_seen && !ISSPACE(c)) {
diff --git a/range.c b/range.c
index eca9af5089..8e3019df7b 100644
--- a/range.c
+++ b/range.c
@@ -16,7 +16,7 @@ VALUE rb_cRange;
static ID id_cmp, id_beg, id_end, id_excl;
#define EXCL(r) RTEST(rb_ivar_get((r), id_excl))
-#define SET_EXCL(r,v) rb_ivar_set((r), id_excl, (v)?Qtrue:Qfalse)
+#define SET_EXCL(r,v) rb_ivar_set((r), id_excl, (v) ? Qtrue : Qfalse)
static VALUE
range_check(args)
@@ -83,7 +83,7 @@ static VALUE
range_exclude_end_p(range)
VALUE range;
{
- return EXCL(range)?Qtrue:Qfalse;
+ return EXCL(range) ? Qtrue : Qfalse;
}
static VALUE
@@ -289,7 +289,7 @@ rb_range_beg_len(range, begp, lenp, len, err)
out_of_range:
if (err) {
rb_raise(rb_eRangeError, "%d..%s%d out of range",
- b, EXCL(range)?".":"", e);
+ b, EXCL(range) ? "." : "", e);
}
return Qnil;
}
@@ -303,7 +303,7 @@ range_to_s(range)
str = rb_obj_as_string(rb_ivar_get(range, id_beg));
str2 = rb_obj_as_string(rb_ivar_get(range, id_end));
str = rb_str_dup(str);
- rb_str_cat(str, "...", EXCL(range)?3:2);
+ rb_str_cat(str, "...", EXCL(range) ? 3 : 2);
rb_str_append(str, str2);
OBJ_INFECT(str, str2);
@@ -319,7 +319,7 @@ range_inspect(range)
str = rb_inspect(rb_ivar_get(range, id_beg));
str2 = rb_inspect(rb_ivar_get(range, id_end));
str = rb_str_dup(str);
- rb_str_cat(str, "...", EXCL(range)?3:2);
+ rb_str_cat(str, "...", EXCL(range) ? 3 : 2);
rb_str_append(str, str2);
OBJ_INFECT(str, str2);
diff --git a/re.c b/re.c
index 9d6cb08392..7c685f47d3 100644
--- a/re.c
+++ b/re.c
@@ -228,7 +228,14 @@ rb_reg_expr_str(str, s, len)
else {
p = s;
while (p<pend) {
- if (*p == '/' && (s == p || p[-1] != '\\')) {
+ if (*p == '\\') {
+ rb_str_cat(str, p, 1);
+ p++;
+ rb_str_cat(str, p, mbclen(*p));
+ p += mbclen(*p);
+ continue;
+ }
+ else if (*p == '/') {
char c = '\\';
rb_str_cat(str, &c, 1);
rb_str_cat(str, p, 1);
@@ -687,19 +694,27 @@ VALUE
rb_reg_match_pre(match)
VALUE match;
{
+ VALUE str;
+
if (NIL_P(match)) return Qnil;
if (RMATCH(match)->BEG(0) == -1) return Qnil;
- return rb_str_new(RSTRING(RMATCH(match)->str)->ptr, RMATCH(match)->BEG(0));
+ str = rb_str_new(RSTRING(RMATCH(match)->str)->ptr, RMATCH(match)->BEG(0));
+ if (OBJ_TAINTED(match)) OBJ_TAINT(str);
+ return str;
}
VALUE
rb_reg_match_post(match)
VALUE match;
{
+ VALUE str;
+
if (NIL_P(match)) return Qnil;
if (RMATCH(match)->BEG(0) == -1) return Qnil;
- return rb_str_new(RSTRING(RMATCH(match)->str)->ptr+RMATCH(match)->END(0),
- RSTRING(RMATCH(match)->str)->len-RMATCH(match)->END(0));
+ str = rb_str_new(RSTRING(RMATCH(match)->str)->ptr+RMATCH(match)->END(0),
+ RSTRING(RMATCH(match)->str)->len-RMATCH(match)->END(0));
+ if (OBJ_TAINTED(match)) OBJ_TAINT(str);
+ return str;
}
VALUE
diff --git a/string.c b/string.c
index 9c43990318..803cf9ae70 100644
--- a/string.c
+++ b/string.c
@@ -1113,7 +1113,9 @@ rb_str_slice_bang(argc, argv, str)
}
buf[i] = rb_str_new(0,0);
result = rb_str_aref_m(argc, buf, str);
- rb_str_aset_m(argc+1, buf, str);
+ if (!NIL_P(result)) {
+ rb_str_aset_m(argc+1, buf, str);
+ }
return result;
}
@@ -1374,7 +1376,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_class2name(CLASS_OF(line)));
}
return line;
}
@@ -2172,7 +2174,7 @@ rb_str_split_m(argc, argv, str)
i = 1;
}
- if (argc == 0) {
+ if (NIL_P(spat)) {
if (!NIL_P(rb_fs)) {
spat = rb_fs;
goto fs_set;
@@ -2669,6 +2671,7 @@ rb_str_crypt(str, salt)
result = rb_str_new2(crypt(RSTRING(str)->ptr, RSTRING(salt)->ptr));
OBJ_INFECT(result, str);
+ OBJ_INFECT(result, salt);
return result;
}