aboutsummaryrefslogtreecommitdiffstats
path: root/file.c
Commit message (Collapse)AuthorAgeFilesLines
* [DOC] Fixed document positionNobuyoshi Nakada2023-12-061-11/+11
| | | | | | Method documentation must be placed immediately before each implementation, without any other functions or preprocessor directives.
* Embed File::Stat objectsJean Boussier2023-11-221-40/+35
| | | | They are very short lived and fit in a 160B slot.
* Fix File.directory? doc hidding File::Stat#directory? docDana Sherson2023-11-171-2/+0
| | | | Now the documentation that was already in the codebase for `File::Stat#directory?` shows up.
* [DOC] Missing comment markersNobuyoshi Nakada2023-09-271-1/+1
|
* [DOC] Correction for doc guide + TOC fix in File (#8505)Burdette Lamar2023-09-241-1/+1
|
* [DOC] Link fix (#8340)Burdette Lamar2023-08-311-1/+1
|
* Introduce `at_char_boundary` functionNobuyoshi Nakada2023-08-261-1/+1
|
* [DOC] Don't suppress autolinksBurdetteLamar2023-08-121-11/+11
|
* [rubygems/rubygems] Bundler: Update bundle-outdated(1) manKentaro Takeyama2023-07-241-1/+1
| | | | | | Updated output examples to current format since the output format has changed since version 2.2.0.dev https://github.com/rubygems/rubygems/commit/48d98f906a
* [DOC] RDoc for File::Constants (#8103)Burdette Lamar2023-07-231-31/+311
|
* Use `File::NULL` instead of hard coded null device namesNobuyoshi Nakada2023-07-101-2/+2
|
* [DOC] Fixes for link fragments (#7981)Burdette Lamar2023-06-281-2/+1
|
* Hide the usage of `rb_io_t` where possible. (#7880)Samuel Williams2023-06-011-1/+0
| | | This retries the compatible parts of the previously reverted PR so we can continue to update related code without breaking backwards compatibility.
* Revert "Hide most of the implementation of `struct rb_io`. (#6511)"NARUSE, Yui2023-06-011-0/+1
| | | | | | | | | This reverts commit 18e55fc1e1ec20e8f3166e3059e76c885fc9f8f2. fix [Bug #19704] https://bugs.ruby-lang.org/issues/19704 This breaks compatibility for extension libraries. Such changes need a discussion.
* Hide most of the implementation of `struct rb_io`. (#6511)Samuel Williams2023-05-301-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | * Add rb_io_path and rb_io_open_descriptor. * Use rb_io_open_descriptor to create PTY objects * Rename FMODE_PREP -> FMODE_EXTERNAL and expose it FMODE_PREP I believe refers to the concept of a "pre-prepared" file, but FMODE_EXTERNAL is clearer about what the file descriptor represents and aligns with language in the IO::Buffer module. * Ensure that rb_io_open_descriptor closes the FD if it fails If FMODE_EXTERNAL is not set, then it's guaranteed that Ruby will be responsible for closing your file, eventually, if you pass it to rb_io_open_descriptor, even if it raises an exception. * Rename IS_EXTERNAL_FD -> RUBY_IO_EXTERNAL_P * Expose `rb_io_closed_p`. * Add `rb_io_mode` to get IO mode. --------- Co-authored-by: KJ Tsanaktsidis <ktsanaktsidis@zendesk.com>
* 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?