summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-07-24 09:07:33 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-07-24 09:07:33 +0000
commit15ffbb1f820be7c798a7eb0aa2be11b5d4207460 (patch)
treef27d9d12e2cda0dca1435e1f0567d9fb423c7230
parent9e214f30c4f2bb6e6529c1bb988be1e46026919f (diff)
downloadruby-15ffbb1f820be7c798a7eb0aa2be11b5d4207460.tar.gz
* eval.c (rb_provide_feature): should not tweak extension used for
loading. * io.c (io_fread): use fread(3) if PENDING_COUND is available. * class.c (rb_mod_include_p): Module#include? added. [new] * re.c (ignorecase_setter): give warning on modifying $=. * string.c (rb_str_casecmp): new method. [new] * string.c (rb_str_eql): separated from rb_str_equal(), make it always be case sensitive. [new] * string.c (rb_str_hash): made it always be case sensitive. * eval.c (rb_f_require): should not include path in $" value * file.c (rb_find_file): should return 0 explicitly on failure. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1642 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog30
-rw-r--r--ToDo1
-rw-r--r--class.c16
-rw-r--r--eval.c35
-rw-r--r--file.c1
-rw-r--r--hash.c2
-rw-r--r--intern.h3
-rw-r--r--io.c28
-rw-r--r--numeric.c1
-rw-r--r--object.c3
-rw-r--r--re.c23
-rw-r--r--string.c63
12 files changed, 150 insertions, 56 deletions
diff --git a/ChangeLog b/ChangeLog
index 0dd6874aa9..bcc2060030 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,15 +1,45 @@
+Mon Jul 23 00:26:04 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * eval.c (rb_provide_feature): should not tweak extension used for
+ loading.
+
Sun Jul 22 21:16:43 2001 Akinori MUSHA <knu@iDaemons.org>
* ext/extmk.rb.in, lib/mkmf.rb: introduce a couple of new make
variables: CLEANFILES and DISTCLEANFILES. They'd typically be
defined in a file "depend".
+Sat Jul 21 09:40:10 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
+
+ * io.c (io_fread): use fread(3) if PENDING_COUND is available.
+
Fri Jul 20 22:55:01 2001 Akinori MUSHA <knu@iDaemons.org>
* gc.c (ruby_xrealloc): fix a dangling bug which led memory
reallocation to fail even though the second try after a GC
succeeds.
+Fri Jul 20 03:00:46 2001 Akinori MUSHA <knu@iDaemons.org>
+
+ * class.c (rb_mod_include_p): Module#include? added. [new]
+
+Fri Jul 20 01:05:50 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * re.c (ignorecase_setter): give warning on modifying $=.
+
+ * string.c (rb_str_casecmp): new method. [new]
+
+ * string.c (rb_str_eql): separated from rb_str_equal(), make it
+ always be case sensitive. [new]
+
+ * string.c (rb_str_hash): made it always be case sensitive.
+
+Thu Jul 19 13:03:15 2001 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
+
+ * eval.c (rb_f_require): should not include path in $" value
+
+ * file.c (rb_find_file): should return 0 explicitly on failure.
+
Tue Jul 17 11:44:40 2001 Usaku Nakamura <usa@osb.att.ne.jp>
* ruby.h: enable volatile directive with VC++.
diff --git a/ToDo b/ToDo
index e9d0d74adf..7eb823c370 100644
--- a/ToDo
+++ b/ToDo
@@ -26,6 +26,7 @@ Language Spec.
* to_i returns nil if str contains no digit.
* raise exception by `` error
* jar like combined library package.
+* resumable Exception via Exception#resume.
Hacking Interpreter
diff --git a/class.c b/class.c
index 1c3391a5d4..68a7b554d3 100644
--- a/class.c
+++ b/class.c
@@ -344,6 +344,22 @@ rb_mod_included_modules(mod)
}
VALUE
+rb_mod_include_p(mod, mod2)
+ VALUE mod;
+ VALUE mod2;
+{
+ VALUE p;
+
+ Check_Type(mod2, T_MODULE);
+ for (p = RCLASS(mod)->super; p; p = RCLASS(p)->super) {
+ if (BUILTIN_TYPE(p) == T_ICLASS) {
+ if (RBASIC(p)->klass == mod2) return Qtrue;
+ }
+ }
+ return Qfalse;
+}
+
+VALUE
rb_mod_ancestors(mod)
VALUE mod;
{
diff --git a/eval.c b/eval.c
index 95cf12d18a..1e0339b8c2 100644
--- a/eval.c
+++ b/eval.c
@@ -5392,19 +5392,6 @@ static void
rb_provide_feature(feature)
VALUE feature;
{
- char *ext;
- char *f = RSTRING(feature)->ptr;
-
- ext = strrchr(f, '.');
- if (ext && (strcmp(DLEXT, ext) == 0
-#ifdef DLEXT2
- || strcmp(DLEXT2, ext) == 0
-#endif
- )) {
- feature = rb_str_new(RSTRING(feature)->ptr, ext-RSTRING(feature)->ptr);
- rb_str_cat2(feature, ".so");
- }
- if (rb_feature_p(RSTRING(feature)->ptr, Qtrue)) return;
rb_ary_push(rb_features, feature);
}
@@ -5440,19 +5427,19 @@ rb_f_require(obj, fname)
}
else if (strcmp(".so", ext) == 0 || strcmp(".o", ext) == 0) {
fname = rb_str_new(RSTRING(fname)->ptr, ext-RSTRING(fname)->ptr);
- tmp = rb_str_dup(fname);
+ feature = tmp = rb_str_dup(fname);
rb_str_cat2(tmp, DLEXT);
tmp = rb_find_file(tmp);
if (tmp) {
- feature = fname = tmp;
+ fname = tmp;
goto load_dyna;
}
#ifdef DLEXT2
- tmp = rb_str_dup(fname);
+ feature = tmp = rb_str_dup(fname);
rb_str_cat2(tmp, DLEXT);
tmp = rb_find_file(tmp);
if (tmp) {
- feature = fname = tmp;
+ fname = tmp;
goto load_dyna;
}
#endif
@@ -5460,7 +5447,8 @@ rb_f_require(obj, fname)
else if (strcmp(DLEXT, ext) == 0) {
tmp = rb_find_file(fname);
if (tmp) {
- feature = fname = tmp;
+ feature = fname;
+ fname = tmp;
goto load_dyna;
}
}
@@ -5468,7 +5456,8 @@ rb_f_require(obj, fname)
else if (strcmp(DLEXT2, ext) == 0) {
tmp = rb_find_file(fname);
if (tmp) {
- feature = fname = tmp;
+ feature = fname;
+ fname = tmp;
goto load_dyna;
}
}
@@ -5480,17 +5469,15 @@ rb_f_require(obj, fname)
break;
case 1:
- feature = fname;
- fname = tmp;
+ feature = fname = tmp;
goto load_rb;
default:
- feature = fname;
+ feature = tmp;
fname = rb_find_file(tmp);
goto load_dyna;
}
- rb_raise(rb_eLoadError, "No such file to load -- %s",
- RSTRING(fname)->ptr);
+ rb_raise(rb_eLoadError, "No such file to load -- %s", RSTRING(fname)->ptr);
load_dyna:
rb_provide_feature(feature);
diff --git a/file.c b/file.c
index d79897fc92..e508cf0242 100644
--- a/file.c
+++ b/file.c
@@ -2348,6 +2348,7 @@ rb_find_file(path)
if (file_load_ok(f)) {
return rb_str_new2(f);
}
+ return 0;
}
static void
diff --git a/hash.c b/hash.c
index c8d2857563..75132c9d56 100644
--- a/hash.c
+++ b/hash.c
@@ -388,7 +388,7 @@ rb_hash_indexes(argc, argv, hash)
return indexes;
}
-static VALUE
+VALUE
rb_hash_delete(hash, key)
VALUE hash, key;
{
diff --git a/intern.h b/intern.h
index 46caaa091e..c1bc8d765e 100644
--- a/intern.h
+++ b/intern.h
@@ -90,6 +90,7 @@ VALUE rb_define_class_id _((ID, VALUE));
VALUE rb_module_new _((void));
VALUE rb_define_module_id _((ID));
VALUE rb_mod_included_modules _((VALUE));
+VALUE rb_mod_include_p _((VALUE, VALUE));
VALUE rb_mod_ancestors _((VALUE));
VALUE rb_class_instance_methods _((int, VALUE*, VALUE));
VALUE rb_class_protected_instance_methods _((int, VALUE*, VALUE));
@@ -201,6 +202,7 @@ VALUE rb_hash_freeze _((VALUE));
VALUE rb_hash_aref _((VALUE, VALUE));
VALUE rb_hash_aset _((VALUE, VALUE, VALUE));
VALUE rb_hash_delete_if _((VALUE));
+VALUE rb_hash_delete _((VALUE,VALUE));
int rb_path_check _((char *));
int rb_env_path_tainted _((void));
/* io.c */
@@ -281,6 +283,7 @@ VALUE rb_range_beg_len _((VALUE, long*, long*, long, int));
VALUE rb_length_by_each _((VALUE));
/* re.c */
int rb_memcmp _((char*,char*,long));
+int rb_memcicmp _((char*,char*,long));
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 2c51dec6e1..448fd60032 100644
--- a/io.c
+++ b/io.c
@@ -108,11 +108,14 @@ static VALUE lineno;
#ifdef _STDIO_USES_IOSTREAM /* GNU libc */
# ifdef _IO_fpos_t
# define READ_DATA_PENDING(fp) ((fp)->_IO_read_ptr != (fp)->_IO_read_end)
+# define READ_DATA_PENDING_COUNT(fp) ((fp)->_IO_read_end - (fp)->_IO_read_ptr)
# else
# define READ_DATA_PENDING(fp) ((fp)->_gptr < (fp)->_egptr)
+# define READ_DATA_PENDING_COUNT(fp) ((fp)->_egptr - (fp)->_gptr)
# endif
#elif defined(FILE_COUNT)
# define READ_DATA_PENDING(fp) ((fp)->FILE_COUNT > 0)
+# define READ_DATA_PENDING_COUNT(fp) ((fp)->FILE_COUNT)
#elif defined(__BEOS__)
# define READ_DATA_PENDING(fp) (fp->_state._eof == 0)
#else
@@ -476,14 +479,34 @@ io_fread(ptr, len, f)
long n = len;
int c;
- while (n--) {
+ while (n > 0) {
+#ifdef READ_DATA_PENDING_COUNT
+ int i = READ_DATA_PENDING_COUNT(f);
+ if (i <= 0) {
+ rb_thread_wait_fd(fileno(f));
+ i = READ_DATA_PENDING_COUNT(f);
+ }
+ if (i > 0) {
+ if (i > n) i = n;
+ TRAP_BEG;
+ c = fread(ptr, 1, i, f);
+ TRAP_END;
+ if (c < 0) goto eof;
+ ptr += c;
+ n -= c;
+ if (c < i) goto eof;
+ continue;
+ }
+#else
if (!READ_DATA_PENDING(f)) {
rb_thread_wait_fd(fileno(f));
}
+#endif
TRAP_BEG;
c = getc(f);
TRAP_END;
if (c == EOF) {
+ eof:
if (ferror(f)) {
if (errno == EINTR) continue;
rb_sys_fail(0);
@@ -492,9 +515,10 @@ io_fread(ptr, len, f)
break;
}
*ptr++ = c;
+ n--;
}
- return len - n - 1;
+ return len - n;
}
#ifndef S_ISREG
diff --git a/numeric.c b/numeric.c
index 67b5eb317a..55ab2a8118 100644
--- a/numeric.c
+++ b/numeric.c
@@ -70,6 +70,7 @@ do_coerce(x, y)
VALUE a[2];
a[0] = *x; a[1] = *y;
+
ary = rb_rescue(coerce_body, (VALUE)a, coerce_rescue, (VALUE)a);
if (TYPE(ary) != T_ARRAY || RARRAY(ary)->len != 2) {
rb_raise(rb_eTypeError, "coerce must return [x, y]");
diff --git a/object.c b/object.c
index 66d369e1e9..f60234411a 100644
--- a/object.c
+++ b/object.c
@@ -956,7 +956,7 @@ rb_Float(val)
d = strtod(p, &end);
if (p == end) {
bad:
- rb_raise(rb_eArgError, "invalid value for Float: \"%s\"", q);
+ rb_raise(rb_eArgError, "invalid value for Float(): \"%s\"", q);
}
if (*end) {
if (*end == '_') {
@@ -1232,6 +1232,7 @@ Init_Object()
rb_define_method(rb_cModule, "dup", rb_mod_dup, 0);
rb_define_method(rb_cModule, "to_s", rb_mod_to_s, 0);
rb_define_method(rb_cModule, "included_modules", rb_mod_included_modules, 0);
+ rb_define_method(rb_cModule, "include?", rb_mod_include_p, 1);
rb_define_method(rb_cModule, "name", rb_mod_name, 0);
rb_define_method(rb_cModule, "ancestors", rb_mod_ancestors, 0);
diff --git a/re.c b/re.c
index bd8f34a173..877ad4c018 100644
--- a/re.c
+++ b/re.c
@@ -72,16 +72,12 @@ static const char casetable[] = {
#define MIN(a,b) (((a)>(b))?(b):(a))
int
-rb_memcmp(p1, p2, len)
+rb_memcicmp(p1, p2, len)
char *p1, *p2;
long len;
{
int tmp;
- if (!ruby_ignorecase) {
- return memcmp(p1, p2, len);
- }
-
while (len--) {
if (tmp = casetable[(unsigned)*p1++] - casetable[(unsigned)*p2++])
return tmp;
@@ -89,6 +85,19 @@ rb_memcmp(p1, p2, len)
return 0;
}
+int
+rb_memcmp(p1, p2, len)
+ char *p1, *p2;
+ long len;
+{
+ int tmp;
+
+ if (!ruby_ignorecase) {
+ return memcmp(p1, p2, len);
+ }
+ return rb_memcicmp(p1, p2, len);
+}
+
#define REG_CASESTATE FL_USER0
#define KCODE_NONE 0
#define KCODE_EUC FL_USER1
@@ -1304,9 +1313,11 @@ ignorecase_getter()
}
static void
-ignorecase_setter(val)
+ignorecase_setter(val, id)
VALUE val;
+ ID id;
{
+ rb_warn("modifying %s is deperecated", rb_id2name(id));
may_need_recompile = 1;
ruby_ignorecase = RTEST(val);
}
diff --git a/string.c b/string.c
index 7d7eb5c769..227f4f78bf 100644
--- a/string.c
+++ b/string.c
@@ -639,30 +639,14 @@ rb_str_hash(str)
key &= ~g;
}
#elif HASH_PERL
- if (ruby_ignorecase) {
- while (len--) {
- key = key*33 + toupper(*p);
- p++;
- }
- }
- else {
- while (len--) {
- key = key*33 + *p++;
- }
+ while (len--) {
+ key = key*33 + *p++;
}
key = key + (key>>5);
#else
- if (ruby_ignorecase) {
- while (len--) {
- key = key*65599 + toupper(*p);
- p++;
- }
- }
- else {
- while (len--) {
- key = key*65599 + *p;
- p++;
- }
+ while (len--) {
+ key = key*65599 + *p;
+ p++;
}
key = key + (key>>5);
#endif
@@ -713,6 +697,20 @@ rb_str_equal(str1, str2)
}
static VALUE
+rb_str_eql(str1, str2)
+ VALUE str1, str2;
+{
+ if (TYPE(str2) != T_STRING || RSTRING(str1)->len != RSTRING(str2)->len)
+ return Qfalse;
+
+ if (memcmp(RSTRING(str1)->ptr, RSTRING(str2)->ptr,
+ lesser(RSTRING(str1)->len, RSTRING(str2)->len)) == 0)
+ return Qtrue;
+
+ return Qfalse;
+}
+
+static VALUE
rb_str_cmp_m(str1, str2)
VALUE str1, str2;
{
@@ -724,6 +722,26 @@ rb_str_cmp_m(str1, str2)
}
static VALUE
+rb_str_casecmp(str1, str2)
+ VALUE str1, str2;
+{
+ long len;
+ int retval;
+
+ StringValue(str2);
+ len = lesser(RSTRING(str1)->len, RSTRING(str2)->len);
+ retval = rb_memcicmp(RSTRING(str1)->ptr, RSTRING(str2)->ptr, len);
+ if (retval == 0) {
+ if (RSTRING(str1)->len == RSTRING(str2)->len) return INT2FIX(0);
+ if (RSTRING(str1)->len > RSTRING(str2)->len) return INT2FIX(1);
+ return INT2FIX(-1);
+ }
+ if (retval == 0) return INT2FIX(0);
+ if (retval > 0) return INT2FIX(1);
+ return INT2FIX(-1);
+}
+
+static VALUE
rb_str_match(x, y)
VALUE x, y;
{
@@ -2934,8 +2952,9 @@ Init_String()
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_equal, 1);
+ rb_define_method(rb_cString, "eql?", rb_str_eql, 1);
rb_define_method(rb_cString, "hash", rb_str_hash_m, 0);
+ rb_define_method(rb_cString, "casecmp", rb_str_casecmp, 1);
rb_define_method(rb_cString, "+", rb_str_plus, 1);
rb_define_method(rb_cString, "*", rb_str_times, 1);
rb_define_method(rb_cString, "%", rb_str_format, 1);