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

* dir.c (struct dir_data): change path field char * to VALUE.

(mark_dir): new function for mark path field.
  (free_dir): follow the path field change.
  (dir_s_alloc): ditto.
  (dir_initialize): ditto.
  (dir_s_open): ditto.
  (dir_inspect): ditto.
  (dir_path): return (duplicate of) the path field to preserve
  encoding.  [ruby-dev:35685]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-07-30 13:13:57 +00:00
parent 52bb9bb2d4
commit 84769be727
2 changed files with 28 additions and 12 deletions

View file

@ -1,3 +1,15 @@
Wed Jul 30 22:08:25 2008 Tanaka Akira <akr@fsij.org>
* dir.c (struct dir_data): change path field char * to VALUE.
(mark_dir): new function for mark path field.
(free_dir): follow the path field change.
(dir_s_alloc): ditto.
(dir_initialize): ditto.
(dir_s_open): ditto.
(dir_inspect): ditto.
(dir_path): return (duplicate of) the path field to preserve
encoding. [ruby-dev:35685]
Wed Jul 30 22:06:56 2008 Yusuke Endoh <mame@tsg.ne.jp>
* string.c (sym_inspect): remove dead code.

28
dir.c
View file

@ -289,16 +289,21 @@ VALUE rb_cDir;
struct dir_data {
DIR *dir;
char *path;
VALUE path;
rb_encoding *extenc;
};
static void
mark_dir(struct dir_data *dir)
{
rb_gc_mark(dir->path);
}
static void
free_dir(struct dir_data *dir)
{
if (dir) {
if (dir->dir) closedir(dir->dir);
if (dir->path) xfree(dir->path);
}
xfree(dir);
}
@ -309,10 +314,10 @@ static VALUE
dir_s_alloc(VALUE klass)
{
struct dir_data *dirp;
VALUE obj = Data_Make_Struct(klass, struct dir_data, 0, free_dir, dirp);
VALUE obj = Data_Make_Struct(klass, struct dir_data, mark_dir, free_dir, dirp);
dirp->dir = NULL;
dirp->path = NULL;
dirp->path = Qnil;
dirp->extenc = NULL;
return obj;
@ -357,9 +362,8 @@ dir_initialize(int argc, VALUE *argv, VALUE dir)
Data_Get_Struct(dir, struct dir_data, dp);
if (dp->dir) closedir(dp->dir);
if (dp->path) xfree(dp->path);
dp->dir = NULL;
dp->path = NULL;
dp->path = Qnil;
dp->extenc = extencoding;
dp->dir = opendir(RSTRING_PTR(dirname));
if (dp->dir == NULL) {
@ -371,7 +375,7 @@ dir_initialize(int argc, VALUE *argv, VALUE dir)
rb_sys_fail(RSTRING_PTR(dirname));
}
}
dp->path = strdup(RSTRING_PTR(dirname));
dp->path = rb_str_dup_frozen(dirname);
return dir;
}
@ -391,7 +395,7 @@ static VALUE
dir_s_open(int argc, VALUE *argv, VALUE klass)
{
struct dir_data *dp;
VALUE dir = Data_Make_Struct(klass, struct dir_data, 0, free_dir, dp);
VALUE dir = Data_Make_Struct(klass, struct dir_data, mark_dir, free_dir, dp);
dir_initialize(argc, argv, dir);
if (rb_block_given_p()) {
@ -440,9 +444,9 @@ dir_inspect(VALUE dir)
struct dir_data *dirp;
Data_Get_Struct(dir, struct dir_data, dirp);
if (dirp->path) {
if (!NIL_P(dirp->path)) {
const char *c = rb_obj_classname(dir);
return rb_sprintf("#<%s:%s>", c, dirp->path);
return rb_sprintf("#<%s:%s>", c, RSTRING_PTR(dirp->path));
}
return rb_funcall(dir, rb_intern("to_s"), 0, 0);
}
@ -462,8 +466,8 @@ dir_path(VALUE dir)
struct dir_data *dirp;
Data_Get_Struct(dir, struct dir_data, dirp);
if (!dirp->path) return Qnil;
return dir_enc_str(rb_str_new2(dirp->path), dirp);
if (NIL_P(dirp->path)) return Qnil;
return rb_str_dup(dirp->path);
}
/*