* dir.c (free_dir): fix memory leak. reported by yamamoto

madoka.

* eval.c (bind_eval): new method. [RCR 251]

* string.c (rb_str_clear): new method. [ruby-dev:24104]

* io.c (rb_io_reopen): should clear allocated OpenFile.  pointed
  out by Guy Decoux. [ruby-core:03288]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6794 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2004-08-19 07:33:15 +00:00
Родитель 4c57b2b499
Коммит d73fa69935
5 изменённых файлов: 87 добавлений и 9 удалений

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

@ -1,3 +1,8 @@
Thu Aug 19 15:15:24 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* dir.c (free_dir): fix memory leak. reported by yamamoto
madoka.
Thu Aug 19 09:19:27 2004 NAKAMURA Usaku <usa@ruby-lang.org>
* configure.in, win32/Makefile.sub (LIBS): need to link shell32
@ -35,6 +40,17 @@ Wed Aug 18 11:22:52 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* win32/win32.c (init_env): initialize HOME and USER environment
variables unless set.
Wed Aug 18 10:17:21 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (bind_eval): new method. [RCR 251]
* string.c (rb_str_clear): new method. [ruby-dev:24104]
Tue Aug 17 17:20:59 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (rb_io_reopen): should clear allocated OpenFile. pointed
out by Guy Decoux. [ruby-core:03288]
Tue Aug 17 01:36:32 2004 Dave Thomas <dave@pragprog.com>
* lib/rdoc/usage.rb: Remove extra indent. Tidy 'ri' option
@ -110,10 +126,19 @@ Sun Aug 8 00:43:31 2004 why the lucky stiff <why@ruby-lang.org>
collections. plain scalars are trimmed if indentation follows in
an ambiguous flow collection.
Sat Aug 7 03:08:21 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* process.c (proc_daemon): new method. should be modified for
platforms without /dev/null.
Sat Aug 7 00:50:01 2004 Tanaka Akira <akr@m17n.org>
* ext/zlib/zlib.c: Zlib::GzipReader#read(0) returns "" instead of nil.
Wed Aug 4 13:26:00 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* marshal.c (r_bytes0): optimize out read(0). [ruby-talk:108276]
Tue Aug 3 13:49:12 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/namespace.rb: bug fix

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

@ -349,7 +349,11 @@ static void
free_dir(dir)
struct dir_data *dir;
{
if (dir && dir->dir) closedir(dir->dir);
if (dir) {
if (dir->dir) closedir(dir->dir);
if (dir->path) free(dir->path);
}
free(dir);
}
static VALUE dir_close _((VALUE));

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

@ -6380,8 +6380,14 @@ rb_obj_instance_eval(argc, argv, self)
VALUE *argv;
VALUE self;
{
VALUE klass = rb_singleton_class(self);
VALUE klass;
if (FIXNUM_P(self) || SYMBOL_P(self)) {
klass = Qnil;
}
else {
klass = rb_singleton_class(self);
}
return specific_eval(argc, argv, klass, self);
}
@ -7881,6 +7887,23 @@ rb_f_binding(self)
return bind;
}
static VALUE
bind_eval(argc, argv, bind)
int argc;
VALUE *argv;
VALUE bind;
{
struct BLOCK *data;
VALUE args[4];
VALUE dummy;
rb_scan_args(argc, argv, "12", &args[0], &args[2], &args[3]);
args[1] = bind;
Data_Get_Struct(bind, struct BLOCK, data);
return rb_f_eval(argc+1, args, data->self);
}
#define PROC_TSHIFT (FL_USHIFT+1)
#define PROC_TMASK (FL_USER1|FL_USER2|FL_USER3)
#define PROC_TMAX (PROC_TMASK >> PROC_TSHIFT)
@ -9306,6 +9329,7 @@ Init_Binding()
rb_undef_alloc_func(rb_cBinding);
rb_undef_method(CLASS_OF(rb_cBinding), "new");
rb_define_method(rb_cBinding, "clone", proc_clone, 0);
rb_define_method(rb_cBinding, "eval", bind_eval, -1);
rb_define_global_function("binding", rb_f_binding, 0);
}

13
io.c
Просмотреть файл

@ -235,9 +235,6 @@ rb_io_check_readable(fptr)
OpenFile *fptr;
{
rb_io_check_closed(fptr);
if (!(fptr->mode & FMODE_READABLE)) {
rb_raise(rb_eIOError, "not opened for reading");
}
#if NEED_IO_SEEK_BETWEEN_RW
if (((fptr->mode & FMODE_WBUF) ||
(fptr->mode & (FMODE_SYNCWRITE|FMODE_RBUF)) == FMODE_SYNCWRITE) &&
@ -257,6 +254,9 @@ rb_io_check_writable(fptr)
if (!(fptr->mode & FMODE_WRITABLE)) {
rb_raise(rb_eIOError, "not opened for writing");
}
if (READ_DATA_BUFFERED(fptr->f)) {
rb_warn("read buffer data lost");
}
#if NEED_IO_SEEK_BETWEEN_RW
if ((fptr->mode & FMODE_RBUF) && !feof(fptr->f) && !fptr->f2) {
io_seek(fptr, 0, SEEK_CUR);
@ -1913,10 +1913,9 @@ rb_io_fptr_finalize(fptr)
free(fptr->path);
fptr->path = 0;
}
if (!fptr->f && !fptr->f2) return 0;
if (fileno(fptr->f) < 3) return 0;
rb_io_fptr_cleanup(fptr, Qtrue);
if ((fptr->f && fileno(fptr->f) > 2) || fptr->f2) {
rb_io_fptr_cleanup(fptr, Qtrue);
}
free(fptr);
return 1;
}

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

@ -2212,6 +2212,31 @@ rb_str_replace(str, str2)
return str;
}
/*
* call-seq:
* string.clear -> string
*
* Makes string empty.
*
* a = "abcde"
* a.clear #=> ""
*/
static VALUE
rb_str_clear(str)
VALUE str;
{
/* rb_str_modify() */ /* no need for str_make_independent */
if (str_independent(str)) {
free(RSTRING(str)->ptr);
}
RSTRING(str)->aux.shared = 0;
FL_UNSET(str, ELTS_SHARED|STR_ASSOC);
RSTRING(str)->ptr = 0;
RARRAY(str)->len = 0;
return str;
}
static VALUE
uscore_get()
{
@ -4593,6 +4618,7 @@ Init_String()
rb_define_method(rb_cString, "index", rb_str_index_m, -1);
rb_define_method(rb_cString, "rindex", rb_str_rindex_m, -1);
rb_define_method(rb_cString, "replace", rb_str_replace, 1);
rb_define_method(rb_cString, "clear", rb_str_clear, 0);
rb_define_method(rb_cString, "to_i", rb_str_to_i, -1);
rb_define_method(rb_cString, "to_f", rb_str_to_f, 0);