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

2000-02-29

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@629 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2000-02-29 08:05:32 +00:00
parent 0c123a83f0
commit 4890f3a684
20 changed files with 243 additions and 136 deletions

View file

@ -1,6 +1,44 @@
Tue Feb 29 01:08:26 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
* range.c (range_initialize): initialization done in `initialize';
`initialize; should not be called more than once.
* object.c (Init_Object): default `initialize' should take zero
argument.
* time.c (time_s_new): call `initialize' in Time::new.
Sat Feb 26 22:39:31 2000 EGUCHI Osamu <eguchi@shizuokanet.ne.jp>
* Fix String#* with huge string.
Sat Feb 26 00:14:59 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
* dir.c (dir_s_new): call `initialize' in Dir::new.
Fri Feb 25 23:01:49 2000 Katsuyuki Komatsu <komatsu@sarion.co.jp>
* ruby.h: export ruby_safe_level by EXTERN for mswin32.
* win32/ruby.def: regular maintenance.
Fri Feb 25 22:12:46 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
* io.c (rb_io_reopen): IO#reopen should accept path as well.
* string.c (rb_str_s_new): call `initialize' in String::new.
* hash.c (rb_hash_s_new): call `initialize' in Hash::new.
* array.c (rb_ary_s_new): call `initialize' in Array::new.
Fri Feb 25 12:50:20 2000 Yukihiro Matsumoto <matz@netlab.co.jp> Fri Feb 25 12:50:20 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
* eval.c (rb_thread_start_timer): interval made 10ms from 50ms. * eval.c (rb_thread_start_timer): interval changed to 10ms from 50ms.
Fri Feb 25 06:42:26 2000 GOTOU YUUZOU <gotoyuzo@notwork.org>
* ext/socket/socket.c (ip_addrsetup): hostp should remain NULL if
host is nil.
Thu Feb 24 16:53:47 2000 Yukihiro Matsumoto <matz@netlab.co.jp> Thu Feb 24 16:53:47 2000 Yukihiro Matsumoto <matz@netlab.co.jp>

3
ToDo
View file

@ -20,6 +20,7 @@ Language Spec.
* def Foo::Bar::baz() .. end ?? * def Foo::Bar::baz() .. end ??
* I18N (or M17N) script/string/regexp * I18N (or M17N) script/string/regexp
* Fixnum 0 as false ???? * Fixnum 0 as false ????
* discourage use of symbol variable (e.g. $/, etc.) in manual
Hacking Interpreter Hacking Interpreter
@ -56,6 +57,7 @@ Standard Libraries
- Thread::start gives arguments, not a thread object to the block - Thread::start gives arguments, not a thread object to the block
- regexp: (?>..), \G - regexp: (?>..), \G
- Struct::new([name,]member,...) - Struct::new([name,]member,...)
- IO#reopen accepts path as well
* String#scanf(?) * String#scanf(?)
* Object#fmt(?) * Object#fmt(?)
* Integer#{bin,oct,hex,heX} * Integer#{bin,oct,hex,heX}
@ -67,6 +69,7 @@ Standard Libraries
* optional stepsize argument for succ() * optional stepsize argument for succ()
* performance tune for String's non-bang methods. * performance tune for String's non-bang methods.
* Ruby module -- Ruby::Version, Ruby::Interpreter * Ruby module -- Ruby::Version, Ruby::Interpreter
* call initialize for builtin class too
Extension Libraries Extension Libraries

44
array.c
View file

@ -167,33 +167,42 @@ rb_ary_s_new(argc, argv, klass)
VALUE *argv; VALUE *argv;
VALUE klass; VALUE klass;
{ {
long len = 0; VALUE ary = rb_ary_new();
VALUE size, val;
NEWOBJ(ary, struct RArray);
OBJSETUP(ary, klass, T_ARRAY); OBJSETUP(ary, klass, T_ARRAY);
rb_obj_call_init(ary, argc, argv);
ary->len = 0; return ary;
ary->ptr = 0;
if (rb_scan_args(argc, argv, "02", &size, &val) == 0) {
ary->capa = ARY_DEFAULT_SIZE;
} }
else {
long capa = NUM2LONG(size);
if (capa < 0) { static VALUE
rb_ary_initialize(argc, argv, ary)
int argc;
VALUE *argv;
VALUE ary;
{
long len;
VALUE size, val;
if (rb_scan_args(argc, argv, "02", &size, &val) == 0) {
return ary;
}
rb_ary_modify(ary);
len = NUM2LONG(size);
if (len < 0) {
rb_raise(rb_eArgError, "negative array size"); rb_raise(rb_eArgError, "negative array size");
} }
if (capa > 0 && capa*sizeof(VALUE) <= 0) { if (len > 0 && len*sizeof(VALUE) <= 0) {
rb_raise(rb_eArgError, "array size too big"); rb_raise(rb_eArgError, "array size too big");
} }
ary->capa = capa; if (len > RARRAY(ary)->capa) {
len = capa; RARRAY(ary)->capa = len;
REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->capa);
} }
ary->ptr = ALLOC_N(VALUE, ary->capa); memfill(RARRAY(ary)->ptr, len, val);
memfill(ary->ptr, len, val); RARRAY(ary)->len = len;
ary->len = len;
return (VALUE)ary; return ary;
} }
static VALUE static VALUE
@ -1544,6 +1553,7 @@ Init_Array()
rb_define_singleton_method(rb_cArray, "new", rb_ary_s_new, -1); rb_define_singleton_method(rb_cArray, "new", rb_ary_s_new, -1);
rb_define_singleton_method(rb_cArray, "[]", rb_ary_s_create, -1); rb_define_singleton_method(rb_cArray, "[]", rb_ary_s_create, -1);
rb_define_method(rb_cArray, "initialize", rb_ary_initialize, -1);
rb_define_method(rb_cArray, "to_s", rb_ary_to_s, 0); rb_define_method(rb_cArray, "to_s", rb_ary_to_s, 0);
rb_define_method(rb_cArray, "inspect", rb_ary_inspect, 0); rb_define_method(rb_cArray, "inspect", rb_ary_inspect, 0);
rb_define_method(rb_cArray, "to_a", rb_ary_to_a, 0); rb_define_method(rb_cArray, "to_a", rb_ary_to_a, 0);

