* class.c (rb_include_module): detect cyclic module inclusion.

* eval.c (rb_thread_cleanup): need not to free thread stacks at
  process termination.

* array.c (rb_ary_fetch): use the block to get the default value
  if the block is given.

* eval.c (rb_thread_schedule): should check time only if BOTH
  WAIT_SELECT and WAIT_TIME.

* eval.c (umethod_bind): should update rklass field.

* hash.c (rb_hash_update): if a block is given, yields [key,
  value1, value2] to the block to resolve conflict.

* string.c (rb_str_split_m): no need to consider KANJI
characters, if the length of separator is 1 (byte).


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2015 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2002-01-25 08:22:11 +00:00
Родитель eb9708f386
Коммит f547c1150c
11 изменённых файлов: 87 добавлений и 22 удалений

Просмотреть файл

@ -1,3 +1,30 @@
Fri Jan 25 17:16:23 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* class.c (rb_include_module): detect cyclic module inclusion.
Fri Jan 25 02:17:56 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_thread_cleanup): need not to free thread stacks at
process termination.
* array.c (rb_ary_fetch): use the block to get the default value
if the block is given.
* eval.c (rb_thread_schedule): should check time only if BOTH
WAIT_SELECT and WAIT_TIME.
Thu Jan 24 11:49:05 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (umethod_bind): should update rklass field.
* hash.c (rb_hash_update): if a block is given, yields [key,
value1, value2] to the block to resolve conflict.
Thu Jan 24 05:42:01 2002 Koji Arai <jca02266@nifty.ne.jp>
* string.c (rb_str_split_m): no need to consider KANJI
characters, if the length of separator is 1 (byte).
Wed Jan 23 16:07:31 2002 Yukihiro Matsumoto <matz@ruby-lang.org> Wed Jan 23 16:07:31 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* array.c (Init_Array): remove Array#filter. * array.c (Init_Array): remove Array#filter.

12
array.c
Просмотреть файл

@ -550,8 +550,16 @@ rb_ary_fetch(argc, argv, ary)
idx += RARRAY(ary)->len; idx += RARRAY(ary)->len;
} }
if (idx < 0 || RARRAY(ary)->len <= idx) { if (idx < 0 || RARRAY(ary)->len <= idx) {
if (argc == 2) return ifnone; if (rb_block_given_p()) {
rb_raise(rb_eIndexError, "index %d out of array", idx); if (argc > 1) {
rb_raise(rb_eArgError, "wrong number of arguments");
}
return rb_yield(pos);
}
if (argc == 1) {
rb_raise(rb_eIndexError, "index %d out of array", idx);
}
return ifnone;
} }
return RARRAY(ary)->ptr[idx]; return RARRAY(ary)->ptr[idx];
} }

Просмотреть файл

