aboutsummaryrefslogtreecommitdiffstats
path: root/dir.c
Commit message (Collapse)AuthorAgeFilesLines
* Check stack overflow in recursive glob_helper [Bug #17162]Nobuyoshi Nakada2021-01-131-0/+2
|
* Remove "." and ".." from Dir.glob with FNM_DOTMATCH [Bug #17280]Nobuyoshi Nakada2021-01-121-2/+8
| | | | Co-authored-by: Jeremy Evans <code@jeremyevans.net>
* dir.c: chdir conflict should raise only when called in different threadYusuke Endoh2020-12-241-1/+3
| | | | | ... and keep it as a warning (like 2.7) when it is called in the same thread. [Bug #15661]
* Revert "Removed deprecated Dir.exists? and File.exists?"Nobuyoshi Nakada2020-12-021-0/+9
| | | | This reverts commit 1a5205536f0c0d6021450b11722919211847df86.
* Removed deprecated Dir.exists? and File.exists?Nobuyoshi Nakada2020-12-021-9/+0
|
* Switch conflicting chdir warning to RuntimeErrorJeremy Evans2020-09-281-2/+3
| | | | | | | | The documentation already stated this was an error in one case (when it was previously a warning). Describe the other case, where chdir without block is called inside block passed to chdir. Fixes [Bug #15661]
* RARRAY_AREF: convert into an inline function卜部昌平2020-08-151-0/+1
| | | | | | RARRAY_AREF has been a macro for reasons. We might not be able to change that for public APIs, but why not relax the situation internally to make it an inline function.
* glob_opendir: move cleanup codes at the end卜部昌平2020-06-291-5/+5
| | | | Nobu likes this arrangement.
* glob_opendir: do not goto into a branch卜部昌平2020-06-291-5/+8
| | | | | I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
* glob_make_pattern: do not goto into a branch卜部昌平2020-06-291-4/+6
| | | | | I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
* sed -i 's|ruby/impl|ruby/internal|'卜部昌平2020-05-111-1/+1
| | | | To fix build failures.
* sed -i s|ruby/3|ruby/impl|g卜部昌平2020-05-111-1/+1
| | | | This shall fix compile errors.
* Added more NORETURN declarationsNobuyoshi Nakada2020-05-111-1/+3
|
* Merge pull request #2991 from shyouhei/ruby.h卜部昌平2020-04-081-1/+1
| | | Split ruby.h
* Show the deprecated name in the warningNobuyoshi Nakada2020-04-071-1/+1
| | | | Fixed up a58bbd6a512d95ca010d8bebae4fe590400c1413.
* [DOC] Removed RDoc of deprecated methods [ci skip]Nobuyoshi Nakada2020-04-061-6/+1
|
* Moved `Dir.[]` to dir.rbNobuyoshi Nakada2020-04-061-39/+11
|
* Moved `Dir.glob` to dir.rbNobuyoshi Nakada2020-04-061-119/+27
|
* Moved `Dir.open` and `Dir#initialize` to dir.rbNobuyoshi Nakada2020-04-061-52/+14
|
* Use `rb_warn_deprecated` for `File.exists?` and `Dir.exists?`Nobuyoshi Nakada2020-04-061-1/+1
|
* Fixed crash when argument array is modifiedNobuyoshi Nakada2020-03-251-1/+1
|
* more on NULL versus functions.卜部昌平2020-02-071-2/+2
| | | | | | Function pointers are not void*. See also ce4ea956d24eab5089a143bba38126f2b11b55b6 8427fca49bd85205f5a8766292dd893f003c0e48
* Fixed double closedirNobuyoshi Nakada2020-01-201-2/+4
| | | | | | In the case that shinking the entries buffer to the exact size failed, `dirp` is already closed. Found by mame with Coverity Scan.
* Sort globbed results by default [Feature #8709]Nobuyoshi Nakada2020-01-191-27/+215
| | | | | | Sort the results which matched single wildcard or character set in binary ascending order, unless `sort: false` is given. The order of an Array of pattern strings and braces are not affected.
* Made glob option keyword IDs staticNobuyoshi Nakada2020-01-181-3/+5
|
* Fix documentation of Dir#each_childSeiei Miyagi2019-12-291-1/+1
|
* decouple internal.h headers卜部昌平2019-12-261-36/+44
| | | | | | | | | | | | | | | | | | Saves comitters' daily life by avoid #include-ing everything from internal.h to make each file do so instead. This would significantly speed up incremental builds. We take the following inclusion order in this changeset: 1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very first thing among everything). 2. RUBY_EXTCONF_H if any. 3. Standard C headers, sorted alphabetically. 4. Other system headers, maybe guarded by #ifdef 5. Everything else, sorted alphabetically. Exceptions are those win32-related headers, which tend not be self- containing (headers have inclusion order dependencies).
* [DOC] Added File::FNM_SYSCASE example [Bug #16391] [ci skip]Nobuyoshi Nakada2019-12-041-0/+1
|
* Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans2019-11-181-3/+1
| | | | | | 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.
* Warn on access/modify of $SAFE, and remove effects of modifying $SAFEJeremy Evans2019-11-181-1/+0
| | | | | | | | | | | | | | | | | 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.
* dir.c (join_path_from_pattern): check NULL from mallocYusuke Endoh2019-10-131-2/+4
| | | | | Coverity Scan points out that all the return values of GLOB_ALLOC_N are NULL-checked except this call.
* avoid overflow in integer multiplication卜部昌平2019-10-091-1/+13
| | | | | | | 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.
* Fix for wrong fnmatch pattternNobuyoshi Nakada2019-10-011-1/+1
| | | | | * dir.c (file_s_fnmatch): ensure that pattern does not contain a NUL character. https://hackerone.com/reports/449617
* Make rb_scan_args handle keywords more similar to Ruby methods (#2460)Jeremy Evans2019-09-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Prohibit nul-separated glob pattern [Feature #14643] (#2419)Nobuyoshi Nakada2019-09-021-24/+7
|
* rb_ensure now free from ANYARGS卜部昌平2019-08-271-2/+4
| | | | | | After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, 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 (dir_each_entry): remove unnecessary checkYusuke Endoh2019-07-151-1/+0
| | | | | I guess that this check was to detect re-entrance (maybe callcc?). But currently it does not work as intended.
* [DOC] fix markups [ci skip]nobu2019-03-221-27/+22
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c: fix Dir.glob starts with braceshirosaki2019-03-211-0/+29
| | | | | | | | * dir.c (ruby_glob0): expand braces if a glob pattern starts with brace. [ruby-core:91728] [Bug #15649] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67332 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c: fix Dir.glob with braces and matching dirshirosaki2019-01-161-0/+4
| | | | | | | | | | | * 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
* Fix styles [ci skip]nobu2019-01-091-1/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Prefer rb_check_arity when 0 or 1 argumentsnobu2018-12-051-3/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* fix "initialize miss".ko12018-09-261-0/+1
| | | | | | | | * dir.c (glob_helper): initialize `args.pathtype`. missed at r64810. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c: fix glob with recursive and braceshirosaki2018-09-251-17/+5
| | | | | | | | Fixed bug that glob with recursive and braces (**/{a,b}) pattern fails. [Feature #13167] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64836 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c: fix memory leak of glob with bracesshirosaki2018-09-251-5/+25
| | | | | | | join_path uses malloc. So free is required. [Feature #13167] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64835 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c: performance fix with bracesshirosaki2018-09-221-30/+138
| | | | | | | | | | | 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
* Suppress more -Wparentheses warningsnobu2018-09-211-1/+1
| | | | | | [Fix GH-1958] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64808 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c: fix glob with base when no DT_UNKNOWNnobu2018-07-261-16/+25
| | | | | | | | | | * 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
* Revert "dir.c: fix glob with base when no DT_UNKNOWN"naruse2018-07-241-7/+7
| | | | | | | 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: fix glob with base when no DT_UNKNOWNnobu2018-07-171-7/+7
| | | | | | | | | | * 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