path: root/dir.c
AgeCommit message (Collapse)Author
2021-01-13Check stack overflow in recursive glob_helper [Bug #17162]Nobuyoshi Nakada
Notes: Merged:
2021-01-12Remove "." and ".." from Dir.glob with FNM_DOTMATCH [Bug #17280]Nobuyoshi Nakada
Co-authored-by: Jeremy Evans <> Notes: Merged:
2020-12-24dir.c: chdir conflict should raise only when called in different threadYusuke Endoh
... and keep it as a warning (like 2.7) when it is called in the same thread. [Bug #15661] Notes: Merged:
2020-12-02Revert "Removed deprecated Dir.exists? and File.exists?"Nobuyoshi Nakada
This reverts commit 1a5205536f0c0d6021450b11722919211847df86.
2020-12-02Removed deprecated Dir.exists? and File.exists?Nobuyoshi Nakada
2020-09-28Switch conflicting chdir warning to RuntimeErrorJeremy Evans
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] Notes: Merged:
2020-08-15RARRAY_AREF: convert into an inline function卜部昌平
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. Notes: Merged:
2020-06-29glob_opendir: move cleanup codes at the end卜部昌平
Nobu likes this arrangement. Notes: Merged:
2020-06-29glob_opendir: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged:
2020-06-29glob_make_pattern: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged:
2020-05-11sed -i 's|ruby/impl|ruby/internal|'卜部昌平
To fix build failures. Notes: Merged:
2020-05-11sed -i s|ruby/3|ruby/impl|g卜部昌平
This shall fix compile errors. Notes: Merged:
2020-05-11Added more NORETURN declarationsNobuyoshi Nakada
2020-04-08Merge pull request #2991 from shyouhei/ruby.h卜部昌平
Split ruby.h Notes: Merged-By: shyouhei <>
2020-04-07Show the deprecated name in the warningNobuyoshi Nakada
Fixed up a58bbd6a512d95ca010d8bebae4fe590400c1413.
2020-04-06[DOC] Removed RDoc of deprecated methods [ci skip]Nobuyoshi Nakada
2020-04-06Moved `Dir.[]` to dir.rbNobuyoshi Nakada
Notes: Merged:
2020-04-06Moved `Dir.glob` to dir.rbNobuyoshi Nakada
Notes: Merged:
2020-04-06Moved `` and `Dir#initialize` to dir.rbNobuyoshi Nakada
Notes: Merged:
2020-04-06Use `rb_warn_deprecated` for `File.exists?` and `Dir.exists?`Nobuyoshi Nakada
2020-03-25Fixed crash when argument array is modifiedNobuyoshi Nakada
2020-02-07more on NULL versus functions.卜部昌平
Function pointers are not void*. See also ce4ea956d24eab5089a143bba38126f2b11b55b6 8427fca49bd85205f5a8766292dd893f003c0e48
2020-01-20Fixed double closedirNobuyoshi Nakada
In the case that shinking the entries buffer to the exact size failed, `dirp` is already closed. Found by mame with Coverity Scan.
2020-01-19Sort globbed results by default [Feature #8709]Nobuyoshi Nakada
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. Notes: Merged:
2020-01-18Made glob option keyword IDs staticNobuyoshi Nakada
2019-12-29Fix documentation of Dir#each_childSeiei Miyagi
Notes: Merged:
2019-12-26decouple internal.h headers卜部昌平
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). Notes: Merged:
2019-12-04[DOC] Added File::FNM_SYSCASE example [Bug #16391] [ci skip]Nobuyoshi Nakada
2019-11-18Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans
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. Notes: Merged:
2019-11-18Warn on access/modify of $SAFE, and remove effects of modifying $SAFEJeremy Evans
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. Notes: Merged:
2019-10-13dir.c (join_path_from_pattern): check NULL from mallocYusuke Endoh
Coverity Scan points out that all the return values of GLOB_ALLOC_N are NULL-checked except this call.
2019-10-09avoid overflow in integer multiplication卜部昌平
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. Notes: Merged:
2019-10-01Fix for wrong fnmatch pattternNobuyoshi Nakada
* dir.c (file_s_fnmatch): ensure that pattern does not contain a NUL character.
2019-09-25Make rb_scan_args handle keywords more similar to Ruby methods (#2460)Jeremy Evans
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. Notes: Merged-By: jeremyevans <>
2019-09-02Prohibit nul-separated glob pattern [Feature #14643] (#2419)Nobuyoshi Nakada
Notes: Merged-By: nobu <>
2019-08-27rb_ensure now free from ANYARGS卜部昌平
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.
2019-07-15dir.c (dir_each_entry): remove unnecessary checkYusuke Endoh
I guess that this check was to detect re-entrance (maybe callcc?). But currently it does not work as intended.
2019-03-22[DOC] fix markups [ci skip]nobu
git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-21dir.c: fix Dir.glob starts with braceshirosaki
* dir.c (ruby_glob0): expand braces if a glob pattern starts with brace. [ruby-core:91728] [Bug #15649] git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-16dir.c: fix Dir.glob with braces and matching dirshirosaki
* 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:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-09Fix styles [ci skip]nobu
git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-05Prefer rb_check_arity when 0 or 1 argumentsnobu
git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-26fix "initialize miss".ko1
* dir.c (glob_helper): initialize `args.pathtype`. missed at r64810. git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-25dir.c: fix glob with recursive and braceshirosaki
Fixed bug that glob with recursive and braces (**/{a,b}) pattern fails. [Feature #13167] git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-25dir.c: fix memory leak of glob with bracesshirosaki
join_path uses malloc. So free is required. [Feature #13167] git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-22dir.c: performance fix with bracesshirosaki
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:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-21Suppress more -Wparentheses warningsnobu
[Fix GH-1958] git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-26dir.c: fix glob with base when no DT_UNKNOWNnobu
* 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:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-24Revert "dir.c: fix glob with base when no DT_UNKNOWN"naruse
This reverts commit r63982. It breaks build on Solaris 11. git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-17dir.c: fix glob with base when no DT_UNKNOWNnobu
* 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:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e