summaryrefslogtreecommitdiff
path: root/ext/pathname
AgeCommit message (Collapse)Author
2020-10-14Promote pathname to default gemsHiroshi SHIBATA
2020-09-14Optimize Pathname#relative? / absolute?Marc-Andre Lafortune
Notes: Merged: https://github.com/ruby/ruby/pull/2107
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: https://github.com/ruby/ruby/pull/3347
2020-08-27sed -i '/r_cast.h/d'卜部昌平
Notes: Merged: https://github.com/ruby/ruby/pull/3346
2020-08-27sed -i '\,2/extern.h,d'卜部昌平
Notes: Merged: https://github.com/ruby/ruby/pull/3338
2020-05-11sed -i 's|ruby/impl|ruby/internal|'卜部昌平
To fix build failures. Notes: Merged: https://github.com/ruby/ruby/pull/3079
2020-05-11sed -i s|ruby/3|ruby/impl|g卜部昌平
This shall fix compile errors. Notes: Merged: https://github.com/ruby/ruby/pull/3079
2020-04-08Merge pull request #2991 from shyouhei/ruby.h卜部昌平
Split ruby.h Notes: Merged-By: shyouhei <shyouhei@ruby-lang.org>
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: https://github.com/ruby/ruby/pull/2923
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: https://github.com/ruby/ruby/pull/2856
2019-12-17Remove unnecessary double bangs from Pathname#root?Masataka Pocke Kuwabara
Notes: Merged: https://github.com/ruby/ruby/pull/2732
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: https://github.com/ruby/ruby/pull/2476
2019-09-26Fix more keyword argument separation issues in PathnameJeremy Evans
Notes: Merged: https://github.com/ruby/ruby/pull/2484
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 <code@jeremyevans.net>
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: https://github.com/ruby/ruby/pull/2473
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://ci.ruby-lang.org/ruby/trunk@67097 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://ci.ruby-lang.org/ruby/trunk@67033 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://ci.ruby-lang.org/ruby/trunk@66431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-16Pathname#relative_path_from compatible with mock.akr
[Fix GH-2049] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66416 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://ci.ruby-lang.org/ruby/trunk@66346 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-13Pathname: Have #relative_path_from accept String argument.marcandre
[Fix GH-1975] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65706 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-10Pathname: Simplified Pathname#mountpoint?nobu
Removed unnecessary comparison in mountpoint? [Fix GH-1927] From: John Whitson <john.whitson@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64273 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 https://github.com/ruby/ruby/blob/trunk/ext/pathname/lib/pathname.rb#L144-L153) [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 = Pathname.new('/') path1 = Pathname.new('/path/to/some/file1.rb') path2 = Pathname.new('/path/to/some/file2.rb') x.report("Pathname#absolute?") do path1.absolute? end x.report("Pathname#cleanpath") do Pathname.new('/path/to/some/file.rb').cleanpath end x.report("Pathname#root?") do path1.root? end x.report("Pathname#absolute?") do path1.absolute? end x.report("Pathname#each_filename") do path1.each_filename { |file| } end x.report("Pathname#ascend") do path1.ascend { |path| } end x.report("Pathname#+") do path1 + path2 end x.report("Pathname#join") do path1.join("../file3.rb") end x.report("Pathname#relative_path_from") do path1.relative_path_from(root) end end ``` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62740 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://ci.ruby-lang.org/ruby/trunk@60711 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-01Pathname: get rid of a -Wcomment warning [DOC]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60600 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-31Pathname: Simplify example [DOC] [ci-skip]marcandre
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60594 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://ci.ruby-lang.org/ruby/trunk@60241 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://ci.ruby-lang.org/ruby/trunk@60238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-03disable rdoc for internal constants [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59484 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-03extract IDsnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59482 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://ci.ruby-lang.org/ruby/trunk@59102 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://ci.ruby-lang.org/ruby/trunk@58054 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://ci.ruby-lang.org/ruby/trunk@56571 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-04pathname.c: unnormalized Fixnum valuenobu
* ext/pathname/pathname.c (path_hash): fix unnormalized Fixnum value bug on mingw/mswin. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56553 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-29rb_funcallvnobu
* *.c: rename rb_funcall2 to rb_funcallv, except for extensions which are/will be/may be gems. [Fix GH-1406] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55773 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-06Update dependenciesnobu
* common.mk (compile.o, loadpath.o): update dependencies. * common.mk (vm_call.o): remove stale object dependencies. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55589 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-16handle ext/ as r53141naruse
g -L frozen_string_literal ext/**/*.rb|xargs ruby -Ka -e'ARGV.each{|fn|puts fn;open(fn,"r+"){|f|s=f.read.sub(/\A(#!.*\n)?(#.*coding.*\n)?/,"\\&# frozen_string_literal: false\n");f.rewind;f.write s}}' git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53143 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-10* lib/open-uri.rb: Remove indicator for "frozen_string_literal: true".akr
* lib/pp.rb: Ditto. * lib/prettyprint.rb: Ditto. * lib/resolv.rb: Ditto. * lib/securerandom.rb: Ditto. * lib/tmpdir.rb: Ditto. * lib/unicode_normalize/tables.rb: Ditto. * test/net/ftp/test_buffered_socket.rb: Ditto. * test/net/ftp/test_mlsx_entry.rb: Ditto. * test/open-uri/test_open-uri.rb: Ditto. * test/open-uri/test_ssl.rb: Ditto. * test/pathname/test_pathname.rb: Ditto. * test/test_pp.rb: Ditto. * test/test_prettyprint.rb: Ditto. * tool/transcode-tblgen.rb: Ditto. * ext/pathname/lib/pathname.rb: Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52526 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-05Put an line before "frozen_string_literal: true" for emacs.akr
https://bugs.ruby-lang.org/issues/8976#note-49 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52052 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-04* ext/pathname/lib/pathname.rb: freeze string literals forakr
reduced object allocation. patch by schneems. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52023 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-14* ext/pathname/lib/pathname.rb (descend): Blockless form supported.akr
(ascend): Ditto. [ruby-core:68820] [Feature #11052] Patch by Piotr Szotkowski. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-14* ext/pathname/lib/pathname.rb: Remove condition of RUBY_VERSION <= 1.9.hsbt
[Feature #11082] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50490 b2dd03c8-39d4-4d8f-98ff-823fe69b080e