summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-07 10:18:45 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-07 10:18:45 (GMT)
commit79219d96562e1254e725bb20f9e821459d40f0f8 (patch)
tree9b1ce5a0825b675e72e2a4a19375e4b1e48c30bb /dir.c
parent376c4e8100082b2012306ac87b05033bf9fbfe00 (diff)
dir.c: GC guard
* dir.c (dir_initialize): add GC guard for retrying. the argument of RSTRING_PTR() may be eliminated by optimization. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49169 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/dir.c b/dir.c
index b6f4ca4..292e9b8 100644
--- a/dir.c
+++ b/dir.c
@@ -445,6 +445,7 @@ dir_initialize(int argc, VALUE *argv, VALUE dir)
rb_encoding *fsenc;
VALUE dirname, opt, orig;
static ID keyword_ids[1];
+ const char *path;
if (!keyword_ids[0]) {
keyword_ids[0] = rb_intern("encoding");
@@ -472,13 +473,15 @@ dir_initialize(int argc, VALUE *argv, VALUE dir)
dp->dir = NULL;
dp->path = Qnil;
dp->enc = fsenc;
- dp->dir = opendir(RSTRING_PTR(dirname));
+ path = RSTRING_PTR(dirname);
+ dp->dir = opendir(path);
if (dp->dir == NULL) {
if (errno == EMFILE || errno == ENFILE) {
rb_gc();
- dp->dir = opendir(RSTRING_PTR(dirname));
+ dp->dir = opendir(path);
}
if (dp->dir == NULL) {
+ RB_GC_GUARD(dirname);
rb_sys_fail_path(orig);
}
}