Граф коммитов

441 Коммитов

Автор SHA1 Сообщение Дата
kazu 246c986eac Use `const void*` instead of `const char*`
Use cast from `char*` to `void*` instead of union in opendir_without_gvl,
because convert from `void*` to `char*` without union in nogvl_opendir.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-21 12:29:51 +00:00
usa 4f83ca015d Cannot call rb_thread_call_with{out,}_gvl before running VM
* dir.c (opendir_without_gvl, with_gvl_gc_for_fd, opendir_at): check the VM is
  already initialized before calling rb_thread_call_with{out,}_gvl().
  [Bug #14115]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60837 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-18 08:25:29 +00:00
normal 8840b033fb dir.c: openat calls release GVL, too
openat(2) also performs a path lookup, so it is also subject
to pathological slowdowns like opendir(3) and open(2) syscalls.

* dir.c (struct opendir_at_arg): new struct for callback
  (with_gvl_gc_for_fd): new callback for rb_thread_call_with_gvl
  (gc_for_fd_with_gvl): moved up
  (nogvl_opendir_at): extracted from do_opendir
  (opendir_at): new wrapper to release GVL for opendir_at
  (do_opendir): use new wrappers to release GVL
  (nogvl_dir_empty_p): adjust for gc_for_fd_with_gvl

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60831 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-18 02:01:49 +00:00
normal 089eb0c5ce dir: release GVL on opendir
opendir(3) is subject to the same pathological slowdowns on
slow or unreliable filesystems as open(2), so release the GVL
to avoid stalling the entire VM like we do with IO#open

* dir.c (nogvl_opendir): new function
  (opendir_without_gvl): new function
  (dir_initialize): s/opendir/&_without_gvl/
  (do_opendir): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60830 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-18 02:01:44 +00:00
normal 0cc57ea018 dir.c: revert r60772, r60770, and r60769
Using readdir(3) without any locking causes thread-safety
problems if directory streams get shared between threads.  On
ancient platforms, readdir(3) may have thread-safety problems
even on different directory streams.

Using readdir_r(3) is not viable, either, as it's deprecated
due to name overflow problems.

So for now, rely on GVL as in previous Rubies and perhaps
consider per-"struct dir_data" mutexes for modern platforms
which allow concurrent calls to readdir(3) on different
directory streams.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60774 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-15 07:24:26 +00:00
usa e9614f9a37 Cannot call rb_thread_call_without_gvl before running VM
* dir.c (readdir_without_gvl): check the VM is already initialized before
  calling rb_thread_call_without_gvl().
  [Bug #14108]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-15 05:18:37 +00:00
usa 5570dba96f nogvl readdir make SEGV on Windows
* dir.c (readdir_without_gvl): workaround for Windows.  [Bug #14108]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60770 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-15 03:44:58 +00:00
normal ea3211720d dir.c: release GVL around remaining readdir calls
Release GVL around all remaining readdir calls from the Dir
class to prevent pathological stalls on slow filesystems in
multi-threaded applications.

opendir, rewinddir, closedir calls are not affected yet, but
will be changed in future commits.

In the future, further work may be done consolidate multiple GVL
releasing calls to reduce overhead, similar to how changes to
Dir.empty? were made in r60111

* dir.c (nogvl_readdir): new function
  (readdir_without_gvl): ditto
  (dir_read): s/READDIR/readdir_without_gvl/
  (dir_each_entry): ditto
  (glob_helper): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60769 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-14 23:20:31 +00:00
nobu bfbf5b0b3e dir.c: cast to suppress a warning
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60597 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-01 01:55:45 +00:00
normal f5f6232399 dir: Dir.mkdir and Dir.rmdir release GVL
This avoids blocking the entire VM when operating on slow or
unreliable filesystems.  Instead, only the thread performing
the mkdir or rmdir operation is blocked and other threads
are free to proceed.

* dir.c (nogvl_mkdir): new function
  (nogvl_rmdir): ditto
  (dir_s_mkdir): release GVL
  (dir_s_rmdir): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-01 00:17:11 +00:00
normal c9d41f6055 use mode_t where applicable (instead of int)
mode_t is the correct type for these syscalls and it can be
easier-to-understand.  It may also help portability to future
platforms and improve type checking.

* dir.c (dir_s_mkdir): use mode_t for mkdir(2)

* file.c (chmod_internal): use mode_t for chmod(2)
  (rb_file_s_chmod): s/int/mode_t/
  (lchmod_internal): ditto, deref pointer as in chmod_internal
  (rb_file_s_lchmod): pass pointer as in rb_file_s_chmod
  (rb_file_s_rename): use mode_t for umask(2)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-31 19:10:19 +00:00
normal 0b0e71ba2b dir: Dir.chdir releases GVL
chdir(2) is subject to all the pathological slowdowns and
caveats as open(2) on slow or unreliable filesystems, so ensure
other threads can proceed while this is happening.

* dir.c (nogvl_chdir): new function

* dir.c (dir_chdir): release GVL

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60583 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-30 23:47:27 +00:00
naruse a6488f04de Revert "Dir.glob with FNM_EXTGLOB is optimized [Feature #13873]"
This reverts commit r60341,r60342,r60344,r60345.
Breaking compabitility of the order of result breaks many tests.
To avoid such effort to fix tests, the order should be kept.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60478 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-27 08:40:40 +00:00
hsbt 0e2d2e6a79 Drop to support NaCl platform.
Because NaCl and PNaCl are already sunset status.
  see https://bugs.chromium.org/p/chromium/issues/detail?id=239656#c160

  configure.ac: Patch for this file was provided by @nobu.

  [Feature #14041][ruby-core:83497][fix GH-1726]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-23 05:56:25 +00:00
nobu 7fa932ece6 dir.c: adjust indent [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60345 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-22 04:06:23 +00:00
naruse 3866715356 Dir.glob with FNM_EXTGLOB is optimized [Feature #13873]
The order of resulted array is changed in some cases.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60341 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-22 02:03:49 +00:00
naruse b39132e993 Revert "ignore server side error"
This reverts commit r60314.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60315 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 16:44:56 +00:00
naruse facccd3129 ignore server side error
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60314 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 16:43:54 +00:00
naruse c1db20c3b5 Revert "Dir.glob with FNM_EXTGLOB is optimized [Feature #13873]"
This reverts commit r60253 because it causes on error on Linux.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60255 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 10:44:13 +00:00
naruse e2a92c54e6 Dir.glob with FNM_EXTGLOB is optimized [Feature #13873]
The order of resulted array is changed in some cases.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60253 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 10:28:34 +00:00
nobu 20685cdc85 Get rid of shadowing local variables
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-18 04:35:25 +00:00
normal 1e14126b4f Dir.empty? releases GVL
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
2017-10-04 00:04:51 +00:00
nobu ec4af34efb dir.c: fix up r59527
* 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
2017-08-08 10:43:19 +00:00
nobu 50dc093d6b dir.c: fix up r59481 for old kernels
* 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
2017-08-08 08:34:10 +00:00
nobu 76857f8ee8 dir.c: reduce syscalls
* 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
2017-08-03 04:13:12 +00:00
nobu 1ef613dd0b dir.c: relative path Dir base
* 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
2017-08-03 03:39:33 +00:00
nobu 83a31e9e90 dir.c: relax base option
* 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
2017-08-03 02:14:51 +00:00
normal 8e2d0deb88 dir.c (ruby_brace_expand): RB_GC_GUARD safety
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
2017-07-25 05:55:22 +00:00
nobu ff5e3b98a0 win32.c: rb_dir_getwd_ospath
* 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
2017-06-12 00:18:30 +00:00
nobu aac0b43ed5 file.c: realpath in OS path encoding
* 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
2017-06-08 01:58:44 +00:00
ko1 b4621c9aae make Dir object WB protected.
* dir.c (dir_data_type): set RUBY_TYPED_WB_PROTECTED.
  Insert WBs for dir_data::path.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58990 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-01 15:18:51 +00:00
nobu 1dec75c02f dir.c: fix FD leaks
* dir.c (do_opendir): close FD when fdopendir failed, e.g.,
  ENOTDIR.  [Feature#13056]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58912 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-27 01:04:23 +00:00
nobu 5e7ce51911 dir.c: yield without base part
* 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
2017-05-26 07:04:43 +00:00
stomar 4bc4403b2d dir.c: document base keyword argument of Dir.glob
* 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
2017-05-25 08:34:13 +00:00
stomar 135c7a53ec dir.c: docs for Dir.each_child and Dir.children
* dir.c: [DOC] fix examples for Dir.each_child and Dir.children.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58884 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-25 07:50:20 +00:00
nobu 944c455b38 dir.c: Dir.each_child and Dir.children
* 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
2017-05-25 02:50:21 +00:00
nobu bf463442ed dir.c: dir_each_entries
* dir.c (dir_each_entries): expand entries without method calls.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58877 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-25 01:46:36 +00:00
nobu de5e3475c0 dir.c: prefer NAMLEN to d_name
* dir.c (glob_helper): prefer NAMLEN, do not assume d_name is NUL
  terminated everywhere.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-24 14:26:09 +00:00
nobu 6d06aadd8e Dir as base option
* 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
2017-05-23 14:34:12 +00:00
nobu 52419a6e10 Dir.glob base option
* dir.c (dir_s_aref, dir_s_glob): add new optional keyword
  argument, `base`.  [Feature#13056]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58858 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-23 13:47:36 +00:00
nobu 92690b6235 potential memory leak
* dir.c (rb_dir_getwd): get rid of potential memory leak.

* util.c (ruby_getcwd): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-18 11:29:42 +00:00
nobu 000482a173 rb_w32_ugetcwd: UTF-8 version getcwd
* dir.c (rb_dir_getwd): convert from UTF-8.

* win32/win32.c (w32_getcwd): codepage aware getcwd using
  GetCurrentDirectoryW.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58745 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-16 10:25:56 +00:00
ktsj 5c8edab967 dir.c: [DOC] Properly refer to keyword argument by its name [Fix GH-1543]
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
2017-05-04 08:58:59 +00:00
nobu 4756365503 dir.c: err at glob failure
* 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
2017-03-27 14:57:08 +00:00
normal cad4591086 remove branches in dmark and dfree GC callbacks
dmark and dfree callbacks are never called in gc.c for NULL
DATA_PTR values, not even for zombie objects.

* compile.c (ibf_loader_mark): remove branch for pointer validity
* compile.c (ibf_loader_free): ditto
* cont.c (cont_free): ditto
* cont.c (fiber_free): ditto
* dir.c (dir_free): ditto
* ext/stringio/stringio.c (strio_mark): ditto
* proc.c (binding_free): ditto
* thread_sync.c (mutex_free): ditto
* vm.c (thread_free): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58006 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-17 19:59:56 +00:00
nobu 1c80c388d5 dir.c: getattrlist on OSX 10.5
* 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
2017-01-01 22:20:38 +00:00
nobu a44c3bb26f dir.c: merge rb_glob2 into rb_glob
* 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
2016-11-05 15:49:29 +00:00
nobu c72fc9f323 dir.c: suppress a warning
* dir.c (to_be_ignored): remove duplicate inline modifier, and
  suppress a warning by VC.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-31 16:01:30 +00:00
nobu 5d20d347c7 dir.c: retry glob with GC
* 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
2016-10-21 07:44:46 +00:00
nobu 9590e99031 dir.c: use rb_gc_for_fd
* 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
2016-10-21 07:40:50 +00:00