ruby-changes:34328
From: nobu <ko1@a...>
Date: Thu, 12 Jun 2014 13:09:55 +0900 (JST)
Subject: [ruby-changes:34328] nobu:r46410 (trunk): file.c: shrink expanded path
nobu 2014-06-12 13:09:41 +0900 (Thu, 12 Jun 2014) New Revision: 46410 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46410 Log: file.c: shrink expanded path * file.c (expand_path): shrink expanded path which no longer needs rooms to append. [ruby-core:63114] [Bug #9934] Modified files: trunk/ChangeLog trunk/file.c trunk/test/ruby/test_file_exhaustive.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 46409) +++ ChangeLog (revision 46410) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Jun 12 13:09:03 2014 Nobuyoshi Nakada <nobu@r...> + + * file.c (expand_path): shrink expanded path which no longer needs + rooms to append. [ruby-core:63114] [Bug #9934] + Wed Jun 11 17:37:48 2014 Nobuyoshi Nakada <nobu@r...> * configure.in (rb_cv_scalar_pthread_t): pthread_t is not required Index: test/ruby/test_file_exhaustive.rb =================================================================== --- test/ruby/test_file_exhaustive.rb (revision 46409) +++ test/ruby/test_file_exhaustive.rb (revision 46410) @@ -458,6 +458,13 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L458 end end + def test_expand_path_memsize + bug9934 = '[ruby-core:63114] [Bug #9934]' + require "objspace" + path = File.expand_path("/foo") + assert_operator(ObjectSpace.memsize_of(path), :<=, path.bytesize, bug9934) + end + def test_expand_path_encoding drive = (DRIVE ? 'C:' : '') if Encoding.find("filesystem") == Encoding::CP1251 Index: file.c =================================================================== --- file.c (revision 46409) +++ file.c (revision 46410) @@ -3507,6 +3507,16 @@ rb_file_expand_path_internal(VALUE fname https://github.com/ruby/ruby/blob/trunk/file.c#L3507 #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)))) @@ -3521,13 +3531,13 @@ VALUE https://github.com/ruby/ruby/blob/trunk/file.c#L3531 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()); } /* @@ -3575,7 +3585,7 @@ VALUE https://github.com/ruby/ruby/blob/trunk/file.c#L3585 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()); } /* @@ -5519,6 +5529,7 @@ is_explicit_relative(const char *path) https://github.com/ruby/ruby/blob/trunk/file.c#L5529 static VALUE copy_path_class(VALUE path, VALUE orig) { + str_shrink(path); RBASIC_SET_CLASS(path, rb_obj_class(orig)); OBJ_FREEZE(path); return path; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/