4
config.sub vendored
View file

@ -68,7 +68,7 @@ esac
# Here we must recognize all the valid KERNEL-OS combinations. # Here we must recognize all the valid KERNEL-OS combinations.
maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
case $maybe_os in case $maybe_os in
linux-gnu*) linux*)
os=-$maybe_os os=-$maybe_os
basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
;; ;;
@ -891,7 +891,7 @@ case $os in
os=-sysv4.2uw os=-sysv4.2uw
;; ;;
-gnu/linux*) -gnu/linux*)
os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` os=`echo $os | sed -e 's|gnu/linux|linux|'`
;; ;;
# First accept the basic system types. # First accept the basic system types.
# The portable systems comes first. # The portable systems comes first.

View file

@ -32,7 +32,7 @@ s%@AR@%ar%g
s%@INSTALL_PROGRAM@%${INSTALL}%g s%@INSTALL_PROGRAM@%${INSTALL}%g
s%@INSTALL_DATA@%${INSTALL} -m 644%g s%@INSTALL_DATA@%${INSTALL} -m 644%g
s%@SET_MAKE@%%g s%@SET_MAKE@%%g
s%@LIBOBJS@% crypt.o flock.o fnmatch.o snprintf.o%g s%@LIBOBJS@% crypt.o flock.o snprintf.o%g
s%@ALLOCA@%%g s%@ALLOCA@%%g
s%@DEFAULT_KCODE@%%g s%@DEFAULT_KCODE@%%g
s%@EXEEXT@%.exe%g s%@EXEEXT@%.exe%g

41
dir.c
View file

@ -233,14 +233,31 @@ free_dir(dir)
static VALUE dir_close _((VALUE)); static VALUE dir_close _((VALUE));
static VALUE static VALUE
dir_s_open(dir_class, dirname) dir_s_new(argc, argv, klass)
VALUE dir_class, dirname; int argc;
VALUE *argv;
VALUE klass;
{
VALUE obj = Data_Wrap_Struct(klass, 0, free_dir, 0);
rb_obj_call_init(obj, argc, argv);
if (rb_iterator_p()) {
rb_ensure(rb_yield, obj, dir_close, obj);
}
return obj;
}
static VALUE
dir_initialize(dir, dirname)
VALUE dir, dirname;
{ {
VALUE obj;
DIR *dirp; DIR *dirp;
Check_SafeStr(dirname); Check_SafeStr(dirname);
if (DATA_PTR(dir)) closedir(DATA_PTR(dir));
DATA_PTR(dir) = NULL;
dirp = opendir(RSTRING(dirname)->ptr); dirp = opendir(RSTRING(dirname)->ptr);
if (dirp == NULL) { if (dirp == NULL) {
if (errno == EMFILE || errno == ENFILE) { if (errno == EMFILE || errno == ENFILE) {
@ -251,14 +268,15 @@ dir_s_open(dir_class, dirname)
rb_sys_fail(RSTRING(dirname)->ptr); rb_sys_fail(RSTRING(dirname)->ptr);
} }
} }
DATA_PTR(dir) = dirp;
obj = Data_Wrap_Struct(dir_class, 0, free_dir, dirp); return dir;
if (rb_iterator_p()) {
return rb_ensure(rb_yield, obj, dir_close, obj);
} }
return obj; static VALUE
dir_s_open(klass, dirname)
VALUE klass, dirname;
{
return dir_s_new(1, &dirname, klass);
} }
static void static void
@ -781,11 +799,12 @@ Init_Dir()
rb_include_module(rb_cDir, rb_mEnumerable); rb_include_module(rb_cDir, rb_mEnumerable);
rb_define_singleton_method(rb_cDir, "new", dir_s_open, 1); rb_define_singleton_method(rb_cDir, "new", dir_s_new, -1);
rb_define_singleton_method(rb_cDir, "open", dir_s_open, 1); rb_define_singleton_method(rb_cDir, "open", dir_s_open, 1);
rb_define_singleton_method(rb_cDir, "foreach", dir_foreach, 1); rb_define_singleton_method(rb_cDir, "foreach", dir_foreach, 1);
rb_define_singleton_method(rb_cDir, "entries", dir_entries, 1); rb_define_singleton_method(rb_cDir, "entries", dir_entries, 1);
rb_define_method(rb_cDir,"initialize", dir_initialize, 1);
rb_define_method(rb_cDir,"read", dir_read, 0); rb_define_method(rb_cDir,"read", dir_read, 0);
rb_define_method(rb_cDir,"each", dir_each, 0); rb_define_method(rb_cDir,"each", dir_each, 0);
rb_define_method(rb_cDir,"rewind", dir_rewind, 0); rb_define_method(rb_cDir,"rewind", dir_rewind, 0);

View file

@ -519,6 +519,7 @@ ip_addrsetup(host, port)
long i = NUM2LONG(host); long i = NUM2LONG(host);
mkinetaddr(htonl(i), hbuf, sizeof(hbuf)); mkinetaddr(htonl(i), hbuf, sizeof(hbuf));
hostp = hbuf;
} }
else { else {
char *name = STR2CSTR(host); char *name = STR2CSTR(host);
@ -532,8 +533,8 @@ ip_addrsetup(host, port)
else { else {
strcpy(hbuf, name); strcpy(hbuf, name);
} }
}
hostp = hbuf; hostp = hbuf;
}
if (NIL_P(port)) { if (NIL_P(port)) {
portp = 0; portp = 0;
} }

51
hash.c
View file

@ -170,29 +170,6 @@ rb_hash_foreach(hash, func, farg)
return rb_ensure(rb_hash_foreach_call, (VALUE)&arg, rb_hash_foreach_ensure, hash); return rb_ensure(rb_hash_foreach_call, (VALUE)&arg, rb_hash_foreach_ensure, hash);
} }
static VALUE
rb_hash_s_new(argc, argv, klass)
int argc;
VALUE *argv;
VALUE klass;
{
VALUE ifnone;
NEWOBJ(hash, struct RHash);
OBJSETUP(hash, klass, T_HASH);
hash->iter_lev = 0;
hash->ifnone = Qnil;
hash->tbl = 0; /* avoid GC crashing */
rb_scan_args(argc, argv, "01", &ifnone);
hash->ifnone = ifnone;
hash->tbl = st_init_table(&objhash);
return (VALUE)hash;
}
static VALUE static VALUE
rb_hash_new2(klass) rb_hash_new2(klass)
VALUE klass; VALUE klass;
@ -214,6 +191,33 @@ rb_hash_new()
return rb_hash_new2(rb_cHash); return rb_hash_new2(rb_cHash);
} }
static VALUE
rb_hash_s_new(argc, argv, klass)
int argc;
VALUE *argv;
VALUE klass;
{
VALUE hash = rb_hash_new2(klass);
rb_obj_call_init(hash, argc, argv);
return hash;
}
static VALUE
rb_hash_initialize(argc, argv, hash)
int argc;
VALUE *argv;
VALUE hash;
{
VALUE ifnone;
rb_scan_args(argc, argv, "01", &ifnone);
rb_hash_modify(hash);
RHASH(hash)->ifnone = ifnone;
return hash;
}
static VALUE static VALUE
rb_hash_s_create(argc, argv, klass) rb_hash_s_create(argc, argv, klass)
int argc; int argc;
@ -1382,6 +1386,7 @@ Init_Hash()
rb_define_singleton_method(rb_cHash, "new", rb_hash_s_new, -1); rb_define_singleton_method(rb_cHash, "new", rb_hash_s_new, -1);
rb_define_singleton_method(rb_cHash, "[]", rb_hash_s_create, -1); rb_define_singleton_method(rb_cHash, "[]", rb_hash_s_create, -1);
rb_define_method(rb_cHash,"initialize", rb_hash_initialize, -1);
rb_define_method(rb_cHash,"clone", rb_hash_clone, 0); rb_define_method(rb_cHash,"clone", rb_hash_clone, 0);
rb_define_method(rb_cHash,"dup", rb_hash_dup, 0); rb_define_method(rb_cHash,"dup", rb_hash_dup, 0);

10
io.c
View file

@ -1707,7 +1707,7 @@ rb_io_mode_string(fptr)
} }
static VALUE static VALUE
rb_io_reopen(io, nfile) io_reopen(io, nfile)
VALUE io, nfile; VALUE io, nfile;
{ {
OpenFile *fptr, *orig; OpenFile *fptr, *orig;
@ -1775,7 +1775,7 @@ rb_io_reopen(io, nfile)
} }
static VALUE static VALUE
rb_file_reopen(argc, argv, file) rb_io_reopen(argc, argv, file)
int argc; int argc;
VALUE *argv; VALUE *argv;
VALUE file; VALUE file;
@ -1787,7 +1787,7 @@ rb_file_reopen(argc, argv, file)
rb_secure(4); rb_secure(4);
if (rb_scan_args(argc, argv, "11", &fname, &nmode) == 1) { if (rb_scan_args(argc, argv, "11", &fname, &nmode) == 1) {
if (TYPE(fname) == T_FILE) { /* fname must be IO */ if (TYPE(fname) == T_FILE) { /* fname must be IO */
return rb_io_reopen(file, fname); return io_reopen(file, fname);
} }
} }
@ -3248,7 +3248,7 @@ Init_IO()
rb_define_virtual_variable("$_", rb_lastline_get, rb_lastline_set); rb_define_virtual_variable("$_", rb_lastline_get, rb_lastline_set);
rb_define_method(rb_cIO, "clone", rb_io_clone, 0); rb_define_method(rb_cIO, "clone", rb_io_clone, 0);
rb_define_method(rb_cIO, "reopen", rb_io_reopen, 1); rb_define_method(rb_cIO, "reopen", rb_io_reopen, -1);
rb_define_method(rb_cIO, "print", rb_io_print, -1); rb_define_method(rb_cIO, "print", rb_io_print, -1);
rb_define_method(rb_cIO, "putc", rb_io_putc, 1); rb_define_method(rb_cIO, "putc", rb_io_putc, 1);
@ -3372,8 +3372,6 @@ Init_IO()
Init_File(); Init_File();
rb_define_method(rb_cFile, "reopen", rb_file_reopen, -1);
rb_define_singleton_method(rb_cFile, "new", rb_file_s_open, -1); rb_define_singleton_method(rb_cFile, "new", rb_file_s_open, -1);
rb_define_singleton_method(rb_cFile, "open", rb_file_s_open, -1); rb_define_singleton_method(rb_cFile, "open", rb_file_s_open, -1);

View file

@ -383,11 +383,12 @@ class DEBUGGER__
binding, binding_file, binding_line = @frames[frame_pos] binding, binding_file, binding_line = @frames[frame_pos]
stdout.printf "#%d %s:%s\n", frame_pos, binding_file, binding_line stdout.printf "#%d %s:%s\n", frame_pos, binding_file, binding_line
when /^\s*fi(?:nish)?$/ when /^\s*fin(?:ish)?$/
if frame_pos == 0 if frame_pos == @frames.size
stdout.print "\"finish\" not meaningful in the outermost frame.\n" stdout.print "\"finish\" not meaningful in the outermost frame.\n"
else else
@finish_pos = @frames.size - frame_pos @finish_pos = @frames.size - frame_pos
p @finish_pos
frame_pos = 0 frame_pos = 0
return return
end end
@ -563,10 +564,10 @@ class DEBUGGER__
@frames.unshift [binding, file, line, id] @frames.unshift [binding, file, line, id]
when 'return', 'end' when 'return', 'end'
@frames.shift
if @frames.size == @finish_pos if @frames.size == @finish_pos
@stop_next = 1 @stop_next = 1
end end
@frames.shift
when 'end' when 'end'
@frames.shift @frames.shift

View file

@ -16,8 +16,8 @@ module Singleton
klass.instance_eval %{ klass.instance_eval %{
@__instance__ = nil @__instance__ = nil
def instance def instance
unless @__instance__
Thread.critical = true Thread.critical = true
unless @__instance__
begin begin
@__instance__ = new @__instance__ = new
ensure ensure

View file

@ -15,9 +15,10 @@ require 'final'
class Tempfile < SimpleDelegator class Tempfile < SimpleDelegator
Max_try = 10 Max_try = 10
def Tempfile.callback(path) def Tempfile.callback(path, data)
lambda{ lambda{
print "removing ", path, "..." if $DEBUG print "removing ", path, "..." if $DEBUG
data[0].close if data[0]
if File.exist?(path) if File.exist?(path)
File.unlink(path) File.unlink(path)
end end
@ -47,10 +48,12 @@ class Tempfile < SimpleDelegator
n += 1 n += 1
end end
@clean_files = Tempfile.callback(tmpname) @protect = []
@clean_files = Tempfile.callback(tmpname, @protect)
ObjectSpace.define_finalizer(self, @clean_files) ObjectSpace.define_finalizer(self, @clean_files)
@tmpfile = File.open(tmpname, 'w+') @tmpfile = File.open(tmpname, 'w+')
@protect[0] = @tmpfile
@tmpname = tmpname @tmpname = tmpname
super(@tmpfile) super(@tmpfile)
Dir.rmdir(lock) Dir.rmdir(lock)
@ -66,12 +69,13 @@ class Tempfile < SimpleDelegator
def open def open
@tmpfile.close if @tmpfile @tmpfile.close if @tmpfile
@tmpfile = File.open(@tmpname, 'r+') @tmpfile = File.open(@tmpname, 'r+')
@protect[0] = @tmpfile
__setobj__(@tmpfile) __setobj__(@tmpfile)
end end
def close(real=false) def close(real=false)
@tmpfile.close if @tmpfile @tmpfile.close if @tmpfile
@tmpfile = nil @protect[0] = @tmpfile = nil
if real if real
@clean_files.call @clean_files.call
ObjectSpace.undefine_finalizer(self) ObjectSpace.undefine_finalizer(self)

View file

@ -266,8 +266,7 @@ rb_obj_is_kind_of(obj, c)
} }
static VALUE static VALUE
rb_obj_dummy(obj) rb_obj_dummy()
VALUE obj;
{ {
return Qnil; return Qnil;
} }
@ -587,6 +586,7 @@ rb_mod_cmp(mod, arg)
static VALUE static VALUE
rb_module_s_new(klass) rb_module_s_new(klass)
VALUE klass;
{ {
VALUE mod = rb_module_new(); VALUE mod = rb_module_new();
@ -979,7 +979,7 @@ Init_Object()
rb_mKernel = rb_define_module("Kernel"); rb_mKernel = rb_define_module("Kernel");
rb_include_module(rb_cObject, rb_mKernel); rb_include_module(rb_cObject, rb_mKernel);
rb_define_private_method(rb_cObject, "initialize", rb_obj_dummy, -1); rb_define_private_method(rb_cObject, "initialize", rb_obj_dummy, 0);
rb_define_private_method(rb_cClass, "inherited", rb_obj_dummy, 1); rb_define_private_method(rb_cClass, "inherited", rb_obj_dummy, 1);
/* /*

28
range.c
View file

@ -33,12 +33,11 @@ range_failed()
return Qnil; /* dummy */ return Qnil; /* dummy */
} }
static VALUE static void
range_new(klass, beg, end, exclude_end) range_init(obj, beg, end, exclude_end)
VALUE klass, beg, end; VALUE obj, beg, end;
int exclude_end; int exclude_end;
{ {
VALUE obj;
VALUE args[2]; VALUE args[2];
args[0] = beg; args[1] = end; args[0] = beg; args[1] = end;
@ -46,15 +45,12 @@ range_new(klass, beg, end, exclude_end)
rb_rescue(range_check, (VALUE)args, range_failed, 0); rb_rescue(range_check, (VALUE)args, range_failed, 0);
} }
obj = rb_obj_alloc(klass);
if (exclude_end) { if (exclude_end) {
SET_EXCL(obj); SET_EXCL(obj);
} }
rb_ivar_set(obj, id_beg, beg); rb_ivar_set(obj, id_beg, beg);
rb_ivar_set(obj, id_end, end); rb_ivar_set(obj, id_end, end);
return obj;
} }
VALUE VALUE
@ -62,19 +58,27 @@ rb_range_new(beg, end, exclude_end)
VALUE beg, end; VALUE beg, end;
int exclude_end; int exclude_end;
{ {
return range_new(rb_cRange, beg, end, exclude_end); VALUE obj = rb_obj_alloc(rb_cRange);
range_init(obj, beg, end, exclude_end);
return obj;
} }
static VALUE static VALUE
range_s_new(argc, argv, klass) range_initialize(argc, argv, obj)
int argc; int argc;
VALUE *argv; VALUE *argv;
VALUE klass; VALUE obj;
{ {
VALUE beg, end, flag; VALUE beg, end, flag;
rb_scan_args(argc, argv, "21", &beg, &end, &flag); rb_scan_args(argc, argv, "21", &beg, &end, &flag);
return range_new(klass, beg, end, RTEST(flag)); /* Ranges are immutable, so that they should be initialized only once. */
if (rb_ivar_defined(obj, id_beg)) {
rb_raise(rb_eNameError, "`initialize' called twice");
}
range_init(obj, beg, end, RTEST(flag));
return Qnil;
} }
static VALUE static VALUE
@ -328,7 +332,7 @@ Init_Range()
{ {
rb_cRange = rb_define_class("Range", rb_cObject); rb_cRange = rb_define_class("Range", rb_cObject);
rb_include_module(rb_cRange, rb_mEnumerable); rb_include_module(rb_cRange, rb_mEnumerable);
rb_define_singleton_method(rb_cRange, "new", range_s_new, -1); rb_define_method(rb_cRange, "initialize", range_initialize, -1);
rb_define_method(rb_cRange, "===", range_eqq, 1); rb_define_method(rb_cRange, "===", range_eqq, 1);
rb_define_method(rb_cRange, "each", range_each, 0); rb_define_method(rb_cRange, "each", range_each, 0);
rb_define_method(rb_cRange, "first", range_first, 0); rb_define_method(rb_cRange, "first", range_first, 0);

2
ruby.h
View file

@ -179,7 +179,7 @@ void rb_check_safe_str _((VALUE));
#define Check_SafeStr(v) rb_check_safe_str((VALUE)(v)) #define Check_SafeStr(v) rb_check_safe_str((VALUE)(v))
void rb_secure _((int)); void rb_secure _((int));
extern int ruby_safe_level; EXTERN int ruby_safe_level;
#define rb_safe_level() (ruby_safe_level) #define rb_safe_level() (ruby_safe_level)
void rb_set_safe_level _((int)); void rb_set_safe_level _((int));

View file

@ -191,27 +191,16 @@ rb_str_dup(str)
} }
static VALUE static VALUE
rb_str_s_new(klass, orig) rb_str_s_new(argc, argv, klass)
int argc;
VALUE *argv;
VALUE klass; VALUE klass;
VALUE orig;
{ {
NEWOBJ(str, struct RString); VALUE str = rb_str_new(0, 0);
OBJSETUP(str, klass, T_STRING); OBJSETUP(str, klass, T_STRING);
str->orig = 0; rb_obj_call_init(str, argc, argv);
orig = rb_obj_as_string(orig); return str;
str->len = RSTRING(orig)->len;
if (RSTRING(orig)->ptr) {
str->ptr = ALLOC_N(char, RSTRING(orig)->len+1);
memcpy(str->ptr, RSTRING(orig)->ptr, RSTRING(orig)->len);
str->ptr[RSTRING(orig)->len] = '\0';
}
if (rb_safe_level() >= 3) {
OBJ_TAINT(str);
}
return (VALUE)str;
} }
static VALUE static VALUE
@ -257,9 +246,13 @@ rb_str_times(str, times)
long i, len; long i, len;
len = NUM2LONG(times); len = NUM2LONG(times);
if (len == 0) return rb_str_new(0,0);
if (len < 0) { if (len < 0) {
rb_raise(rb_eArgError, "negative argument"); rb_raise(rb_eArgError, "negative argument");
} }
if (LONG_MAX/len < RSTRING(str)->len) {
rb_raise(rb_eArgError, "argument too big");
}
str2 = rb_str_new(0, RSTRING(str)->len*len); str2 = rb_str_new(0, RSTRING(str)->len*len);
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
@ -811,6 +804,7 @@ rb_str_aref(str, indx)
case T_FIXNUM: case T_FIXNUM:
idx = FIX2LONG(indx); idx = FIX2LONG(indx);
num_index:
if (idx < 0) { if (idx < 0) {
idx = RSTRING(str)->len + idx; idx = RSTRING(str)->len + idx;
} }
@ -841,7 +835,8 @@ rb_str_aref(str, indx)
return rb_str_substr(str, beg, len); return rb_str_substr(str, beg, len);
} }
} }
rb_raise(rb_eIndexError, "invalid index for string"); idx = NUM2LONG(indx);
goto num_index;
} }
return Qnil; /* not reached */ return Qnil; /* not reached */
} }
@ -863,8 +858,8 @@ rb_str_aref_m(argc, argv, str)
static void static void
rb_str_replace(str, beg, len, val) rb_str_replace(str, beg, len, val)
VALUE str, val; VALUE str, val;
int beg; long beg;
int len; long len;
{ {
if (len < RSTRING(val)->len) { if (len < RSTRING(val)->len) {
/* expand string */ /* expand string */
@ -891,12 +886,12 @@ rb_str_aset(str, indx, val)
VALUE str; VALUE str;
VALUE indx, val; VALUE indx, val;
{ {
int idx; long idx, beg;
int beg;
switch (TYPE(indx)) { switch (TYPE(indx)) {
case T_FIXNUM: case T_FIXNUM:
beg = idx = NUM2INT(indx); num_index:
idx = NUM2INT(indx);
if (idx < 0) { if (idx < 0) {
idx += RSTRING(str)->len; idx += RSTRING(str)->len;
} }
@ -943,7 +938,8 @@ rb_str_aset(str, indx, val)
return val; return val;
} }
} }
rb_raise(rb_eIndexError, "invalid index for string"); idx = NUM2LONG(indx);
goto num_index;
} }
} }
@ -955,7 +951,7 @@ rb_str_aset_m(argc, argv, str)
{ {
rb_str_modify(str); rb_str_modify(str);
if (argc == 3) { if (argc == 3) {
int beg, len; long beg, len;
if (TYPE(argv[2]) != T_STRING) argv[2] = rb_str_to_str(argv[2]); if (TYPE(argv[2]) != T_STRING) argv[2] = rb_str_to_str(argv[2]);
beg = NUM2INT(argv[0]); beg = NUM2INT(argv[0]);
@ -1049,7 +1045,7 @@ rb_str_sub_bang(argc, argv, str)
VALUE pat, repl, match; VALUE pat, repl, match;
struct re_registers *regs; struct re_registers *regs;
int iter = 0; int iter = 0;
int plen; long plen;
if (argc == 1 && rb_iterator_p()) { if (argc == 1 && rb_iterator_p()) {
iter = 1; iter = 1;
@ -1113,10 +1109,10 @@ rb_str_gsub_bang(argc, argv, str)
{ {
VALUE pat, val, repl, match; VALUE pat, val, repl, match;
struct re_registers *regs; struct re_registers *regs;
int beg, n; long beg, n;
long offset, blen, len;
int iter = 0; int iter = 0;
char *buf, *bp, *cp; char *buf, *bp, *cp;
int offset, blen, len;
int tainted = 0; int tainted = 0;
if (argc == 1 && rb_iterator_p()) { if (argc == 1 && rb_iterator_p()) {
@ -1462,7 +1458,7 @@ static VALUE
rb_str_dump(str) rb_str_dump(str)
VALUE str; VALUE str;
{ {
int len; long len;
char *p, *pend; char *p, *pend;
char *q, *qend; char *q, *qend;
VALUE result; VALUE result;
@ -2038,7 +2034,7 @@ rb_str_split_m(argc, argv, str)
VALUE spat; VALUE spat;
VALUE limit; VALUE limit;
int char_sep = -1; int char_sep = -1;
int beg, end, i; long beg, end, i;
int lim = 0; int lim = 0;
VALUE result, tmp; VALUE result, tmp;
@ -2078,7 +2074,7 @@ rb_str_split_m(argc, argv, str)
beg = 0; beg = 0;
if (char_sep >= 0) { if (char_sep >= 0) {
char *ptr = RSTRING(str)->ptr; char *ptr = RSTRING(str)->ptr;
int len = RSTRING(str)->len; long len = RSTRING(str)->len;
char *eptr = ptr + len; char *eptr = ptr + len;
if (char_sep == ' ') { /* AWK emulation */ if (char_sep == ' ') { /* AWK emulation */
@ -2120,9 +2116,9 @@ rb_str_split_m(argc, argv, str)
} }
} }
else { else {
int start = beg; long start = beg;
long idx;
int last_null = 0; int last_null = 0;
int idx;
struct re_registers *regs; struct re_registers *regs;
while ((end = rb_reg_search(spat, str, start, 0)) >= 0) { while ((end = rb_reg_search(spat, str, start, 0)) >= 0) {
@ -2198,7 +2194,7 @@ rb_str_each_line(argc, argv, str)
int rslen; int rslen;
char *p = RSTRING(str)->ptr, *pend = p + RSTRING(str)->len, *s; char *p = RSTRING(str)->ptr, *pend = p + RSTRING(str)->len, *s;
char *ptr = p; char *ptr = p;
int len = RSTRING(str)->len; long len = RSTRING(str)->len;
VALUE line; VALUE line;
if (rb_scan_args(argc, argv, "01", &rs) == 0) { if (rb_scan_args(argc, argv, "01", &rs) == 0) {
@ -2251,7 +2247,7 @@ static VALUE
rb_str_each_byte(str) rb_str_each_byte(str)
VALUE str; VALUE str;
{ {
int i; long i;
for (i=0; i<RSTRING(str)->len; i++) { for (i=0; i<RSTRING(str)->len; i++) {
rb_yield(INT2FIX(RSTRING(str)->ptr[i] & 0xff)); rb_yield(INT2FIX(RSTRING(str)->ptr[i] & 0xff));
@ -2314,7 +2310,7 @@ rb_str_chomp_bang(argc, argv, str)
int newline; int newline;
int rslen; int rslen;
char *p = RSTRING(str)->ptr; char *p = RSTRING(str)->ptr;
int len = RSTRING(str)->len; long len = RSTRING(str)->len;
if (rb_scan_args(argc, argv, "01", &rs) == 0) { if (rb_scan_args(argc, argv, "01", &rs) == 0) {
rs = rb_rs; rs = rb_rs;
@ -2654,7 +2650,8 @@ Init_String()
rb_cString = rb_define_class("String", rb_cObject); rb_cString = rb_define_class("String", rb_cObject);
rb_include_module(rb_cString, rb_mComparable); rb_include_module(rb_cString, rb_mComparable);
rb_include_module(rb_cString, rb_mEnumerable); rb_include_module(rb_cString, rb_mEnumerable);
rb_define_singleton_method(rb_cString, "new", rb_str_s_new, 1); rb_define_singleton_method(rb_cString, "new", rb_str_s_new, -1);
rb_define_method(rb_cString, "initialize", rb_str_replace_m, 1);
rb_define_method(rb_cString, "clone", rb_str_clone, 0); rb_define_method(rb_cString, "clone", rb_str_clone, 0);
rb_define_method(rb_cString, "dup", rb_str_dup, 0); rb_define_method(rb_cString, "dup", rb_str_dup, 0);
rb_define_method(rb_cString, "<=>", rb_str_cmp_m, 1); rb_define_method(rb_cString, "<=>", rb_str_cmp_m, 1);

20
time.c
View file

@ -73,6 +73,24 @@ time_s_now(klass)
return obj; return obj;
} }
static VALUE
time_s_new(argc, argv, klass)
int argc;
VALUE *argv;
VALUE klass;
{
VALUE obj = time_s_now(klass);
rb_obj_call_init(obj, argc, argv);
return obj;
}
static VALUE
time_initialize()
{
return Qnil;
}
static VALUE static VALUE
time_new_internal(klass, sec, usec) time_new_internal(klass, sec, usec)
VALUE klass; VALUE klass;
@ -983,7 +1001,7 @@ Init_Time()
rb_include_module(rb_cTime, rb_mComparable); rb_include_module(rb_cTime, rb_mComparable);
rb_define_singleton_method(rb_cTime, "now", time_s_now, 0); rb_define_singleton_method(rb_cTime, "now", time_s_now, 0);
rb_define_singleton_method(rb_cTime, "new", time_s_now, 0); rb_define_singleton_method(rb_cTime, "new", time_s_new, -1);
rb_define_singleton_method(rb_cTime, "at", time_s_at, -1); rb_define_singleton_method(rb_cTime, "at", time_s_at, -1);
rb_define_singleton_method(rb_cTime, "gm", time_s_timegm, -1); rb_define_singleton_method(rb_cTime, "gm", time_s_timegm, -1);
rb_define_singleton_method(rb_cTime, "local", time_s_timelocal, -1); rb_define_singleton_method(rb_cTime, "local", time_s_timelocal, -1);

View file

@ -33,7 +33,7 @@ s%@AR@%ar%g
s%@INSTALL_PROGRAM@%${INSTALL}%g s%@INSTALL_PROGRAM@%${INSTALL}%g
s%@INSTALL_DATA@%${INSTALL} -m 644%g s%@INSTALL_DATA@%${INSTALL} -m 644%g
s%@SET_MAKE@%%g s%@SET_MAKE@%%g
s%@LIBOBJS@% crypt.o flock.o fnmatch.o vsnprintf.o%g s%@LIBOBJS@% crypt.o flock.o vsnprintf.o%g
s%@ALLOCA@%%g s%@ALLOCA@%%g
s%@DEFAULT_KCODE@%%g s%@DEFAULT_KCODE@%%g
s%@EXEEXT@%.exe%g s%@EXEEXT@%.exe%g

View file

@ -1,4 +1,4 @@
#define RUBY_VERSION "1.5.2" #define RUBY_VERSION "1.5.2"
#define RUBY_RELEASE_DATE "2000-02-25" #define RUBY_RELEASE_DATE "2000-02-29"
#define RUBY_VERSION_CODE 152 #define RUBY_VERSION_CODE 152
#define RUBY_RELEASE_CODE 20000225 #define RUBY_RELEASE_CODE 20000229

View file

@ -34,6 +34,7 @@ EXPORTS
ruby_nerrs ruby_nerrs
;eval.c ;eval.c
rb_cProc rb_cProc
ruby_safe_level
ruby_frame ruby_frame
rb_cThread rb_cThread
rb_thread_tick rb_thread_tick
@ -133,6 +134,7 @@ EXPORTS
mygetservbyname mygetservbyname
mygetservbyport mygetservbyport
myget_osfhandle myget_osfhandle
win32_getcwd
win32_getenv win32_getenv
;array.c ;array.c
rb_mem_clear rb_mem_clear
@ -172,6 +174,7 @@ EXPORTS
rb_int2big rb_int2big
rb_uint2inum rb_uint2inum
rb_int2inum rb_int2inum
rb_cstr2inum
rb_str2inum rb_str2inum
rb_big2str rb_big2str
rb_big2ulong rb_big2ulong
@ -224,7 +227,6 @@ EXPORTS
dln_find_file dln_find_file
;enum.c ;enum.c
rb_each rb_each
rb_enum_length
;error.c ;error.c
rb_compile_error rb_compile_error
rb_compile_error_append rb_compile_error_append
@ -250,10 +252,9 @@ EXPORTS
rb_method_boundp rb_method_boundp
rb_attr rb_attr
rb_dvar_defined rb_dvar_defined
rb_dvar_curr
rb_dvar_ref rb_dvar_ref
rb_dvar_push rb_dvar_push
rb_dvar_asgn
rb_safe_level
rb_set_safe_level rb_set_safe_level
rb_check_safe_str rb_check_safe_str
rb_secure rb_secure
@ -323,8 +324,12 @@ EXPORTS
;file.c ;file.c
eaccess eaccess
rb_file_s_expand_path rb_file_s_expand_path
rb_file_const
rb_find_file
rb_path_check
;gc.c ;gc.c
xmalloc xmalloc
xfree
xcalloc xcalloc
xrealloc xrealloc
rb_global_variable rb_global_variable
@ -356,6 +361,7 @@ EXPORTS
rb_io_check_closed rb_io_check_closed
rb_io_check_readable rb_io_check_readable
rb_io_check_writable rb_io_check_writable
rb_read_pending
rb_read_check rb_read_check
rb_io_write rb_io_write
rb_io_eof rb_io_eof
@ -432,7 +438,9 @@ EXPORTS
rb_range_beg_len rb_range_beg_len
;re.c ;re.c
rb_str_cicmp rb_str_cicmp
rb_reg_mbclen2
rb_match_busy rb_match_busy
rb_reg_adjust_startpos
rb_reg_search rb_reg_search
rb_reg_nth_defined rb_reg_nth_defined
rb_reg_nth_match rb_reg_nth_match
@ -518,10 +526,10 @@ EXPORTS
rb_class_of rb_class_of
rb_type rb_type
rb_special_const_p rb_special_const_p
rb_test_false_or_nil
ruby_scan_oct ruby_scan_oct
ruby_scan_hex ruby_scan_hex
ruby_mktemp ruby_mktemp
ruby_add_suffix
ruby_qsort ruby_qsort
;variable.c ;variable.c
rb_mod_name rb_mod_name
@ -542,7 +550,8 @@ EXPORTS
rb_f_untrace_var rb_f_untrace_var
rb_gvar_get rb_gvar_get
rb_gvar_set rb_gvar_set
rb_gvar_set2 rb_gv_set
rb_gv_get
rb_gvar_defined rb_gvar_defined
rb_f_global_variables rb_f_global_variables
rb_alias_variable rb_alias_variable