@@ -3397,6 +3397,16 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na
33973397
33983398#define EXPAND_PATH_BUFFER () rb_usascii_str_new(0, MAXPATHLEN + 2)
33993399
3400+ static VALUE
3401+ str_shrink (VALUE str )
3402+ {
3403+ rb_str_resize (str , RSTRING_LEN (str ));
3404+ return str ;
3405+ }
3406+
3407+ #define expand_path (fname , dname , abs_mode , long_name , result ) \
3408+ str_shrink(rb_file_expand_path_internal(fname, dname, abs_mode, long_name, result))
3409+
34003410#define check_expand_path_args (fname , dname ) \
34013411 (((fname) = rb_get_path(fname)), \
34023412 (void)(NIL_P(dname) ? (dname) : ((dname) = rb_get_path(dname))))
@@ -3411,13 +3421,13 @@ VALUE
34113421rb_file_expand_path (VALUE fname , VALUE dname )
34123422{
34133423 check_expand_path_args (fname , dname );
3414- return rb_file_expand_path_internal (fname , dname , 0 , 1 , EXPAND_PATH_BUFFER ());
3424+ return expand_path (fname , dname , 0 , 1 , EXPAND_PATH_BUFFER ());
34153425}
34163426
34173427VALUE
34183428rb_file_expand_path_fast (VALUE fname , VALUE dname )
34193429{
3420- return rb_file_expand_path_internal (fname , dname , 0 , 0 , EXPAND_PATH_BUFFER ());
3430+ return expand_path (fname , dname , 0 , 0 , EXPAND_PATH_BUFFER ());
34213431}
34223432
34233433/*
@@ -3465,7 +3475,7 @@ VALUE
34653475rb_file_absolute_path (VALUE fname , VALUE dname )
34663476{
34673477 check_expand_path_args (fname , dname );
3468- return rb_file_expand_path_internal (fname , dname , 1 , 1 , EXPAND_PATH_BUFFER ());
3478+ return expand_path (fname , dname , 1 , 1 , EXPAND_PATH_BUFFER ());
34693479}
34703480
34713481/*
@@ -5408,6 +5418,7 @@ is_explicit_relative(const char *path)
54085418static VALUE
54095419copy_path_class (VALUE path , VALUE orig )
54105420{
5421+ str_shrink (path );
54115422 RBASIC_SET_CLASS (path , rb_obj_class (orig ));
54125423 OBJ_FREEZE (path );
54135424 return path ;
0 commit comments