From abc49e493d6c1dc47586a7d1b616df5237bd606f Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 14 Jun 2000 05:30:29 +0000 Subject: 2000-06-14 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@757 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 29 ++++++++++++++++++++++++++++- intern.h | 1 + io.c | 3 ++- marshal.c | 6 +++--- re.c | 27 +++++++++++++++++---------- string.c | 37 +++++++++++++++++++------------------ struct.c | 6 ++++-- win32/ruby.def | 2 +- 8 files changed, 75 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2b8852bfba..9a7a2a3b32 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,33 @@ Wed Jun 14 14:07:38 2000 WATANABE Hirofumi * configure.in: add include when daylight checking. +Wed Jun 14 11:36:52 2000 WATANABE Hirofumi + + * marshal.c (r_object): modified for symbols. + + * marshal.c (w_object): ditto. + +Wed Jun 14 10:04:58 2000 Yukihiro Matsumoto + + * re.c (rb_memcmp): should compare according to ruby_ignorecase. + + * string.c (rb_str_cmp): use rb_memcmp. + + * string.c (rb_str_index): ditto. + + * string.c (rb_str_rindex): ditto. + + * string.c (rb_str_each_line): ditto. + +Wed 14 Jun 04:58:53 2000 Dave Thomas + + * io.c (rb_io_set_lineno): should have returned VALUE, not + integer. + +Wed Jun 14 09:29:42 2000 Yukihiro Matsumoto + + * string.c (rb_str_dup): dup should always propagate taintness. + Wed Jun 14 00:50:14 2000 Wakou Aoyama * lib/cgi.rb: read_multipart(): if no content body then raise EOFError. @@ -50,7 +77,7 @@ Thu Jun 8 14:25:45 2000 Hiroshi Igarashi * lib/mkmf.rb: add target `distclean' in Makefile for extlib. target `clean' doesn't remove Makefile. -Thu Jun 8 13:34:03 2000 Dave Thomas +Thu Jun 8 13:34:03 2000 Dave Thomas * numeric.c: add nan?, infinite?, and finite? to Float diff --git a/intern.h b/intern.h index 6c291c6bc8..d0938df5e1 100644 --- a/intern.h +++ b/intern.h @@ -257,6 +257,7 @@ VALUE rb_range_new _((VALUE, VALUE, int)); VALUE rb_range_beg_len _((VALUE, long*, long*, long, int)); VALUE rb_length_by_each _((VALUE)); /* re.c */ +int rb_memcmp _((char*,char*,size_t)); VALUE rb_reg_nth_defined _((int, VALUE)); VALUE rb_reg_nth_match _((int, VALUE)); VALUE rb_reg_last_match _((VALUE)); diff --git a/io.c b/io.c index f56ed79f73..0d604a9fe3 100644 --- a/io.c +++ b/io.c @@ -787,7 +787,8 @@ rb_io_set_lineno(io, lineno) GetOpenFile(io, fptr); rb_io_check_readable(fptr); - return fptr->lineno = NUM2INT(lineno); + fptr->lineno = NUM2INT(lineno); + return lineno; } static void diff --git a/marshal.c b/marshal.c index dd8376a8ff..4b385dc117 100644 --- a/marshal.c +++ b/marshal.c @@ -384,7 +384,7 @@ w_object(obj, arg, limit) rb_raise(rb_eTypeError, "uninitialized struct"); } for (i=0; iptr[i]), arg); + w_symbol(SYM2ID(RARRAY(mem)->ptr[i]), arg); w_object(RSTRUCT(obj)->ptr[i], arg, limit); } } @@ -826,11 +826,11 @@ r_object(arg) for (i=0; iptr[i] != INT2FIX(slot)) { + if (RARRAY(mem)->ptr[i] != ID2SYM(slot)) { rb_raise(rb_eTypeError, "struct %s not compatible (:%s for :%s)", rb_class2name(klass), rb_id2name(slot), - rb_id2name(FIX2INT(RARRAY(mem)->ptr[i]))); + rb_id2name(SYM2ID(RARRAY(mem)->ptr[i]))); } rb_struct_aset(v, INT2FIX(i), r_object(arg)); } diff --git a/re.c b/re.c index 5559ce0a0f..57bbb7207d 100644 --- a/re.c +++ b/re.c @@ -71,20 +71,27 @@ static const char casetable[] = { #define MIN(a,b) (((a)>(b))?(b):(a)) int -rb_str_cicmp(str1, str2) - VALUE str1, str2; -{ - int len, i; +rb_memcmp(p1, p2, len) char *p1, *p2; + size_t len; +{ + int tmp; - len = MIN(RSTRING(str1)->len, RSTRING(str2)->len); - p1 = RSTRING(str1)->ptr; p2 = RSTRING(str2)->ptr; + if (!ruby_ignorecase) { + return memcmp(p1, p2, len); + } - for (i = 0; i < len; i++, p1++, p2++) { - if (casetable[(unsigned)*p1] != casetable[(unsigned)*p2]) - return casetable[(unsigned)*p1] - casetable[(unsigned)*p2]; + while (len--) { + if (tmp = casetable[(unsigned)*p1++] - casetable[(unsigned)*p2++]) + return tmp; } - return RSTRING(str1)->len - RSTRING(str2)->len; + return 0; +} + +int +rb_str_cicmp(str1, str2) + VALUE str1, str2; +{ } #define REG_CASESTATE FL_USER0 diff --git a/string.c b/string.c index 73657fc0d4..27d51e46e3 100644 --- a/string.c +++ b/string.c @@ -87,6 +87,7 @@ rb_str_new3(str) str2->len = RSTRING(str)->len; str2->ptr = RSTRING(str)->ptr; str2->orig = str; + OBJ_INFECT(str2, str); return (VALUE)str2; } @@ -179,24 +180,28 @@ VALUE rb_str_dup(str) VALUE str; { - VALUE shadow; + VALUE str2; if (TYPE(str) != T_STRING) str = rb_str_to_str(str); if (OBJ_FROZEN(str)) return rb_str_new3(str); if (FL_TEST(str, STR_NO_ORIG)) { - VALUE s = rb_str_new(RSTRING(str)->ptr, RSTRING(str)->len); - OBJ_INFECT(s, str); - return s; + str2 = rb_str_new(RSTRING(str)->ptr, RSTRING(str)->len); + OBJ_INFECT(str2, str); + return str2; + } + if (RSTRING(str)->orig) { + str2 = rb_str_new3(RSTRING(str)->orig); + OBJ_INFECT(str2, str); + return str2; } - if (RSTRING(str)->orig) return rb_str_new3(RSTRING(str)->orig); - shadow = rb_str_new4(str); + str2 = rb_str_new4(str); { NEWOBJ(dup, struct RString); OBJSETUP(dup, rb_cString, T_STRING); - dup->len = RSTRING(shadow)->len; - dup->ptr = RSTRING(shadow)->ptr; - dup->orig = shadow; + dup->len = RSTRING(str2)->len; + dup->ptr = RSTRING(str2)->ptr; + dup->orig = str2; OBJ_INFECT(dup, str); return (VALUE)dup; @@ -515,12 +520,8 @@ rb_str_cmp(str1, str2) long len; int retval; - if (ruby_ignorecase) { - return rb_str_cicmp(str1, str2); - } - len = lesser(RSTRING(str1)->len, RSTRING(str2)->len); - retval = memcmp(RSTRING(str1)->ptr, RSTRING(str2)->ptr, len); + retval = rb_memcmp(RSTRING(str1)->ptr, RSTRING(str2)->ptr, len); if (retval == 0) { if (RSTRING(str1)->len == RSTRING(str2)->len) return 0; if (RSTRING(str1)->len > RSTRING(str2)->len) return 1; @@ -606,7 +607,7 @@ rb_str_index(str, sub, offset) if (len == 0) return offset; e = RSTRING(str)->ptr + RSTRING(str)->len - len + 1; while (s < e) { - if (*s == *(RSTRING(sub)->ptr) && memcmp(s, p, len) == 0) { + if (rb_memcmp(s, p, len) == 0) { return (s-(RSTRING(str)->ptr)); } s++; @@ -706,7 +707,7 @@ rb_str_rindex(argc, argv, str) t = RSTRING(sub)->ptr; if (len) { while (sbeg <= s) { - if (*s == *t && memcmp(s, t, len) == 0) { + if (rb_memcmp(s, t, len) == 0) { return INT2NUM(s - RSTRING(str)->ptr); } s--; @@ -2286,7 +2287,7 @@ rb_str_each_line(argc, argv, str) } if (p[-1] == newline && (rslen <= 1 || - memcmp(RSTRING(rs)->ptr, p-rslen, rslen) == 0)) { + rb_memcmp(RSTRING(rs)->ptr, p-rslen, rslen) == 0)) { line = rb_str_new(s, p - s); rb_yield(line); if (RSTRING(str)->ptr != ptr || RSTRING(str)->len != len) @@ -2398,7 +2399,7 @@ rb_str_chomp_bang(argc, argv, str) if (p[len-1] == newline && (rslen <= 1 || - memcmp(RSTRING(rs)->ptr, p+len-rslen, rslen) == 0)) { + rb_memcmp(RSTRING(rs)->ptr, p+len-rslen, rslen) == 0)) { rb_str_modify(str); RSTRING(str)->len -= rslen; RSTRING(str)->ptr[RSTRING(str)->len] = '\0'; diff --git a/struct.c b/struct.c index 961475d28f..4d9018a611 100644 --- a/struct.c +++ b/struct.c @@ -496,12 +496,14 @@ rb_struct_aset(s, idx, val) i = NUM2LONG(idx); if (i < 0) i = RSTRUCT(s)->len + i; - if (i < 0) + if (i < 0) { rb_raise(rb_eIndexError, "offset %d too small for struct(size:%d)", i, RSTRUCT(s)->len); - if (RSTRUCT(s)->len <= i) + } + if (RSTRUCT(s)->len <= i) { rb_raise(rb_eIndexError, "offset %d too large for struct(size:%d)", i, RSTRUCT(s)->len); + } if (OBJ_FROZEN(s)) rb_error_frozen("Struct"); return RSTRUCT(s)->ptr[i] = val; } diff --git a/win32/ruby.def b/win32/ruby.def index 4ec787af07..704e98b7b5 100644 --- a/win32/ruby.def +++ b/win32/ruby.def @@ -462,7 +462,7 @@ EXPORTS rb_range_new rb_range_beg_len ;re.c - rb_str_cicmp + rb_memcmp rb_reg_mbclen2 rb_match_busy rb_reg_adjust_startpos -- cgit v1.2.3