summaryrefslogtreecommitdiff
path: root/file.c
Commit message (Collapse)AuthorAgeFilesLines
* Should not reach end of non-void functionNobuyoshi Nakada2023-03-221-6/+2
|
* Fix the macro for conditionNobuyoshi Nakada2023-03-201-1/+1
|
* Revert "reuse open(2) from rb_file_load_ok on POSIX-like system"Takashi Kokubun2023-02-271-31/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 35136e1e9c232ad7a03407b992b2e86b6df43f63. test-spec has been failing since this revision. .github/workflows/compilers.yml:82 https://github.com/ruby/ruby/actions/runs/4276884159/jobs/7445299562 ``` env: # Minimal flags to pass the check. default_cc: 'gcc-11 -fcf-protection -Wa,--generate-missing-build-notes=yes' optflags: '-O2' LDFLAGS: '-Wl,-z,now' # FIXME: Drop skipping options # https://bugs.ruby-lang.org/issues/18061 # https://sourceware.org/annobin/annobin.html/Test-pie.html TEST_ANNOCHECK_OPTS: "--skip-pie --skip-gaps" ``` Failure: ``` 1) An exception occurred during: Kernel#require (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded /__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:317 Kernel#require (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded ERROR LeakError: Leaked file descriptor: 8 : #<File:/__w/ruby/ruby/src/spec/ruby/fixtures/code/load_fixture.ext.rb> /__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:5:in `<top (required)>' 2) An exception occurred during: Kernel#require ($LOADED_FEATURES) stores an absolute path /__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:330 Kernel#require ($LOADED_FEATURES) stores an absolute path ERROR LeakError: Closed file descriptor: 8 /__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:5:in `<top (required)>' 3) An exception occurred during: Kernel#require ($LOADED_FEATURES) does not load a non-canonical path for a file already loaded /__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:535 Kernel#require ($LOADED_FEATURES) does not load a non-canonical path for a file already loaded ERROR LeakError: Leaked file descriptor: 8 : #<File:/__w/ruby/ruby/src/spec/ruby/fixtures/code/load_fixture.rb> /__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:5:in `<top (required)>' 4) An exception occurred during: Kernel#require ($LOADED_FEATURES) does not load a ../ relative path for a file already loaded /__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:551 Kernel#require ($LOADED_FEATURES) does not load a ../ relative path for a file already loaded ERROR LeakError: Leaked file descriptor: 9 : #<File:../code/load_fixture.rb> /__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:5:in `<top (required)>' 5) An exception occurred during: Kernel#require ($LOADED_FEATURES) complex, enumerator, rational, thread, ruby2_keywords are already required /__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:563 Kernel#require ($LOADED_FEATURES) complex, enumerator, rational, thread, ruby2_keywords are already required ERROR LeakError: Closed file descriptor: 8 Closed file descriptor: 9 /__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:5:in `<top (required)>' 6) An exception occurred during: Kernel.require (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded /__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:317 Kernel.require (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded ERROR LeakError: Leaked file descriptor: 8 : #<File:/__w/ruby/ruby/src/spec/ruby/fixtures/code/load_fixture.ext.rb> /__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:23:in `<top (required)>' 7) An exception occurred during: Kernel.require ($LOADED_FEATURES) stores an absolute path /__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:330 Kernel.require ($LOADED_FEATURES) stores an absolute path ERROR LeakError: Closed file descriptor: 8 /__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:23:in `<top (required)>' 8) An exception occurred during: Kernel.require ($LOADED_FEATURES) does not load a non-canonical path for a file already loaded /__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:535 Kernel.require ($LOADED_FEATURES) does not load a non-canonical path for a file already loaded ERROR LeakError: Leaked file descriptor: 8 : #<File:/__w/ruby/ruby/src/spec/ruby/fixtures/code/load_fixture.rb> /__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:23:in `<top (required)>' 9) An exception occurred during: Kernel.require ($LOADED_FEATURES) does not load a ../ relative path for a file already loaded /__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:551 Kernel.require ($LOADED_FEATURES) does not load a ../ relative path for a file already loaded ERROR LeakError: Leaked file descriptor: 9 : #<File:../code/load_fixture.rb> /__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:23:in `<top (required)>' 10) An exception occurred during: Kernel.require ($LOADED_FEATURES) complex, enumerator, rational, thread, ruby2_keywords are already required /__w/ruby/ruby/src/spec/ruby/core/kernel/shared/require.rb:563 Kernel.require ($LOADED_FEATURES) complex, enumerator, rational, thread, ruby2_keywords are already required ERROR LeakError: Closed file descriptor: 8 Closed file descriptor: 9 /__w/ruby/ruby/src/spec/ruby/core/kernel/require_spec.rb:23:in `<top (required)>' 11) An exception occurred during: Kernel#require_relative with a relative path (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded /__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:197 Kernel#require_relative with a relative path (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded ERROR LeakError: Leaked file descriptor: 8 : #<File:/__w/ruby/ruby/src/spec/ruby/fixtures/code/load_fixture.ext.rb> /__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:4:in `<top (required)>' 12) An exception occurred during: Kernel#require_relative with a relative path ($LOADED_FEATURES) stores an absolute path /__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:205 Kernel#require_relative with a relative path ($LOADED_FEATURES) stores an absolute path ERROR LeakError: Closed file descriptor: 8 /__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:4:in `<top (required)>' 13) An exception occurred during: Kernel#require_relative with an absolute path (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded /__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:399 Kernel#require_relative with an absolute path (file extensions) does not load a C-extension file if a complex-extensioned .rb file is already loaded ERROR LeakError: Leaked file descriptor: 8 : #<File:/__w/ruby/ruby/src/spec/ruby/fixtures/code/load_fixture.ext.rb> /__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:277:in `<top (required)>' 14) An exception occurred during: Kernel#require_relative with an absolute path ($LOAD_FEATURES) stores an absolute path /__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:407 Kernel#require_relative with an absolute path ($LOAD_FEATURES) stores an absolute path ERROR LeakError: Closed file descriptor: 8 /__w/ruby/ruby/src/spec/ruby/core/kernel/require_relative_spec.rb:277:in `<top (required)>' ```
* reuse open(2) from rb_file_load_ok on POSIX-like systemEric Wong2023-02-261-7/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When loading Ruby source files, we can save the result of successful opens as open(2)/openat(2) are a fairly expensive syscalls. This also avoids a time-of-check-to-time-of-use (TOCTTOU) problem. This reduces open(2) syscalls during `require'; but should be most apparent when users have a small $LOAD_PATH. Users with large $LOAD_PATH will benefit less since there'll be more open(2) failures due to ENOENT. With `strace -c -e openat ruby -e exit' under Linux, this results in a ~14% reduction of openat(2) syscalls (glibc uses openat(2) to implement open(2)). % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 0.00 0.000000 0 296 110 openat 0.00 0.000000 0 254 110 openat Additionally, the introduction of `struct ruby_file_load_state' may make future optimizations more apparent. This change cannot benefit binary (.so) loading since the dlopen(3) API requires a filename and I'm not aware of an alternative that takes a pre-existing FD. In typical situations, Ruby source files outnumber the mount of .so files.
* file.c: rb_file_load_ok: GC+retry on EMFILE/ENFILE/ENOMEMEric Wong2023-02-151-1/+5
| | | | | `require' should make a best effort to avoid failure on recoverable resource exhaustion errors.
* Enable write barriers on File::StatJean Boussier2023-02-031-1/+1
| | | | It holds no reference, so no changes needed.
* * expand tabs. [ci skip]git2023-01-301-1/+1
| | | | Please consider using misc/expand_tabs.rb as a pre-commit hook.
* file.c: add some endif labels where appropriateEric Wong2023-01-301-58/+60
| | | | | | | | | | | | | | "Appropriate" for me being ifdefs which: 1) span enough lines to be hard-to-follow (I need big fonts to see) 2) nested within other ifdefs, or within large functions (I have a short attention span) rb_file_expand_path_internal is the prime example of a large function I struggle to understand due to the amount of platform-specific ifdefs. Hopefully this helps others with poor vision and/or short attention spans.
* [DOC] Fix false link to ::DataAlan Wu2022-12-091-1/+1
|
* Introduce `IO.new(..., path:)` and promote `File#path` to `IO#path`. (#6867)Samuel Williams2022-12-081-37/+0
|
* Fix typos (#6775)Yudai Takada2022-11-201-1/+1
| | | | | | | | | | | * s/Innteger/Integer/ * s/diretory/directory/ * s/Bufer/Buffer/ * s/defalt/default/ * s/covearge/coverage/
* Add support for `sockaddr_un` on Windows. (#6513)Samuel Williams2022-11-171-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Windows: Fix warning about undefined if_indextoname() * Windows: Fix UNIXSocket on MINGW and make .pair more reliable * Windows: Use nonblock=true for read tests with scheduler * Windows: Move socket detection from File.socket? to File.stat Add S_IFSOCK to Windows and interpret reparse points accordingly. Enable tests that work now. * Windows: Use wide-char functions to UNIXSocket This fixes behaviour with non-ASCII characters. It also fixes deletion of temporary UNIXSocket.pair files. * Windows: Add UNIXSocket tests for specifics of Windows impl. * Windows: fix VC build due to missing _snwprintf Avoid usage of _snwprintf, since it fails linking ruby.dll like so: linking shared-library x64-vcruntime140-ruby320.dll x64-vcruntime140-ruby320.def : error LNK2001: unresolved external symbol snwprintf x64-vcruntime140-ruby320.def : error LNK2001: unresolved external symbol vsnwprintf_l whereas linking miniruby.exe succeeds. This patch uses snprintf on the UTF-8 string instead. Also remove branch GetWindowsDirectoryW, since it doesn't work. * Windows: Fix dangling symlink test failures Co-authored-by: Lars Kanis <kanis@comcard.de>
* Windows: Readlink improvements (#6745)Lars Kanis2022-11-171-2/+2
| | | | | | | | | | | | | | | | | | | * Windows: Use readlink emulation for File.readlink This fixes readlink emulation for the ERROR_MORE_DATA case and general error reporting. It now releases GVL while readlink IO operation. The dedicated rb_readlink was introduced in commit 2ffb87995a33cdc7ba609a4b867f03f18da0c3b3 in order to improve encoding and buffer allocation. However the encoding issues are solved since ruby-3.0 switched to UTF-8 and the buffer allocation will be improved in a later commit. * Windows: Increase the default buffer size for reparse point info So far nearly all queries of reparse points needed two attempts to get enough buffer. * Windows: Remove declaration of rb_w32_wreadlink It was removed in commit 2f6fdd3aebdee2ce04d003b206f6da78120e8235
* [DOC] Enhanced RDoc for IO (#6669)Burdette Lamar2022-11-091-1/+1
|
* [DOC] More about line number (#6582)Burdette Lamar2022-10-191-3/+3
|
* [DOC] Remove unknown markup or macro [ci skip]Nobuyoshi Nakada2022-10-051-4/+3
| | | | Also remove the ancient word "Windows NT".
* Remove an unused macro [ci skip]Nobuyoshi Nakada2022-10-031-4/+0
|
* [Bug #19034] No runtime check for `utimensat` if unavailableNobuyoshi Nakada2022-10-031-1/+3
|
* [DOC] RDoc changes for IO (#6458)Burdette Lamar2022-10-021-1/+1
| | | | | | Moves Expect library doc into io.c. Changes certain links to local sections, now pointing to sections in doc/io_streams.rdoc. Removes local sections now superseded by sections in doc/io_streams.rdoc.
* Initialize Objective-C classes before fork() for macOS 13Yuta Saito2022-09-261-0/+44
| | | | | | | | | | | | | | | | Since macOS 13, CFString family API used in `rb_str_append_normalized_ospath` may internally use Objective-C classes (`NSTaggedPointerString` and `NSPlaceholderMutableString`) for small strings. On the other hand, Objective-C classes should not be used for the first time in a `fork()`'ed but not `exec()`'ed process. Violations for this rule can result deadlock during class initialization, so Objective-C runtime conservatively crashes on such cases by default. Therefore, we need to use CFString API to initialize Objective-C classes used internally *before* `fork()`. For more details, see https://bugs.ruby-lang.org/issues/18912
* New page IO Streams (#6383)Burdette Lamar2022-09-211-28/+596
| | | This page provides an overview of IO streams. It's meant to be linked to from many other doc spots. In particular it will be linked to from many places in ARGF, File, IO, and StringIO.
* avoid ANYARGS卜部昌平2022-09-211-6/+4
| | | | | Use macro instead of a static functon. This isn't very amusing but doing this wihtout a macro (is possibe but) seems just too much.
* Using is_broken_string functionS-H-GAMELINKS2022-09-101-2/+2
|
* [Bug #5317] Use `rb_off_t` instead of `off_t`Nobuyoshi Nakada2022-09-081-4/+4
| | | | Get rid of the conflict with system-provided small `off_t`.
* [Win32] Remove dead code using `chsize`Nobuyoshi Nakada2022-09-081-40/+4
| | | | | Already using `rb_w32_truncate` and `rb_w32_ftruncate`, and `HAVE_FTRUNCATE` has been added 14 years ago.
* Remove extra semicolons at the top level [ci skip]Nobuyoshi Nakada2022-09-051-3/+3
|
* Fixed by [Bug #18964]Nobuyoshi Nakada2022-08-191-3/+0
|
* rb_str_resize: Only clear coderange on truncationJean Boussier2022-08-181-0/+3
| | | | | If we are expanding the string or only stripping extra capacity then coderange won't change, so clearing it is wasteful.
* Expand tabs [ci skip]Takashi Kokubun2022-07-211-1068/+1068
| | | | [Misc #18891]
* Rename ENCINDEX_ASCII to ENCINDEX_ASCII_8BITJean Boussier2022-07-191-5/+5
| | | | Otherwise it's way too easy to confuse it with US_ASCII.
* Remove no longer used label [ci skip]Nobuyoshi Nakada2022-06-291-3/+0
|
* Check availability of `utimensat` on macOSNobuyoshi Nakada2022-06-271-9/+42
|
* Using is_ascii_string to check encodingS-H-GAMELINKS2022-06-171-1/+1
|
* Fix missing paren [ci skip]Kazuhiro NISHIYAMA2022-05-061-2/+2
|
* File rdoc (#5888)Burdette Lamar2022-05-051-14/+29
| | | | | | | | | Treats: ::pipe? ::symlink? ::socket? ::blockdev? ::chardev?
* Enhanced RDoc for File (#5849)Burdette Lamar2022-04-261-35/+67
| | | | | | | | | | | Treats: #path ::stat ::lstat #lstat ::directory? Also adds section "Example Files" that explains assumptions about example files. I'm using t.txt already, and I'm pretty sure I'll need t.dat (binary data). I don't know whether I'll need t.rus (Russian text).
* [DOC] Use consistent terms [Bug #18680]Nobuyoshi Nakada2022-04-181-3/+3
|
* Return `false` where sticky-bit is not provided [Bug #18734]Nobuyoshi Nakada2022-04-151-1/+1
|
* Use an empty string when building File.expand_pathPeter Zhu2022-04-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Allocating a string of length MAXPATHLEN and then shrinking the string is inefficient when the resulting path is short. Preallocating a large string is also a problem for Variable Width Allocation since we can't easily downsize the capacity. I ran the following benchmark: ```ruby Benchmark.ips do |x| { "empty" => "", "short" => "a/" * 10, "medium" => "a/" * 100, "long" => "a/" * 500 }.each do |name, path| x.report(name) do |times| i = 0 while i < times File.expand_path(path) i += 1 end end end end ``` On this commit: ``` empty 97.486k (± 0.7%) i/s - 492.915k in 5.056507s short 96.026k (± 2.4%) i/s - 486.489k in 5.068966s medium 86.304k (± 1.3%) i/s - 435.336k in 5.045112s long 59.395k (± 1.7%) i/s - 302.175k in 5.089026s ``` On master: ``` empty 94.138k (± 1.4%) i/s - 472.158k in 5.016590s short 92.043k (± 1.4%) i/s - 468.180k in 5.087496s medium 84.910k (± 2.3%) i/s - 425.750k in 5.017007s long 61.503k (± 2.7%) i/s - 309.723k in 5.039429s ```
* Fix formatting of What's Here for File (#5717)Burdette Lamar2022-03-251-93/+93
|
* [DOC] Replace with IO@ModesPeter Zhu2022-02-071-1/+1
|
* [DOC] Use RDoc link style for links in the same class/modulePeter Zhu2022-02-071-4/+4
| | | | | | | | | | I used this regex: (?<=\[)#(?:class|module)-([A-Za-z]+)-label-([A-Za-z0-9\-\+]+) And performed a global find & replace for this: rdoc-ref:$1@$2
* [DOC] Use RDoc link style for links to other classes/modulesPeter Zhu2022-02-071-2/+2
| | | | | | | | | | I used this regex: ([A-Za-z]+)\.html#(?:class|module)-[A-Za-z]+-label-([A-Za-z0-9\-\+]+) And performed a global find & replace for this: rdoc-ref:$1@$2
* [DOC] Fix links in documentation for File and IOPeter Zhu2022-02-071-1/+1
| | | | Fixes some typos and dead links.
* File rdoc (#5438)Burdette Lamar2022-01-131-28/+59
| | | | | | | | Treats: File introduction File.open File.new
* Removed deprecated Dir.exists? and File.exists?Nobuyoshi Nakada2021-12-281-18/+0
|
* Adjust styles [ci skip]Nobuyoshi Nakada2021-12-241-1/+2
|
* Improved exception usage/classes.Samuel Williams2021-12-211-10/+14
|
* size_t is not for file sizeNobuyoshi Nakada2021-11-101-2/+3
|
* IO::Buffer for scheduler interface.Samuel Williams2021-11-101-7/+14
|