@ -349,11 +349,13 @@ rb_include_module(klass, module)
OBJ_INFECT(klass, module); OBJ_INFECT(klass, module);
c = klass; c = klass;
while (module) { while (module) {
if (RCLASS(klass)->m_tbl == RCLASS(module)->m_tbl)
rb_raise(rb_eArgError, "cyclic include detected");
/* ignore if the module included already in superclasses */ /* ignore if the module included already in superclasses */
for (p = RCLASS(klass)->super; p; p = RCLASS(p)->super) { for (p = RCLASS(klass)->super; p; p = RCLASS(p)->super) {
if (BUILTIN_TYPE(p) == T_ICLASS && if (BUILTIN_TYPE(p) == T_ICLASS) {
RCLASS(p)->m_tbl == RCLASS(module)->m_tbl) { if (RCLASS(p)->m_tbl == RCLASS(module)->m_tbl)
goto skip; goto skip;
} }
} }
RCLASS(c)->super = include_class_new(module, RCLASS(c)->super); RCLASS(c)->super = include_class_new(module, RCLASS(c)->super);

4
dir.c
Просмотреть файл

@ -734,7 +734,7 @@ glob_helper(path, sub, flags, func, arg)
if (strcmp(".", dp->d_name) == 0 || strcmp("..", dp->d_name) == 0) if (strcmp(".", dp->d_name) == 0 || strcmp("..", dp->d_name) == 0)
continue; continue;
buf = ALLOC_N(char, strlen(base)+NAMLEN(dp)+strlen(m)+6); buf = ALLOC_N(char, strlen(base)+NAMLEN(dp)+strlen(m)+6);
sprintf(buf, "%s%s%s", base, (BASE)?"/":"", dp->d_name); sprintf(buf, "%s%s%s", base, (BASE) ? "/" : "", dp->d_name);
if (lstat(buf, &st) < 0) { if (lstat(buf, &st) < 0) {
if (errno != ENOENT) rb_sys_warning(buf); if (errno != ENOENT) rb_sys_warning(buf);
continue; continue;
@ -750,7 +750,7 @@ glob_helper(path, sub, flags, func, arg)
} }
if (fnmatch(magic, dp->d_name, flags) == 0) { if (fnmatch(magic, dp->d_name, flags) == 0) {
buf = ALLOC_N(char, strlen(base)+NAMLEN(dp)+2); buf = ALLOC_N(char, strlen(base)+NAMLEN(dp)+2);
sprintf(buf, "%s%s%s", base, (BASE)?"/":"", dp->d_name); sprintf(buf, "%s%s%s", base, (BASE) ? "/" : "", dp->d_name);
if (!m) { if (!m) {
(*func)(buf, arg); (*func)(buf, arg);
free(buf); free(buf);

Просмотреть файл

@ -1,3 +1,11 @@
: Array#fetch
takes block to get the default value.
: Hash#update
takes block to resolve key conflict.
: IO#fsync : IO#fsync
Added. Added.

15
eval.c
Просмотреть файл

@ -166,7 +166,7 @@ print_undef(klass, id)
{ {
rb_name_error(id, "undefined method `%s' for %s `%s'", rb_name_error(id, "undefined method `%s' for %s `%s'",
rb_id2name(id), rb_id2name(id),
(TYPE(klass) == T_MODULE)?"module":"class", (TYPE(klass) == T_MODULE) ? "module" : "class",
rb_class2name(klass)); rb_class2name(klass));
} }
@ -4262,8 +4262,8 @@ rb_f_missing(argc, argv, obj)
char buf[BUFSIZ]; char buf[BUFSIZ];
snprintf(buf, BUFSIZ, format, rb_id2name(id), snprintf(buf, BUFSIZ, format, rb_id2name(id),
desc, desc[0]=='#'?"":":", desc, desc[0]=='#' ? "" : ":",
desc[0]=='#'?"":rb_class2name(CLASS_OF(obj))); desc[0]=='#' ? "" : rb_class2name(CLASS_OF(obj)));
exc = rb_exc_new2(exc, buf); exc = rb_exc_new2(exc, buf);
rb_iv_set(exc, "name", argv[0]); rb_iv_set(exc, "name", argv[0]);
rb_iv_set(exc, "args", rb_ary_new4(argc-1, argv+1)); rb_iv_set(exc, "args", rb_ary_new4(argc-1, argv+1));
@ -6866,6 +6866,7 @@ umethod_bind(method, recv)
method = Data_Make_Struct(rb_cMethod,struct METHOD,bm_mark,free,bound); method = Data_Make_Struct(rb_cMethod,struct METHOD,bm_mark,free,bound);
*bound = *data; *bound = *data;
bound->recv = recv; bound->recv = recv;
bound->rklass = CLASS_OF(recv);
return method; return method;
} }
@ -7319,7 +7320,7 @@ static rb_thread_t
rb_thread_check(data) rb_thread_check(data)
VALUE data; VALUE data;
{ {
if (TYPE(data) != T_DATA || RDATA(data)->dfree != (RUBY_DATA_FUNC)thread_free) { if (TYPE(data) != T_DATA || RDATA(data)->dmark != (RUBY_DATA_FUNC)thread_mark) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected Thread)", rb_raise(rb_eTypeError, "wrong argument type %s (expected Thread)",
rb_class2name(CLASS_OF(data))); rb_class2name(CLASS_OF(data)));
} }
@ -7744,7 +7745,8 @@ rb_thread_schedule()
if (select_timeout && n == 0) { if (select_timeout && n == 0) {
if (now < 0.0) now = timeofday(); if (now < 0.0) now = timeofday();
FOREACH_THREAD_FROM(curr, th) { FOREACH_THREAD_FROM(curr, th) {
if ((th->wait_for & (WAIT_SELECT|WAIT_TIME)) && th->delay <= now) { if (((th->wait_for&(WAIT_SELECT|WAIT_TIME)) == (WAIT_SELECT|WAIT_TIME)) &&
th->delay <= now) {
th->status = THREAD_RUNNABLE; th->status = THREAD_RUNNABLE;
th->wait_for = 0; th->wait_for = 0;
th->select_value = 0; th->select_value = 0;
@ -7810,7 +7812,7 @@ rb_thread_schedule()
FOREACH_THREAD_FROM(curr, th) { FOREACH_THREAD_FROM(curr, th) {
fprintf(stderr, "deadlock 0x%lx: %d:%d %s - %s:%d\n", fprintf(stderr, "deadlock 0x%lx: %d:%d %s - %s:%d\n",
th->thread, th->status, th->thread, th->status,
th->wait_for, th==main_thread?"(main)":"", th->wait_for, th==main_thread ? "(main)" : "",
th->file, th->line); th->file, th->line);
} }
END_FOREACH_FROM(curr, th); END_FOREACH_FROM(curr, th);
@ -8664,6 +8666,7 @@ rb_thread_cleanup()
th->gid = 0; th->gid = 0;
th->priority = 0; th->priority = 0;
th->status = THREAD_TO_KILL; th->status = THREAD_TO_KILL;
RDATA(th->thread)->dfree = NULL;
} }
} }
END_FOREACH(th); END_FOREACH(th);

Просмотреть файл

@ -26,6 +26,7 @@ SRC_EXT = ["c", "cc", "m", "cxx", "cpp", "C"]
$extlist = [] $extlist = []
$includedir = "@includedir@".gsub(/\$\{prefix\}|\$\(prefix\)/,'@prefix@') $includedir = "@includedir@".gsub(/\$\{prefix\}|\$\(prefix\)/,'@prefix@')
$libdir = "@libdir@".gsub(/\$\{exec_prefix\}|\$\(exec_prefix\)/,'@exec_prefix@')
$top_srcdir = "@top_srcdir@" $top_srcdir = "@top_srcdir@"
if $top_srcdir !~ "^/" if $top_srcdir !~ "^/"
@ -73,7 +74,7 @@ if /mswin32/ =~ RUBY_PLATFORM
else else
OUTFLAG = '-o ' OUTFLAG = '-o '
end end
LINK = "@CC@ #{OUTFLAG}conftest -I#$topdir -I#$top_srcdir #{CFLAGS} -I#$includedir @LDFLAGS@ %s %s %s conftest.c %s %s @LIBS@" LINK = "@CC@ #{OUTFLAG}conftest -I#$topdir -I#$top_srcdir #{CFLAGS} -I#$includedir -L#$libdir @LDFLAGS@ %s %s %s conftest.c %s %s @LIBS@"
CPP = "@CPP@ @CPPFLAGS@ -I#$topdir -I#$top_srcdir #{CFLAGS} -I#$includedir %s %s %s conftest.c" CPP = "@CPP@ @CPPFLAGS@ -I#$topdir -I#$top_srcdir #{CFLAGS} -I#$includedir %s %s %s conftest.c"
$log = open('extmk.log', 'w') $log = open('extmk.log', 'w')
@ -450,7 +451,7 @@ target_prefix = #{target_prefix}
" "
mfile.printf "LOCAL_LIBS = %s %s\n", $LOCAL_LIBS, $local_flags mfile.printf "LOCAL_LIBS = %s %s\n", $LOCAL_LIBS, $local_flags
mfile.printf "LIBS = %s\n", $libs mfile.printf "LIBS = -L%s %s\n", $libdir, $libs
mfile.printf "OBJS = " mfile.printf "OBJS = "
if !$objs then if !$objs then
$objs = [] $objs = []

22
hash.c
Просмотреть файл

@ -889,12 +889,30 @@ rb_hash_update_i(key, value, hash)
return ST_CONTINUE; return ST_CONTINUE;
} }
static int
rb_hash_update_block_i(key, value, hash)
VALUE key, value;
VALUE hash;
{
if (key == Qundef) return ST_CONTINUE;
if (rb_hash_has_key(hash, key)) {
value = rb_yield(rb_ary_new3(3, key, rb_hash_aref(hash, key), value));
}
rb_hash_aset(hash, key, value);
return ST_CONTINUE;
}
static VALUE static VALUE
rb_hash_update(hash1, hash2) rb_hash_update(hash1, hash2)
VALUE hash1, hash2; VALUE hash1, hash2;
{ {
hash2 = to_hash(hash2); hash2 = to_hash(hash2);
st_foreach(RHASH(hash2)->tbl, rb_hash_update_i, hash1); if (rb_block_given_p()) {
st_foreach(RHASH(hash2)->tbl, rb_hash_update_block_i, hash1);
}
else {
st_foreach(RHASH(hash2)->tbl, rb_hash_update_i, hash1);
}
return hash1; return hash1;
} }
@ -985,7 +1003,7 @@ env_fetch(argc, argv)
if (!env) { if (!env) {
if (rb_block_given_p()) { if (rb_block_given_p()) {
if (argc > 1) { if (argc > 1) {
rb_raise(rb_eArgError, "wrong number of arguments", argc); rb_raise(rb_eArgError, "wrong number of arguments");
} }
return rb_yield(key); return rb_yield(key);
} }

Просмотреть файл

@ -256,8 +256,7 @@ The variable ruby-indent-level controls the amount of indentation.
(looking-at "[a-zA-Z][a-zA-z0-9_]* +%[^ \t]")) (looking-at "[a-zA-Z][a-zA-z0-9_]* +%[^ \t]"))
((eq option 'expr-re) ((eq option 'expr-re)
(looking-at "[a-zA-Z][a-zA-z0-9_]* +/[^ \t]")) (looking-at "[a-zA-Z][a-zA-z0-9_]* +/[^ \t]"))
(t (t nil))))))))
(looking-at "[a-zA-Z][a-zA-z0-9_]* +")))))))))
(defun ruby-forward-string (term &optional end no-error expand) (defun ruby-forward-string (term &optional end no-error expand)
(let ((n 1) (c (string-to-char term)) (let ((n 1) (c (string-to-char term))

Просмотреть файл

@ -438,7 +438,7 @@ rb_range_beg_len(range, begp, lenp, len, err)
out_of_range: out_of_range:
if (err) { if (err) {
rb_raise(rb_eRangeError, "%d..%s%d out of range", rb_raise(rb_eRangeError, "%d..%s%d out of range",
b, EXCL(range)?".":"", e); b, EXCL(range)? "." : "", e);
} }
return Qnil; return Qnil;
} }

Просмотреть файл

@ -1634,7 +1634,7 @@ uscore_get()
line = rb_lastline_get(); line = rb_lastline_get();
if (TYPE(line) != T_STRING) { if (TYPE(line) != T_STRING) {
rb_raise(rb_eTypeError, "$_ value need to be String (%s given)", 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; return line;
} }
@ -2509,7 +2509,6 @@ rb_str_split_m(argc, argv, str)
if (!NIL_P(limit) && lim <= ++i) break; if (!NIL_P(limit) && lim <= ++i) break;
} }
end++; end++;
if (ismbchar(*ptr)) {ptr++; end++;}
} }
} }
} }