@@ -3397,6 +3397,16 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na
3397
3397
3398
3398
#define EXPAND_PATH_BUFFER () rb_usascii_str_new(0, MAXPATHLEN + 2)
3399
3399
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
+
3400
3410
#define check_expand_path_args (fname , dname ) \
3401
3411
(((fname) = rb_get_path(fname)), \
3402
3412
(void)(NIL_P(dname) ? (dname) : ((dname) = rb_get_path(dname))))
@@ -3411,13 +3421,13 @@ VALUE
3411
3421
rb_file_expand_path (VALUE fname , VALUE dname )
3412
3422
{
3413
3423
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 ());
3415
3425
}
3416
3426
3417
3427
VALUE
3418
3428
rb_file_expand_path_fast (VALUE fname , VALUE dname )
3419
3429
{
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 ());
3421
3431
}
3422
3432
3423
3433
/*
@@ -3465,7 +3475,7 @@ VALUE
3465
3475
rb_file_absolute_path (VALUE fname , VALUE dname )
3466
3476
{
3467
3477
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 ());
3469
3479
}
3470
3480
3471
3481
/*
@@ -5408,6 +5418,7 @@ is_explicit_relative(const char *path)
5408
5418
static VALUE
5409
5419
copy_path_class (VALUE path , VALUE orig )
5410
5420
{
5421
+ str_shrink (path );
5411
5422
RBASIC_SET_CLASS (path , rb_obj_class (orig ));
5412
5423
OBJ_FREEZE (path );
5413
5424
return path ;
0 commit comments