summaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-05 04:23:37 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-05 04:23:37 +0000
commitb9e630607ed20bd35adf75faee325d88654c42e4 (patch)
tree8415d744ce43c8bfd2c73a2e0a32231a5a24d896 /file.c
parentd7f49a9b066f511cdea83762b81d25fffd2f54c7 (diff)
merge revision(s) 46408,46410,46413,46414,46424,46436,46437: [Backport #9934]
string.c: shrink too big buffer * string.c (rb_str_resize): shrink the buffer even if new length is same but it is enough smaller than the capacity. * file.c (expand_path): shrink expanded path which no longer needs rooms to append. [ruby-core:63114] [Bug #9934] * string.c (rb_str_resize): should consider the capacity instead of the old length, as pointed out by nagachika. * string.c (rb_str_resize): update capa only when buffer get reallocated. http://d.hatena.ne.jp/nagachika/20140613/ruby_trunk_changes_46413_46420#r46413 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47399 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r--file.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/file.c b/file.c
index 70da79b735..96544766a9 100644
--- a/file.c
+++ b/file.c
@@ -3301,6 +3301,16 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na
#define EXPAND_PATH_BUFFER() rb_usascii_str_new(0, MAXPATHLEN + 2)
+static VALUE
+str_shrink(VALUE str)
+{
+ rb_str_resize(str, RSTRING_LEN(str));
+ return str;
+}
+
+#define expand_path(fname, dname, abs_mode, long_name, result) \
+ str_shrink(rb_file_expand_path_internal(fname, dname, abs_mode, long_name, result))
+
#define check_expand_path_args(fname, dname) \
(((fname) = rb_get_path(fname)), \
(void)(NIL_P(dname) ? (dname) : ((dname) = rb_get_path(dname))))
@@ -3315,13 +3325,13 @@ VALUE
rb_file_expand_path(VALUE fname, VALUE dname)
{
check_expand_path_args(fname, dname);
- return rb_file_expand_path_internal(fname, dname, 0, 1, EXPAND_PATH_BUFFER());
+ return expand_path(fname, dname, 0, 1, EXPAND_PATH_BUFFER());
}
VALUE
rb_file_expand_path_fast(VALUE fname, VALUE dname)
{
- return rb_file_expand_path_internal(fname, dname, 0, 0, EXPAND_PATH_BUFFER());
+ return expand_path(fname, dname, 0, 0, EXPAND_PATH_BUFFER());
}
/*
@@ -3358,7 +3368,7 @@ VALUE
rb_file_absolute_path(VALUE fname, VALUE dname)
{
check_expand_path_args(fname, dname);
- return rb_file_expand_path_internal(fname, dname, 1, 1, EXPAND_PATH_BUFFER());
+ return expand_path(fname, dname, 1, 1, EXPAND_PATH_BUFFER());
}
/*
@@ -5287,6 +5297,7 @@ is_explicit_relative(const char *path)
static VALUE
copy_path_class(VALUE path, VALUE orig)
{
+ str_shrink(path);
RBASIC(path)->klass = rb_obj_class(orig);
OBJ_FREEZE(path);
return path;