diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-09-21 03:08:33 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-09-21 03:08:33 +0000 |
commit | bfabc05a4375b84fa128af89337b1195248bd6da (patch) | |
tree | ae0c8f703dca2b6ae94a5b5518c736d373bca377 /dir.c | |
parent | 90ae99b0f0505f66a6fc1dfb7d7c631bf4bf76cc (diff) | |
download | ruby-bfabc05a4375b84fa128af89337b1195248bd6da.tar.gz |
* enum.c (enum_sort_by): do not use qsort directly. use
rb_ary_sort_bang() instead. [ruby-dev:24291]
* enum.c (enum_sort_by): pedantic type check added.
[ruby-dev:24291]
* hash.c (rb_hash_foreach_iter): check iter_lev after each
iteration. [ruby-dev:24289]
* array.c (rb_ary_and): element size might change during
comparison. [ruby-dev:24290]
* array.c (rb_ary_or): ditto. [ruby-dev:24292]
* array.c (rb_ary_equal): wrong fix. [ruby-dev:24286]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6939 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'dir.c')
-rw-r--r-- | dir.c | 51 |
1 files changed, 27 insertions, 24 deletions
@@ -677,36 +677,42 @@ dir_close(dir) static void dir_chdir(path) - const char *path; + VALUE path; { - if (chdir(path) < 0) - rb_sys_fail(path); + if (chdir(RSTRING(path)->ptr) < 0) + rb_sys_fail(RSTRING(path)->ptr); } static int chdir_blocking = 0; static VALUE chdir_thread = Qnil; struct chdir_data { - char *dist; - VALUE path; + VALUE old_path, new_path; + int done; }; static VALUE chdir_yield(args) struct chdir_data *args; { - dir_chdir(args->dist); - return rb_yield(args->path); + dir_chdir(args->new_path); + args->done = Qtrue; + chdir_blocking++; + if (chdir_thread == Qnil) + chdir_thread = rb_thread_current(); + return rb_yield(args->new_path); } static VALUE -chdir_restore(path) - char *path; +chdir_restore(args) + struct chdir_data *args; { - chdir_blocking--; - if (chdir_blocking == 0) - chdir_thread = Qnil; - dir_chdir(path); + if (args->done) { + chdir_blocking--; + if (chdir_blocking == 0) + chdir_thread = Qnil; + dir_chdir(args->old_path); + } return Qnil; } @@ -756,19 +762,18 @@ dir_s_chdir(argc, argv, obj) VALUE obj; { VALUE path = Qnil; - char *dist = ""; rb_secure(2); if (rb_scan_args(argc, argv, "01", &path) == 1) { FilePathValue(path); - dist = RSTRING(path)->ptr; } else { - dist = getenv("HOME"); + const char *dist = getenv("HOME"); if (!dist) { dist = getenv("LOGDIR"); if (!dist) rb_raise(rb_eArgError, "HOME/LOGDIR not set"); } + path = rb_str_new2(dist); } if (chdir_blocking > 0) { @@ -777,17 +782,15 @@ dir_s_chdir(argc, argv, obj) } if (rb_block_given_p()) { - char *cwd = my_getcwd(); struct chdir_data args; + char *cwd = my_getcwd(); - chdir_blocking++; - if (chdir_thread == Qnil) - chdir_thread = rb_thread_current(); - args.dist = dist; - args.path = path; - return rb_ensure(chdir_yield, (VALUE)&args, chdir_restore, (VALUE)cwd); + args.old_path = rb_tainted_str_new2(cwd); free(cwd); + args.new_path = path; + args.done = Qfalse; + return rb_ensure(chdir_yield, (VALUE)&args, chdir_restore, (VALUE)&args); } - dir_chdir(dist); + dir_chdir(path); return INT2FIX(0); } |