This converts all slow syscalls in the Dir.empty? implementation
to release GVL. We avoid unnecessarily GVL release and
reacquire for each slow call (opendir, readdir, closedir) and
instead only release and acquire the GVL once in the common
case.
Benchmark results show a small degradation in single-threaded
performance:
Execution time (sec)
name trunk built
dir_empty_p 0.689 0.758
Speedup ratio: compare with the result of `trunk' (greater is better)
name built
dir_empty_p 0.909
* dir.c (rb_gc_for_fd_with_gvl): new function
(nogvl_dir_empty_p): ditto
(dir_s_empty_p): use new functions to release GVL
* benchmark/bm_dir_empty_p.rb: new benchmark
[ruby-core:83071] [Feature #13958]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60111 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (glob_helper): fix up r59527, dot files other than current
directory should not be included unless FNM_DOTMATCH is given.
[ruby-core:82266] [Bug #13785]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59529 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (glob_helper): fix up r59481 for old kernels, which
provide d_type member but just always set DT_UNKNOWN for any
entries. [ruby-core:82266] [Bug #13785]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (glob_helper): utilize d_type even if no recursive
pattern, to reduce stat/lstat syscalls in subsequent
glob_helper.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59481 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (glob_helper): fix globbing based on a relative path Dir.
[Feature #13056]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59479 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (dir_glob_options): relax base option. ignore when nil
or an empty string as :base option. [Feature #13056]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59476 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
The lifetime of a String VALUE must match or exceed the lifetime
of its R*_PTR result; otherwise the GC can while reclaim the
VALUE while the R*_PTR result is in use.
* dir.c (ruby_brace_expand): add var parameter for GC guard
(ruby_brace_glob_with_enc): adjust call
(file_s_fnmatch): ditto
(push_glob): remove misplaced GC guard
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59416 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* win32/win32.c (rb_dir_getwd_ospath): Windows implementation
moved from dir.c. get rid of freeing malloced memory by xfree.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59061 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (rb_dir_getwd_ospath): return cwd path in the OS path
encoding.
* file.c (rb_realpath_internal): work in the OS path encoding
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (glob_helper): yield globbed part only without the base
directory path part if the base is given. [Feature#13056]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58901 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c: [DOC] document the new `base` keyword argument of Dir.glob
[Feature #13056]; also improve docs for Dir.glob and Dir[].
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (dir_s_each_child, dir_s_children): Dir.each_child and
Dir.children which are similar to Dir.foreach and Dir.entries
respectively, except to exclude "." and "..". [Feature #11302]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58879 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (glob_helper): support Dir instance as `base` option.
[Feature#13056]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
enc is the name of the variable used in the example, not the name of the
keyword argument (encoding).
The documentation used to wrongly suggest that the keyword argument name was
"enc" which could cause people try try to call `Dir.open("thing", enc: "utf-8")`
Author: Olivier Lacan <hi@olivierlacan.com>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58566 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (glob_helper): raise a SystemCallError exception when
opendir() failed, except for ENOENT, ENOTDIR, and EACCES. this
behavior predates 1.0; the comments in glob.c claimed that
glob() returned -1 on error but actualy the pointer to a global
variable, then dir_glob() did check only -1 as the comments, and
ignored actual errors. [ruby-core:80226] [Bug #13276]
dir.c: ruby_glob_funcs_t
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (is_case_sensitive): use getattrlist() if fgetattrlist()
is unavailable, on OSX 10.5. [ruby-core:68829] [Bug #11054]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57248 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (rb_glob): merge rb_glob2 which is used only here.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (do_opendir): retry after GC when the limit for open file
descriptors reached.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56467 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (rb_dir_s_empty_p): use rb_gc_for_fd for the condition to
invoke GC by errno.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56466 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (to_be_ignored): make an inline function to get rid of
multiple errno function calls.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56465 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* *.c: rename rb_funcall2 to rb_funcallv, except for extensions
which are/will be/may be gems. [Fix GH-1406]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55773 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (USE_NAME_ON_FS): name constants.
* USE_NAME_ON_FS_REAL_BASENAME: platform dependent APIs to get
real basenames.
* USE_NAME_ON_FS_BY_FNMATCH: select the matching basename by
fnmatch.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55470 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (push_pattern, push_glob): deal with read paths as UTF-8
to stat later, on Windows as well as OS X.
[ruby-core:73868] [Bug #12081]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53877 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (rb_dir_s_empty_p): add Dir.empty? method, which tells the
argument is the name of an empty directory. [Feature #10121]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53841 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
NULL checking is finished Before call of memsize functions.
See r52979.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (dir_initialize): use rb_gc_for_fd for ENOMEM
* ext/socket/init.c (rsock_socket): ditto
* ext/socket/socket.c (rsock_socketpair): ditto
* internal.h (rb_gc_for_fd): prototype
* io.c (rb_gc_for_fd): remove static
[ruby-core:71623] [Feature #11727]
Manpages for opendir(2), socket(2), and socketpair(3posix)
describe ENOMEM as a possible error for each of these;
handle it consistently with our existing wrappers for
open(2)/pipe(2) etc...
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52726 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Solaris 10 does not have dirfd, but the file descriptor of a
directory is stored in the d_fd or dd_fd member in the DIR struct.
Note that Solaris 11 has dirfd(3C).
* configure.in: checks for DIR.d_fd and DIR.dd_fd on Solaris 10.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (ruby_brace_expand): glob brace expansion edge case fix.
When there are closing braces '}' before a open brace '{' it
must be ignored and considered as literal.
[ruby-core:71138] [Bug #11609]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52212 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (rb_dir_getwd): make ASCII-8BIT if filesystem encoding is
US-ASCII, like as Dir.glob.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52031 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (rb_dir_getwd): normalize OS path to UTF-8 on OS X.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52012 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (glob_helper): move pathlen to argument which is known in
the callers almost.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51990 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (is_case_sensitive): get attributes by the file descriptor
of open directory, instead of using mount point name.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (replace_real_basename): Win32 API does not set errno, get
the last error by GetLastError() and map to errno. [Bug #10015]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51111 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (replace_real_basename): update path type by the target
attributes if possible, to improve the performance. [Bug #10015]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51106 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
volatile is unnecessary since we use rb_sys_fail_path nowadays
and that prevents the path argument from being GC-ed.
Using a return value instead of modifying the argument directly
simplifies the generated code (on 32-bit x86):
text data bss dec hex filename
20744 40 20 20804 5144 dir.o-orig
20720 40 20 20780 512c dir.o
* dir.c (check_dirname): avoid volatile, use return value
(dir_s_chroot, dir_s_mkdir, dir_s_rmdir): adjust callers
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51000 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (dirent_match): match short names only when FNM_SHORTNAME
flag is given, for the backward compatibility, and the new
behavior is often dangerous. [ruby-core:69435] [Bug #11206]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50760 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (need_normalization): use getattrlist() if fgetattrlist()
is unavailable, on OSX 10.5. [ruby-core:68829] [Bug #11054]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50218 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (ruby_brace_glob_with_enc): call ruby_brace_glob_with_enc
in ruby_brace_glob, and expanded ruby_brace_glob0 which is no
longer used anywhere else.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50144 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (dir_close): don't raise on dobule close for consistent to
IO#close.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50064 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* win32/win32.c (winnt_stat): stat with following symbolic links.
* win32/win32.c (winnt_lstat): rename old winnt_stat, which does
not follow symbolic links.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50060 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (glob_helper): distinguish not-yet-stated and DT_UNKNOWN
by readdir, and traverse recursively for the former. Linux
readdir returns DT_UNKNOWN on some filesystems, e.g., smbfs,
iso9660.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49983 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (glob_helper): use d_type to reduce lstat system calls.
* win32/dir.h (struct direct): add d_type instead of d_isdir and
d_isrep. SYMLINKD is unreliable, since the target can be
replaced after a link was created.
* win32/win32.c (readdir_internal): set d_type.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49966 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (glob_helper): match patterns against legacy short names
too, not only ordinary names. [ruby-core:67954] [Bug #10819]
* win32/dir.h (struct direct): add short name members.
* win32/win32.c (opendir_internal, readdir_internal): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49892 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
the object system is loaded.
[ruby-core:68430] [Bug #10941]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49859 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (push_pattern, push_glob): make globbed file names same
encoding to the given pattern.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49744 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (is_case_sensitive, replace_real_basename): [OSX] use
packed structs instead of arrays to suppress warning by older
versions of gcc.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49712 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* use rb_funcallv() for no arguments call instead of variadic
rb_funcall().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49612 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (has_magic): always get long path name on Windows even if
no tilde is there. [ruby-core:68011] [Bug #10819]
* dir.c (replace_real_basename): FindFirstFile ignore redirection
character, check if exists before call it. cf. [Bug #8597]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (glob_helper): use USE_NAME_ON_FS instead of configure and
platform macro list.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (sys_enc_warning_in): preserve encoding of path name in
warning messages.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (glob_helper): obtain real name with FindFirstFile API
instead of matchin all entries, on Windows.
[ruby-core:67954] [Bug #10819]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49478 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (glob_helper): match in case-folding only if the directory
resides on a case-insensitve file system, on OSX.
[ruby-core:67364] [Bug #10700]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (dir_initialize): workaround of opendir failure at symlink
directories on Windows via CIFS.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49170 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (dir_initialize): add GC guard for retrying. the argument
of RSTRING_PTR() may be eliminated by optimization.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49169 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (need_normalization): not only HFS+, CIFS (SMB) is also
decomposed. [Bug #10704]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49168 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (NORMALIZE_UTF8PATH): Unicode decomposition seems to
perform in an upper layer than file systems on OSX, as all path
names are always decomposed regardless of file system types.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49166 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (ruby_glob0): no need to check never-NULL pointer.
reported by Denis Denisov <denji0k AT gmail.com>.
* win32/file.c (rb_file_expand_path_internal): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (replace_real_basename): get the real name and replace the
base name with it by getattrlist(2) if available.
suggested by Matthew Draper at [ruby-core:67116]. [Bug #10015]
* dir.c (glob_helper): get the real name of the whole path, not
only the last name.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48990 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (glob_helper): shortcut for case-insensitive name by
stopping reading after a matching name found.
[ruby-core:63591] [Bug #10015]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48975 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (glob_make_pattern): restrict searching case-insensitive
name from the filesystem to only last part, for the performance.
[ruby-core:63591] [ruby-core:63591]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48972 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
use 0 for rb_data_type_t::reserved instead of NULL, since its type
may be changed in the future and possibly not a pointer type.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48662 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (dir_s_aref): fix rdoc. `Dir.glob` allows an array but
`Dir[]` not. the former accepts an optional parameter `flags`,
while the latter accepts arbitrary number of arguments but no
`flags`. [ruby-core:65265] [Bug #10294]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47850 b2dd03c8-39d4-4d8f-98ff-823fe69b080e