file.c: get rid of useless conversion
* file.c (rb_file_s_stat): File.stat does not accept an IO object as trying conversion to path name string first. skip conversion to IO and try stat(2) only. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
015a415ee3
commit
1daa624d56
43
file.c
43
file.c
@ -1082,6 +1082,17 @@ no_gvl_fstat(void *data)
|
|||||||
return (VALUE)fstat(arg->file.fd, arg->st);
|
return (VALUE)fstat(arg->file.fd, arg->st);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
fstat_without_gvl(int fd, struct stat *st)
|
||||||
|
{
|
||||||
|
no_gvl_stat_data data;
|
||||||
|
|
||||||
|
data.file.fd = fd;
|
||||||
|
data.st = st;
|
||||||
|
|
||||||
|
return (int)(VALUE)rb_thread_io_blocking_region(no_gvl_fstat, &data, fd);
|
||||||
|
}
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
no_gvl_stat(void * data)
|
no_gvl_stat(void * data)
|
||||||
{
|
{
|
||||||
@ -1089,28 +1100,39 @@ no_gvl_stat(void * data)
|
|||||||
return (void *)(VALUE)STAT(arg->file.path, arg->st);
|
return (void *)(VALUE)STAT(arg->file.path, arg->st);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
stat_without_gvl(const char *path, struct stat *st)
|
||||||
|
{
|
||||||
|
no_gvl_stat_data data;
|
||||||
|
|
||||||
|
data.file.path = path;
|
||||||
|
data.st = st;
|
||||||
|
|
||||||
|
return (int)(VALUE)rb_thread_call_without_gvl(no_gvl_stat, &data,
|
||||||
|
RUBY_UBF_IO, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
rb_stat(VALUE file, struct stat *st)
|
rb_stat(VALUE file, struct stat *st)
|
||||||
{
|
{
|
||||||
VALUE tmp;
|
VALUE tmp;
|
||||||
VALUE result;
|
int result;
|
||||||
no_gvl_stat_data data;
|
|
||||||
|
|
||||||
data.st = st;
|
|
||||||
tmp = rb_check_convert_type_with_id(file, T_FILE, "IO", idTo_io);
|
tmp = rb_check_convert_type_with_id(file, T_FILE, "IO", idTo_io);
|
||||||
if (!NIL_P(tmp)) {
|
if (!NIL_P(tmp)) {
|
||||||
rb_io_t *fptr;
|
rb_io_t *fptr;
|
||||||
|
|
||||||
GetOpenFile(tmp, fptr);
|
GetOpenFile(tmp, fptr);
|
||||||
data.file.fd = fptr->fd;
|
result = fstat_without_gvl(fptr->fd, st);
|
||||||
result = rb_thread_io_blocking_region(no_gvl_fstat, &data, fptr->fd);
|
file = tmp;
|
||||||
return (int)result;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
FilePathValue(file);
|
FilePathValue(file);
|
||||||
file = rb_str_encode_ospath(file);
|
file = rb_str_encode_ospath(file);
|
||||||
data.file.path = StringValueCStr(file);
|
result = stat_without_gvl(RSTRING_PTR(file), st);
|
||||||
result = (VALUE)rb_thread_call_without_gvl(no_gvl_stat, &data, RUBY_UBF_IO, NULL);
|
}
|
||||||
return (int)result;
|
RB_GC_GUARD(file);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1130,7 +1152,8 @@ rb_file_s_stat(VALUE klass, VALUE fname)
|
|||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
FilePathValue(fname);
|
FilePathValue(fname);
|
||||||
if (rb_stat(fname, &st) < 0) {
|
fname = rb_str_encode_ospath(fname);
|
||||||
|
if (stat_without_gvl(RSTRING_PTR(fname), &st) < 0) {
|
||||||
rb_sys_fail_path(fname);
|
rb_sys_fail_path(fname);
|
||||||
}
|
}
|
||||||
return rb_stat_new(&st);
|
return rb_stat_new(&st);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user