path: root/ext/pathname
AgeCommit message (Collapse)Author
9 days[ruby/pathname] Bump up pathname version to 0.2.0Hiroshi SHIBATA
2021-10-05ruby tool/update-deps --fix卜部昌平
Notes: Merged:
2021-08-31[Feature #16972] Add mode: option to Pathname#mkpathNobuyoshi Nakada
2021-08-30Faster Pathname FileUtils methodsschneems
Currently when calling any of the "FileUtils" methods on pathname `require` is called every time even though that library might already be loaded. This is slow: We can speed it up by either checking first if the constant is already defined, or by using autoload. Using defined speeds up the action by about 300x and using autoload is about twice as fast as that (600x faster than current require method). I'm proposing we use autoload: ```ruby require 'benchmark/ips' Benchmark.ips do |x| autoload(:FileUtils, "fileutils")"require") { require 'fileutils' }"defined") { require 'fileutils' unless defined?(FileUtils) }"autoload") { FileUtils }! end # Warming up -------------------------------------- # require 3.624k i/100ms # defined 1.465M i/100ms # autoload 2.320M i/100ms # Calculating ------------------------------------- # require 36.282k (± 2.4%) i/s - 184.824k in 5.097153s # defined 14.539M (± 2.0%) i/s - 73.260M in 5.041161s # autoload 23.100M (± 1.9%) i/s - 115.993M in 5.023271s # Comparison: # autoload: 23099779.2 i/s # defined: 14538544.9 i/s - 1.59x (± 0.00) slower # require: 36282.3 i/s - 636.67x (± 0.00) slower ``` Because this autoload is scoped to Pathname it will not change the behavior of existing programs that are not expecting FileUtils to be loaded yet: ``` ruby -rpathname -e "class Pathname; autoload(:FileUtils, 'fileutils'); end; puts FileUtils.exist?" Traceback (most recent call last): -e:1:in `<main>': uninitialized constant FileUtils (NameError) ``` Notes: Merged:
2021-04-27[ruby/pathname] gemspec: Explicitly list 0 executablesOlle Jonsson
This gem exposes no executables.
2021-04-13dependency updates卜部昌平
Notes: Merged:
2021-03-28[ruby/pathname] Fix segfault of Pathname#splitKenichi Kamiya
Fix segmentation fault of Pathname#split when File.split returns non array value [Bug #17755]
2021-01-29Forward keyword arguments for Pathname#each_line [Bug #17589]Nobuyoshi Nakada
Notes: Merged:
2020-12-20[pathname] Make Pathname Ractor safe (#3940)Kenta Murata
Notes: Merged-By: mrkn <>
2020-10-14Promote pathname to default gemsHiroshi SHIBATA
2020-09-14Optimize Pathname#relative? / absolute?Marc-Andre Lafortune
Notes: Merged:
2020-09-02Document limitation of Pathname#relative_path_from [ci skip]Jeremy Evans
This method is explicitly documented to not access the filesystem, and the only way to get the correct behavior for a case where the filesystem's case sensitivity differs from the operating system default would be to access the filesystem. Fixes [Bug #15417]
2020-08-27sed -i '/rmodule.h/d'卜部昌平
Notes: Merged:
2020-08-27sed -i '/r_cast.h/d'卜部昌平
Notes: Merged:
2020-08-27sed -i '\,2/extern.h,d'卜部昌平
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-04-08Merge pull request #2991 from shyouhei/ruby.h卜部昌平
Split ruby.h Notes: Merged-By: shyouhei <>
2020-03-02Add `#write` and `#binwrite` to IO section [ci skip]Kazuhiro NISHIYAMA
2020-02-25Fix wrong documentation for return value of Pathname#fnmatchMasataka Pocke Kuwabara
Notes: Merged:
2020-02-15Fix call-seq of Pathname#{,l}ch{mod,own} [ci skip]Kazuhiro NISHIYAMA
2020-02-04Add call-seq to Pathname#open from File.openKazuhiro NISHIYAMA
before: ``` open(p1 = v1, p2 = v2, p3 = v3) ```
2020-01-23Revert pathname, rb_warn_deprecated* are not public APINobuyoshi Nakada
2020-01-23Added rb_warn_deprecated_to_removeNobuyoshi Nakada
Warn the deprecation and future removal, with obeying the warning flag.
2020-01-22Make taint warnings non-verbose instead of verboseJeremy Evans
Notes: Merged:
2019-12-17Remove unnecessary double bangs from Pathname#root?Masataka Pocke Kuwabara
Notes: Merged:
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-09-26Fix more keyword argument separation issues in PathnameJeremy Evans
Notes: Merged:
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-21Make Kernel#{Pathname,BigDecimal,Complex} return argument if given correct typeJeremy Evans
This is how Kernel#{Array,String,Float,Integer,Hash,Rational} work. BigDecimal and Complex instances are always frozen, so this should not cause backwards compatibility issues for those. Pathname instances are not frozen, so potentially this could cause backwards compatibility issues by not returning a new object. Based on a patch from Joshua Ballanco, some minor changes by me. Fixes [Bug #7522] Notes: Merged:
2019-07-14Include ruby/assert.h in ruby/ruby.h so that assertions can be thereNobuyoshi Nakada
2019-07-14Delegates 3 arguments for Pathname.glob.Tanaka Akira
Thanks for the patch by pocke (Masataka Kuwabara) [Feature #14405].
2019-02-20Try statx syscallnobu
* file.c (rb_file_s_birthtime): export for pathname to check if birthtime is supported. git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-08Removed moving toplevel header since r12501nobu
Moving public headers was 12-years ago, no depend files would expect ruby.h in the top source directory now. git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-18Pathname#relative_path_from uses is_a?akr
I reconsidered because simpler code would have better maintainablity. git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-16Pathname#relative_path_from compatible with mock.akr
[Fix GH-2049] git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-12Use File class methods to avoid pipe executionakr
Following methods use corresponding File class methods instead of IO class methods. - Pathname#each_line - Pathname#read - Pathname#binread - Pathname#write - Pathname#binwrite - Pathname#readlines Reported by ooooooo_q. git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-13Pathname: Have #relative_path_from accept String argument.marcandre
[Fix GH-1975] git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-10Pathname: Simplified Pathname#mountpoint?nobu
Removed unnecessary comparison in mountpoint? [Fix GH-1927] From: John Whitson <> git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-13Improve Pathname performancewatson1978
If it will not use special variables (like $1, $&, $`...), it can improve the performance by using Regexp#match? instead of Regexp#=~. Because Regexp#=~ will generate the objects to special variables by pattern matching. This patch will replace Regexp#=~ without special variables to Regexp#match?. (Excludes [Fix GH-1836] [ruby-core:86093] [Bug #14599] ## Environment * OS : Ubuntu 17.10 * Compiler : gcc version 7.2.0 * CPU : Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz * Memory : 16 GB ## TL;DR   | Before | After | Speed up --------------------------- | ------ | ------ | -------- Pathname#absolute? | 142836 | 198487 | 39.0% Pathname#cleanpath | 60706 | 79415 | 30.8% Pathname#root? | 603806 | 759157 | 25.7% Pathname#absolute? | 142592 | 197859 | 38.8% Pathname#each_filename | 115600 | 152982 | 32.3% Pathname#ascend | 50494 | 63606 | 26.0% Pathname#+ | 100550 | 130372 | 29.7% Pathname#join | 46673 | 60994 | 30.7% Pathname#relative_path_from | 28362 | 37494 | 32.2% ## Before ``` Calculating ------------------------------------- Pathname#absolute? 142.836k (± 0.1%) i/s - 722.304k in 5.056884s Pathname#cleanpath 60.706k (± 0.1%) i/s - 306.764k in 5.053305s Pathname#root? 603.806k (± 0.3%) i/s - 3.062M in 5.071696s Pathname#absolute? 142.592k (± 0.1%) i/s - 720.846k in 5.055301s Pathname#each_filename 115.600k (± 0.1%) i/s - 586.818k in 5.076292s Pathname#ascend 50.494k (± 0.1%) i/s - 255.301k in 5.056049s Pathname#+ 100.550k (± 0.1%) i/s - 509.630k in 5.068433s Pathname#join 46.673k (± 0.1%) i/s - 236.433k in 5.065696s Pathname#relative_path_from 28.362k (± 0.0%) i/s - 143.728k in 5.067640s ``` ## After ``` Calculating ------------------------------------- Pathname#absolute? 198.487k (± 0.1%) i/s - 995.665k in 5.016272s Pathname#cleanpath 79.415k (± 0.1%) i/s - 404.406k in 5.092344s Pathname#root? 759.157k (± 0.0%) i/s - 3.800M in 5.005072s Pathname#absolute? 197.859k (± 0.1%) i/s - 995.720k in 5.032494s Pathname#each_filename 152.982k (± 0.1%) i/s - 775.555k in 5.069607s Pathname#ascend 63.606k (± 0.0%) i/s - 320.862k in 5.044560s Pathname#+ 130.372k (± 0.1%) i/s - 660.856k in 5.068991s Pathname#join 60.994k (± 0.1%) i/s - 305.068k in 5.001626s Pathname#relative_path_from 37.494k (± 0.4%) i/s - 189.124k in 5.044146s ``` ## Benchmark code ```ruby require 'pathname' require 'benchmark/ips' Benchmark.ips do |x| root ='/') path1 ='/path/to/some/file1.rb') path2 ='/path/to/some/file2.rb')"Pathname#absolute?") do path1.absolute? end"Pathname#cleanpath") do'/path/to/some/file.rb').cleanpath end"Pathname#root?") do path1.root? end"Pathname#absolute?") do path1.absolute? end"Pathname#each_filename") do path1.each_filename { |file| } end"Pathname#ascend") do path1.ascend { |path| } end"Pathname#+") do path1 + path2 end"Pathname#join") do path1.join("../file3.rb") end"Pathname#relative_path_from") do path1.relative_path_from(root) end end ``` git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-07pathname.c: improve docs for Pathnamestomar
* ext/pathname/pathname.c: [DOC] improve example for Pathname.glob, by using a more common glob pattern, and improve the reference to the `base' keyword argument for Pathname#glob. git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-01Pathname: get rid of a -Wcomment warning [DOC]nobu
git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-31Pathname: Simplify example [DOC] [ci-skip]marcandre
git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21declare variables once for each line in pathname.c.akr
This ease adding/deleting variables. git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21Pathname#glob method implemented.akr
[ruby-core:49373] [Feature #7360] proposed by Alexander E. Fischer. git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-03disable rdoc for internal constants [ci skip]nobu
git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-03extract IDsnobu
git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-16pathname.rb: UNC root pathname needs a separatornobu
* ext/pathname/lib/pathname.rb (Pathname#plus): UNC root pathname needs a separator. File.basename returns "/" on UNC root, as well as sole drive letter, even if it does not end with a separator. [ruby-core:80900] [Bug #13515] git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-22ruby tool/update-deps --fixshyouhei
Onigumo 6 (r57045) introduced new onigumo.h header file, which is required from quite much everywhere. This commit adds necessary dependencies. Note: ruby/oniguruma.h now includes onigumo.h, ruby/io.h includes oniguruma.h, ruby/encoding.h also includes oniguruma.h, and internal.h includes encoding.h. git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05Pathname#empty? implemented.akr
* ext/pathname/pathname.c (Pathname#empty?): New method. [ruby-core:76404] [Feature#12596] Proposed by John Backus. git-svn-id: svn+ssh:// b2dd03c8-39d4-4d8f-98ff-823fe69b080e