This removes the related tests, and puts the related specs behind
version guards. This affects all code in lib, including some
libraries that may want to support older versions of Ruby.
This removes the security features added by $SAFE = 1, and warns for access
or modification of $SAFE from Ruby-level, as well as warning when calling
all public C functions related to $SAFE.
This modifies some internal functions that took a safe level argument
to no longer take the argument.
rb_require_safe now warns, rb_require_string has been added as a
version that takes a VALUE and does not warn.
One public C function that still takes a safe level argument and that
this doesn't warn for is rb_eval_cmd. We may want to consider
adding an alternative method that does not take a safe level argument,
and warn for rb_eval_cmd.
This changeset basically replaces `ruby_xmalloc(x * y)` into
`ruby_xmalloc2(x, y)`. Some convenient functions are also
provided for instance `rb_xmalloc_mul_add(x, y, z)` which allocates
x * y + z byes.
Cfuncs that use rb_scan_args with the : entry suffer similar keyword
argument separation issues that Ruby methods suffer if the cfuncs
accept optional or variable arguments.
This makes the following changes to : handling.
* Treats as **kw, prompting keyword argument separation warnings
if called with a positional hash.
* Do not look for an option hash if empty keywords are provided.
For backwards compatibility, treat an empty keyword splat as a empty
mandatory positional hash argument, but emit a a warning, as this
behavior will be removed in Ruby 3. The argument number check
needs to be moved lower so it can correctly handle an empty
positional argument being added.
* If the last argument is nil and it is necessary to treat it as an option
hash in order to make sure all arguments are processed, continue to
treat the last argument as the option hash. Emit a warning in this case,
as this behavior will be removed in Ruby 3.
* If splitting the keyword hash into two hashes, issue a warning, as we
will not be splitting hashes in Ruby 3.
* If the keyword argument is required to fill a mandatory positional
argument, continue to do so, but emit a warning as this behavior will
be going away in Ruby 3.
* If keyword arguments are provided and the last argument is not a hash,
that indicates something wrong. This can happen if a cfunc is calling
rb_scan_args multiple times, and providing arguments that were not
passed to it from Ruby. Callers need to switch to the new
rb_scan_args_kw function, which allows passing of whether keywords
were provided.
This commit fixes all warnings caused by the changes above.
It switches some function calls to *_kw versions with appropriate
kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS
is used. If creating new arguments, RB_PASS_KEYWORDS is used if
the last argument is a hash to be treated as keywords.
In open_key_args in io.c, use rb_scan_args_kw.
In this case, the arguments provided come from another C
function, not Ruby. The last argument may or may not be a hash,
so we can't set keyword argument mode. However, if it is a
hash, we don't want to warn when treating it as keywords.
In Ruby files, make sure to appropriately use keyword splats
or literal keywords when calling Cfuncs that now issue keyword
argument separation warnings through rb_scan_args. Also, make
sure not to pass nil in place of an option hash.
Work around Kernel#warn warnings due to problems in the Rubygems
override of the method. There is an open pull request to fix
these issues in Rubygems, but part of the Rubygems tests for
their override fail on ruby-head due to rb_scan_args not
recognizing empty keyword splats, which this commit fixes.
Implementation wise, adding rb_scan_args_kw is kind of a pain,
because rb_scan_args takes a variable number of arguments.
In order to not duplicate all the code, the function internals need
to be split into two functions taking a va_list, and to avoid passing
in a ton of arguments, a single struct argument is used to handle
the variables previously local to the function.
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct. This commit deletes ANYARGS from
rb_ensure, which also revealed many arity / type mismatches.
* dir.c (join_path_from_pattern): add the last slash for directory
matching.
* test/ruby/test_dir.rb (test_glob_recursive_directory): add a test
for above.
[ruby-core:91110] [Bug #15540]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66838 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Braces were expended before ruby_glob0(). This caused to call
replace_real_basename() for same plain patterns repeatedly.
Move blace expansion into glob_helper() in ruby_glob0() to reduce
replace_real_basename() call.
This fix changes the order of glob results.
[Feature #13167] [Fix GH-1864]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64810 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (do_stat, do_lstat, do_opendir): need the length of the base
path for fstatat() when fd is valid.
* dir.c (glob_helper): fix for platforms where DT_UNKNOWN is not
available, e.g. Solaris.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64067 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This reverts commit r63982.
It breaks build on Solaris 11.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64038 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (do_stat, do_lstat): need the length of the base path for
fstatat() when fd is valid.
* dir.c (glob_helper): fix for platforms where DT_UNKNOWN is not
available, e.g. Solaris.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63982 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (glob_helper): fix directory glob which resulted in lacking
the first byte. adjust the length of basename to be appended as
well as removing the heading path, not the length of the joined
path. [ruby-dev:50588] [Bug #14899]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63909 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
SuSE 10 has openat(), but not O_CLOEXEC
Reported-by: wangpeiwen
[ruby-core:87591] [Bug #14864]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63720 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (dir_s_glob): [DOC] added an example of Dir.glob using
pattern list. [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (rb_push_glob): do not assume string is NUL terminated
always, shared substring may not in the future.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63034 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (GlobPathValue): should be used in rb_push_glob only.
other methods should use FilePathValue.
https://hackerone.com/reports/302338
* dir.c (rb_push_glob): expand GlobPathValue
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62989 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Flags are 3rd argument of openat(2) while the 4th argument
(mode_t) is unnecessary for our uses. This bug exists since
Ruby 2.5 from r58860 and was discoverd by strace.
* dir.c (nogvl_opendir_at): use openat correctly
[Feature #13056] [Feature #14346]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61754 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
On further examination, Dir.chdir with a block from multiple
threads is thread-unsafe given our use of the chdir_blocking and
chdir_thread global variables.
This bug was only introduced in r60583 so not part of any stable
release.
Dir.chdir without a block can still make senses in a MT context
as only one thread could be cwd-sensitive and other threads do
not care which directory they're in.
* dir.c (dir_chdir): keep GVL here
(dir_s_chdir): release GVL if no block given
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61091 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Support nanosec file timestamp on Windows 8 or later.
Original patches are written by kubo (Kubo Takehiro).
Windows 7 and earlier also supports nanosec file timestamp, but it's too
accurate than system time. so, this feature is disabled on such versions.
[Feature #13726]
this change also includes [Misc #13702]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61013 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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
* 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
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
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
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
* 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
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
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
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