Граф коммитов

883 Коммитов

Автор SHA1 Сообщение Дата
Alan D. Salewski c15cddd1d5 Allow Dir.home to work for non-login procs when $HOME not set
Allow the 'Dir.home' method to reliably locate the user's home directory when
all three of the following are true at the same time:

    1. Ruby is running on a Unix-like OS
    2. The $HOME environment variable is not set
    3. The process is not a descendant of login(1) (or a work-alike)

The prior behavior was that the lookup could only work for login-descended
processes.

This is accomplished by looking up the user's record in the password database
by uid (getpwuid_r(3)) as a fallback to the lookup by name (getpwname_r(3))
which is still attempted first (based on the name, if any, returned by
getlogin_r(3)).

If getlogin_r(3), getpwnam_r(3), and/or getpwuid_r(3) is not available at
compile time, will fallback on using their respective non-*_r() variants:
getlogin(3), getpwnam(3), and/or getpwuid(3).

The rationale for attempting to do the lookup by name prior to doing it by uid
is to accommodate the possibility of multiple login names (each with its own
record in the password database, so each with a potentially different home
directory) being mapped to the same uid (as is explicitly allowed for by
POSIX; see getlogin(3posix)).

Preserves the existing behavior for login-descended processes, and adds the
new capability of having Dir.home being able to find the user's home directory
for non-login-descended processes.

Fixes [Bug #16787]

Related discussion:
    https://bugs.ruby-lang.org/issues/16787
    https://github.com/ruby/ruby/pull/3034
2020-05-23 23:16:28 +09:00
卜部昌平 9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平 d7f4d732c1 sed -i s|ruby/3|ruby/impl|g
This shall fix compile errors.
2020-05-11 09:24:08 +09:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
Nobuyoshi Nakada 67f616c523
Show the deprecated name in the warning
Fixed up a58bbd6a51.
2020-04-07 12:49:33 +09:00
Nobuyoshi Nakada d827c718db
[DOC] Removed RDoc of deprecated methods [ci skip] 2020-04-06 23:06:03 +09:00
Nobuyoshi Nakada a58bbd6a51
Use `rb_warn_deprecated` for `File.exists?` and `Dir.exists?` 2020-04-06 21:43:32 +09:00
卜部昌平 5e22f873ed decouple 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).
2019-12-26 20:45:12 +09:00
NAKAMURA Usaku 204dc3f39f Revert "Should return "." for File.extname("file.") also on Windows"
We want to introduce consistency and better compatibility with unixen,
but the Windows APIs doues not have consistency fundamentally and
we can not found any logical way...

This reverts commit 61aff0cd18.
2019-12-23 11:54:25 +09:00
NAKAMURA Usaku 61aff0cd18 Should return "." for File.extname("file.") also on Windows
But not changes another cases, such as "file.rb."
[Bug #15267]
2019-12-22 02:42:09 +09:00
Nobuyoshi Nakada 04e95f8985 Get rid of infinite recursion at loading transcoder
Disable encoding US-ASCII path to filesystem on Windows too.
[Bug #16392]
2019-12-16 16:16:54 +09:00
Nobuyoshi Nakada 14a17063a1
Fixed stack overflow [Bug #16382]
Get rid of infinite recursion in expanding a load path to the real
path while loading a transcoder.
2019-12-03 08:51:50 +09:00
Jeremy Evans ffd0820ab3 Deprecate taint/trust and related methods, and make the methods no-ops
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.
2019-11-18 01:00:25 +02:00
Jeremy Evans c5c05460ac Warn on access/modify of $SAFE, and remove effects of modifying $SAFE
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.
2019-11-18 01:00:25 +02:00
Nobuyoshi Nakada 4f13927f1f
[DOC] no change on Windows [Bug #15267] [ci skip] 2019-10-17 19:43:10 +09:00
Nobuyoshi Nakada e169ad93f4 Fixed File.extname at a name ending with a dot
File.extname now returns a dot string at a name ending with a dot.
[Bug #15267]
2019-10-17 18:51:51 +09:00
Jeremy Evans 978276a7d9 Update documentation for File#{readable,writable,executable}{,_real}? [ci skip]
Some OS-level security features cause these methods to not return
expected results.  For example fs.protected_regular sysctl on Linux,
or pledge(2)/unveil(2) on OpenBSD.

Fixes [Bug #16002]
2019-10-14 17:43:11 -07:00
Nobuyoshi Nakada 0c6f36668a
Adjusted spaces [ci skip] 2019-09-27 10:20:56 +09:00
David Rodríguez 2a166cfea2 Add `File.absolute_path?` (#2198)
In order to check whether a path is absolute or not in a portable way.

[Feature #15868]
2019-09-05 20:00:50 +09:00
卜部昌平 3df37259d8 drop-in type check for rb_define_singleton_method
We can check the function pointer passed to
rb_define_singleton_method like how we do so in rb_define_method.
Doing so revealed many arity mismatches.
2019-08-29 18:34:09 +09:00
卜部昌平 7bcfd9189a drop-in type check for rb_define_global_function
We can check the function pointer passed to rb_define_global_function
like we do so in rb_define_method.  It turns out that almost anybody
is misunderstanding the API.
2019-08-29 18:34:09 +09:00
Jeremy Evans a50bc9f3c8 Do not always taint the result of File#path
The result should only be tainted if the path given to the method
was tainted.

The code to always taint the result was added in
a4934a42cb (svn revision 4892) in
2003 by matz.  However, the change wasn't mentioned in the
commit message, and it may have been committed by accident.

Skip part of a readline test that uses Reline.  Reline in general
would pass the test, but Reline's test mode doesn't raise a
SecurityError if passing a tainted prompt and $SAFE >= 1. This
was hidden earlier because File#path was always returning a
tainted string.

Fixes [Bug #14485]
2019-07-30 11:55:59 -07:00
Jeremy Evans 6eab49a40a Revert "Do not always taint the result of File#path"
This reverts commit 1a759bfe5d.

This fails on some operating systems.
2019-07-29 12:10:15 -07:00
Jeremy Evans 1a759bfe5d Do not always taint the result of File#path
The result should only be tainted if the path given to the method
was tainted.

The code to always taint the result was added in
a4934a42cb (svn revision 4892) in
2003 by matz.  However, the change wasn't mentioned in the
commit message, and it may have been committed by accident.

Skip part of a readline test that uses Reline.  Reline in general
would pass the test, but Reline's test mode doesn't raise a
SecurityError if passing a tainted prompt and $SAFE >= 1. This
was hidden earlier because File#path was always returning a
tainted string.

Fixes [Bug #14485]
2019-07-29 10:45:14 -07:00
Yusuke Endoh 81fc3becc7 file.c: add a NORETURN declaration for statx_notimplement
clang complains the lack.
2019-07-20 15:43:42 +09:00
git 9987296b8b * expand tabs. 2019-07-14 17:16:35 +09:00
Yusuke Endoh 934e6b2aeb Prefer `rb_error_arity` to `rb_check_arity` when it can be used 2019-07-14 17:16:19 +09:00
Jeremy Evans 142617c8e1 Don't use native realpath(3) on Solaris
CI shows it does work on Solaris 11, but does not work on Solaris
10.  However, until I figure out a good way to differentiate
between Solaris 10 and 11, this should get CI passing on both.
2019-07-01 15:33:13 -07:00
git 93328b5237 * expand tabs. 2019-07-02 04:14:17 +09:00
Jeremy Evans 11c311e36f Use realpath(3) instead of custom realpath implementation if available
This approach is simpler than the previous approach which tries to
emulate realpath(3).  It also performs much better on both Linux and
OpenBSD on the included benchmarks.

By using realpath(3), we can better integrate with system security
features such as OpenBSD's unveil(2) system call.

This does not use realpath(3) on Windows even if it exists, as the
approach for checking for absolute paths does not work for drive
letters.  This can be fixed without too much difficultly, though until
Windows defines realpath(3), there is no need to do so.

For File.realdirpath, where the last element of the path is not
required to exist, fallback to the previous approach, as realpath(3)
on most operating systems requires the whole path be valid (per POSIX),
and the operating systems where this isn't true either plan to conform
to POSIX or may change to conform to POSIX in the future.

glibc realpath(3) does not handle /path/to/file.rb/../other_file.rb
paths, returning ENOTDIR in that case.  Fallback to the previous code
if realpath(3) returns ENOTDIR.

glibc doesn't like realpath(3) usage for paths like /dev/fd/5,
returning ENOENT even though the path may appear to exist in the
filesystem.  If ENOENT is returned and the path exists, then fall
back to the default approach.
2019-07-01 11:46:30 -07:00
Jeremy Evans c8edf70cd2 Update documentation for File.executable{,_real}? to mention Windows issues
Fixes [Bug #15664]
2019-06-17 13:57:43 -07:00
Nobuyoshi Nakada 27a59ca2c8
file.c: fix compile error with MacPorts gcc
With the SDK of Xcode 10.2.1, `API_AVAILABLE` and so on macros are
not defined in <os/availability.h> when using a compiler other
than clang (which has `__has_feature` and `__has_attribute`), but
`__API_AVAILABLE` macro and so on are defined, which are also
defined in <Availability.h>.

I suspect this is a bug of the SDK.
2019-06-08 19:40:55 +09:00
Jeremy Evans a15f7dd1fb
Always mark the string returned by File.realpath as tainted
This string can include elements that were not in either string
passed to File.realpath, even if one of the strings is an
absolute path, due to symlinks:

```ruby
Dir.mkdir('b') unless File.directory?('b')
File.write('b/a', '') unless File.file?('b/a')
File.symlink('b', 'c') unless File.symlink?('c')
path = File.realpath('c/a'.untaint, Dir.pwd.untaint)
path # "/home/testr/ruby/b/a"
path.tainted? # should be true, as 'b' comes from file system
```

[Bug #15803]
2019-04-28 10:47:51 +09:00
glass 0bd50e95f9 file.c: raise NotImplementedError instread of Errno::ENOSYS
[Misc #15615]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67338 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-23 10:41:16 +00:00
nobu 56557ec28a [DOC] fix markups [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-22 11:04:59 +00:00
nobu 23a8183bea Check stx_btime in struct statx
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-24 11:57:18 +00:00
nobu fc90c4ec5d Support File#birthtime on Linux
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67116 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-22 06:01:08 +00:00
nobu 607ecea7c9 Unified rb_file_s_birthtime
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67115 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-22 03:08:38 +00:00
nobu 8b94ce988b Constified
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67108 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-21 07:32:24 +00:00
nobu 936b61d4ac Path for AT_EMPTY_PATH must not be NULL
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-21 07:03:12 +00:00
nobu 7c369b7847 Separate fstatx_without_gvl from statx_without_gvl
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67105 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-21 06:12:13 +00:00
ko1 e487e86e98 fix r67097 with cast
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-20 07:34:05 +00:00
nobu 15a98ab428 Try statx syscall
* 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-20 06:54:23 +00:00
ko1 5e80e9144f revert r67093 because it breaks tests
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67094 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-20 04:27:24 +00:00
nobu 10deba066e Try statx syscall
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67093 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-20 04:02:30 +00:00
svn d3ff564779 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67089 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-19 05:45:00 +00:00
glass 88798f0787 file.c: enable File.birthtime on Linux
enable File.birthtime on Linux if statx(2) is available.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67088 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-19 05:44:53 +00:00
mame dc2e3f1ecf file.c: use correct integer-conversion function
The return value of major() and minor() is unsigned int, not dev_t.
So, UINT2NUM() is a better choice than DEVT2NUM().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65319 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-23 12:23:04 +00:00
aycabta 39a840d084 Document File.{setuid?,setgid?,sticky?} support for IO objects [Bug #13972]
* file.c (rb_file_setuid_p): rdoc for IO object support
  (rb_file_sgid_p): ditto (rb_file_sticky_p): ditto
* NEWS: inform users of new feature
* test/file/test_file_exhaustive.rb (io_open): wrapper for bare IO
  object (test_suid): test for bare IO support (test_sgid): ditto
  (test_sticky): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20 11:47:45 +00:00
stomar af7f9de4b9 array.c, file.c, string.c: [DOC] fix typos
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65185 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-19 21:35:51 +00:00
nobu fa8b08b424 Prefer `rb_fstring_lit` over `rb_fstring_cstr`
The former states explicitly that the argument must be a literal,
and can optimize away `strlen` on all compilers.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-13 09:59:22 +00:00
nobu 081df64083 file.c: chardev is loadable
* file.c (ruby_is_fd_loadable): allow character devices to load,
  e.g., `ruby /dev/null` exits successfully.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63143 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-13 06:26:30 +00:00
nobu 5a53cbe314 file.c: realpath on special symlink
* file.c (realpath_rec): fallback to symlink path when it is
  accessible but the link target is not actual entry on file
  systems.  [ruby-dev:50487] [Bug #14557]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62607 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-28 05:43:53 +00:00
nobu 1daa624d56 file.c: get rid of useless conversion
* file.c (rb_file_s_stat): File.stat does not accept an IO
  object as trying conversion to path name string first.  skip
  conversion to IO and try stat(2) only.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-28 05:17:01 +00:00
nobu 96db72ce38 [DOC] missing docs at toplevel
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-23 02:18:52 +00:00
nobu f0137f05e1 share ruby_null_device
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-06 23:40:19 +00:00
normal 7e669f40be ruby/ruby.h: remove unnecessary exports from C-API
Needlessly exporting can reduce performance locally and increase
binary size.

Increasing the footprint of our C-API larger is also detrimental
to our development as it encourages tighter coupling with our
internals; making it harder for us to preserve compatibility.

If some parts of the core codebase needs access to globals,
internal.h should be used instead of anything in include/ruby/*.

"Urabe, Shyouhei" <shyouhei@ruby-lang.org> wrote:
> On Thu, Jan 18, 2018 at 7:33 PM, Eric Wong <normalperson@yhbt.net> wrote:
> > shyouhei@ruby-lang.org wrote:
> >>   https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61908
> >>
> >>     export rb_mFConst
> >
> > Why are we exporting all these and making the public C-API bigger?
> > If anything, we should make these static.  Thanks.
>
> No concrete reason, except they have already been externed in 2.5.
> These variables had lacked declarations so far, which resulted in their
> visibility to be that of extern. The commit is just confirming the status quo.
>
> I'm not against to turn them into static.

This reverts changes from r61910, r61909, r61908, r61907, and r61906.

* transcode.c (rb_eUndefinedConversionError): make static
  (rb_eInvalidByteSequenceError): ditto
  (rb_eConverterNotFoundError): ditto
* process.c (rb_mProcGID, rb_mProcUid, rb_mProcID_Syscall): ditto
* file.c (rb_mFConst): ditto
* error.c (rb_mWarning, rb_cWarningBuffer): ditto
* enumerator.c (rb_cLazy): ditto
  [Misc #14381]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-24 21:07:14 +00:00
shyouhei de9d264026 there is no guarantee that mode_t is as wide as int
POSIX only defines mode_t to be "an integer typea", and in fact
MacOS defines it to be uint16_t.  We didn't have NUM2USHORT before
so it did not make sense but now that we have it.  Why not check
apptopriately.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61950 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-19 09:12:06 +00:00
nobu 6b5e0bd98c exclude flexible array size with old compilers
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61814 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-14 11:19:18 +00:00
mame 879df66d96 file.c (struct apply_arg): Use FLEX_ARY_LEN
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61807 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-13 12:25:15 +00:00
nobu e9cb552ec9 internal.h: remove dependecy on ruby/encoding.h
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 06:24:11 +00:00
kazu 8279699592 [DOC] Fix indent [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61406 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-22 03:35:52 +00:00
kazu 71749e26a5 [DOC] Remove unmatched parenthesis [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61405 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-22 03:35:46 +00:00
usa 91de3d6539 support 128bit ino on Windows (if available)
* win32/win32.c, include/ruby/win32.h (stati128, rb_{,u,l,ul}stati128): rename
  from stati64ns, change the type of st_ino to 64bit and added st_inohigh.

* dir.c, file.c (stat, lstat): follow above changes.

* file.c (rb_stat_ino): support 128bit ino.

* win32/win32.c (rb_{,u,l,ul}stati128): ditto.
  [Feature #13731]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61096 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-10 17:26:58 +00:00
kazu 378f028077 [DOC] improve rdoc formatting for links [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61014 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-04 12:31:44 +00:00
usa ce7c1c0577 support nanosec file timestamp on newer Windows
Support nanosec file timestamp on Windows 8 or later.
Original patches are written by kubo (Kubo Takehiro).
Windows 7 and earlier also supports nanosec file timestamp, but it's too
accurate than system time.  so, this feature is disabled on such versions.
[Feature #13726]

this change also includes [Misc #13702]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61013 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-04 10:48:30 +00:00
usa 8e7560bbaf support `File.identical?` on ReFS
* file.c (rb_file_idenitical_p): move Windows dependent code to win32/win32.c.

* win32/win32.c (rb_w32_file_identical_p): support ReFS.
  see [Feature #13731] [ruby-dev:50166]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61005 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-04 03:33:48 +00:00
nobu defcaf89dd file.c: File.lutime
* file.c (utime_internal): add File.lutime.  [Feature #4052]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60933 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-29 09:59:20 +00:00
normal 17dd212f00 file: release GVL for access(2) syscalls
Like stat(2), the access(2) syscall may take an indeterminate
amount of time on slow/remote filesystems.

This lets the following methods release the GVL to avoid choking
the entire VM while one thread is stuck on a slow or
non-responsive filesystem:

- File.readable?
- File.readable_real?
- File.writable?
- File.writable_real?
- File.executable?
- File.executable_real?

* file.c (nogvl_eaccess): new function
  (nogvl_access): ditto
  (rb_access): new wrapper function
  (rb_eaccess): release GVL
  (rb_file_readable_real_p): use rb_access
  (rb_file_writable_real_p): ditto
  (rb_file_executable_real_p): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60925 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-28 03:28:35 +00:00
nobu cea5a91163 util.h: remove my_getcwd
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60908 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-26 01:36:33 +00:00
normal 8fb87e43c6 file.c: simplify eaccess(3) callers
This will make future work to release GVL here simpler.

* file.c (rb_eaccess): new function
  (rb_file_readable_p): use rb_eaccess
  (rb_file_writable_p): ditto
  (rb_file_executable_p): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60895 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-24 04:49:05 +00:00
kazu 31b6079e17 Fix a typo
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-21 12:29:52 +00:00
normal b7cbe4e2e3 File.mkfifo releases GVL
mkfifo(3) is subject to the same problems as open(2) on slow
filesystems.  Release the GVL and let the rest of the VM run
while we call mkfifo.

* file.c (nogvl_mkfifo): new function
  (rb_file_s_mkfifo): release GVL

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60861 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-20 02:29:35 +00:00
normal 38e8a979fc file.c (rb_file_s_mkfifo): use mode_t instead of int
mode_t is the correct type for mkfifo(3).  This fixes an
oversight from r60592 which made the same change to several
other functions.

* file.c (rb_file_s_mkfifo): use mode_t instead of int

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60847 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-19 05:23:48 +00:00
normal 3152d68bf3 file.c: fix 64-bit conversion warnings from r60844
* file.c (nogvl_truncate): cast int to VALUE before "void *"
  (rb_file_s_truncate): cast "void *" to VALUE before int

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-19 05:03:22 +00:00
normal 6b58fd54d8 File.readlink and rb_readlink releases GVL
The `readlink' can stall on slow filesystems like `open' and
`read' syscalls.  Release the GVL and let the rest of the VM
function while `readlink' runs.

* file.c (nogvl_readlink): new function
  (readlink_without_gvl): ditto
  (rb_readlink): use readlink_without_gvl

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-19 05:03:17 +00:00
normal 935d29f73c file: File#truncate and File.truncate release GVL
Like IO#write and IO.open, these file operations have
unpredictable performance on slow file systems.  Allow other
threads of the VM to proceed while they are taking place.

* file.c (nogvl_truncate): extract from rb_file_s_truncate
  (rb_file_s_truncate): release GVL
  (nogvl_ftruncate): extract from rb_file_truncate
  (rb_file_truncate): release GVL

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60844 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-18 22:45:11 +00:00
stomar 086015a5cb file.c: improve docs for File#path
* file.c: [DOC] fix grammar in docs for File#path
  and use a stronger description than "inaccurate".

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60706 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-07 20:10:29 +00:00
nobu 2b43825fae file.c: infect from arguments
* file.c (rb_check_realpath_internal): infetct the result with
  arguments, no taint if none are tainted and cwd is not used.
  [ruby-core:83583] [Bug #14060]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60599 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-01 02:22:10 +00:00
ko1 76d4fa8d15 revert r60596 because it cause faulure on TestFile#test_realpath_taintedness
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-01 02:04:02 +00:00
nobu 42727ceb19 file.c: infect from arguments
* file.c (rb_check_realpath_internal): infetct the result with
  arguments, no taint if none are tainted and cwd is not used.
  [ruby-core:83583] [Bug #14060]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-01 01:51:57 +00:00
normal c9d41f6055 use mode_t where applicable (instead of int)
mode_t is the correct type for these syscalls and it can be
easier-to-understand.  It may also help portability to future
platforms and improve type checking.

* dir.c (dir_s_mkdir): use mode_t for mkdir(2)

* file.c (chmod_internal): use mode_t for chmod(2)
  (rb_file_s_chmod): s/int/mode_t/
  (lchmod_internal): ditto, deref pointer as in chmod_internal
  (rb_file_s_lchmod): pass pointer as in rb_file_s_chmod
  (rb_file_s_rename): use mode_t for umask(2)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-31 19:10:19 +00:00
normal 95e1c87014 file.c: fix possible alignment bugs in r60386
* file.c (struct apply_filename): split out from struct apply_arg
* file.c (apply2files): use offsetof for flex array size calculation
* file.c (apply2files): avoid redundant marking with ALLOCV
  [ruby-core:83535]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60408 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-24 23:35:52 +00:00
normal cb9c849af6 file.c: apply2files releases GVL
This means File.chmod, File.lchmod, File.chown, File.lchown,
File.unlink, and File.utime operations on slow filesystems
no longer hold up other threads.

The platform-specific utime_failed changes is compile-tested
using a new UTIME_EINVAL macro

This hurts performance on fast filesystem, but these methods
are unlikely to be performance bottlenecks and (IMHO) avoiding
pathological slowdowns and stalls are more important.

benchmark results:
minimum results in each 3 measurements.
Execution time (sec)
name	trunk	built
file_chmod	0.591	0.801

Speedup ratio: compare with the result of `trunk' (greater is better)
name	built
file_chmod	0.737

* file.c (UTIME_EINVAL): new macro to ease compile-testing
* file.c (struct apply_arg): new struct
* file.c (no_gvl_apply2files): new function
* file.c (apply2files): release GVL
* file.c (chmod_internal): adjust for apply2files changes
* file.c (lchmod_internal): ditto
* file.c (chown_internal): ditto
* file.c (lchown_internal): ditto
* file.c (utime_failed): ditto
* file.c (utime_internal): ditto
* file.c (unlink_internal): ditto
  [ruby-core:83200] [Feature #13996]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60386 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-24 01:20:04 +00:00
hsbt 0e2d2e6a79 Drop to support NaCl platform.
Because NaCl and PNaCl are already sunset status.
  see https://bugs.chromium.org/p/chromium/issues/detail?id=239656#c160

  configure.ac: Patch for this file was provided by @nobu.

  [Feature #14041][ruby-core:83497][fix GH-1726]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-23 05:56:25 +00:00
hsbt 926103a958 Improve docs for `File.delete` exceptions.
https://github.com/ruby/ruby/pull/1505

  Patch by @mrtazz [fix GH-1505]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60274 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 13:49:39 +00:00
nobu 20685cdc85 Get rid of shadowing local variables
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-18 04:35:25 +00:00
nobu 3bd4910cad file.c: ALT_SEPARATOR on cygwin
* file.c (file_alt_separator): define only on DOSISH platforms.
  File::ALT_SEPARATOR is nil on cygwin.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60159 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-11 04:45:08 +00:00
normal fbb3432736 file.c: release GVL around lstat(2)
Like stat(2), lstat(2) can be expensive on slow filesystems and
should not block other threads.  There should be a minor, but
not significant slowdowns in single-threaded performance similar
to benchmarks around the more-portable stat(2):
[ruby-core:83012] [Bug #13941]

* file.c (no_gvl_lstat): new function for rb_thread_call_without_gvl
  (lstat_without_gvl): new wrapper to replace lstat(2) calls
  (rb_file_s_lstat): s/lstat/&_without_gvl/
  (rb_file_lstat): ditto
  (rb_file_symlink_p): ditto
  (rb_file_s_ftype): ditto
  (rb_file_expand_path_internal): ditto
  (realpath_rec): ditto
  [ruby-core:83075] [Feature #13963]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60110 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-03 23:47:53 +00:00
normal 27cced701b file.c: release GVL in File.{setuid?,setgid?,sticky?}
* file.c (check3rdbyte): use rb_stat to release GVL

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60108 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-03 23:47:29 +00:00
ko1 da4f041ea2 use `ra` instead of new variables.
* file.c (rb_file_s_rename): `struct rename_args ra` already has members
  which contain C ptrs. Pointed by MSP-Greg. Thanks!


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60093 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-02 01:57:27 +00:00
ko1 d0566062f9 catch up r60088 for DOSISH.
* file.c (rb_file_s_rename): src and dst are used only on DOSISH env.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60092 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-02 01:22:11 +00:00
normal e552afc30e File#rename releases GVL
rename(2) requires two pathname resolution operations which can
take considerable time on slow filesystems, release the GVL so
operations on other threads may proceed.

On fast, local filesystems, this change results in some slowdown
as shown by the new benchmark.  I consider the performance trade
off acceptable as cases are avoided.

benchmark results:
minimum results in each 3 measurements.
Execution time (sec)
name	trunk	built
file_rename	2.648	2.804

Speedup ratio: compare with the result of `trunk' (greater is better)
name	built
file_rename	0.944

* file.c (no_gvl_rename): new function
  (rb_file_s_rename): release GVL for renames
* benchmark/bm_file_rename.rb: new benchmark

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60088 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-01 21:19:24 +00:00
normal dbb5595649 file.c: remove unnecessary volatile use
For apply2files, all callers use the `path' VALUE for
generating exceptions, so there is no need to guard it.
In realpath_rec, RB_GC_GUARD is already used on link_orig.

In rb_check_realpath_internal, RB_GC_GUARD is necessary and
preferable (see Appendix E. of doc/extension.rdoc)

* file.c (apply2files): remove unnecessary volatile
  (realpath_rec): ditto
  (rb_check_realpath_internal): ditto, and add RB_GC_GUARD

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60081 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-01 01:44:47 +00:00
nobu 66c9d4f55e Release gvl while doing (f)stat
At the moment rb_stat function is blocking. This patch changes the
behaviour to release the gvl while waiting for OS to return from
f(stat).

There is behaviour impact, but not significant (times are for 100000
iterations):

   $ ~/releaseruby_patch/bin/ruby bench.rb
Rehearsal ------------------------------------------------
File.exist?:   0.036412   0.056616   0.093028 (  0.093075)
--------------------------------------- total: 0.093028sec

                   user     system      total        real
File.exist?:   0.042953   0.049783   0.092736 (  0.092804)

   $ ~/releaseruby_no_patch/bin/ruby bench.rb
Rehearsal ------------------------------------------------
File.exist?:   0.056094   0.026293   0.082387 (  0.082389)
--------------------------------------- total: 0.082387sec

                   user     system      total        real
File.exist?:   0.037250   0.046702   0.083952 (  0.083956)

Based on the patch by Wolf <wolf@wolfsden.cz> at [ruby-core:83012],
with using `rb_thread_io_blocking_region` for `fstat`.
[Bug #13941]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60027 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-26 04:13:37 +00:00
nobu 5754f15975 file.c: rb_check_realpath
* file.c (rb_check_realpath): returns real path which has no
  symbolic links.  similar to rb_realpath except for returning
  Qnil if any parts did not exist.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59983 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-21 07:29:16 +00:00
nobu 40d117ae88 file.c: [DOC] separators at dirname and basename
* file.c (rb_file_s_basename, rb_file_s_dirname): [DOC] state
  that trailing separators will be stripped first, like as
  basename(1) and dirname(1).  [ruby-core:82828] [Bug #13908]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59933 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-16 11:50:56 +00:00
sorah 75cda5e22f File#path: Raise IOError when a file is O_TMPFILE
File#path for a file opened with O_TMPFILE has no meaning.

A filepath returned by this method isn't guarranteed about its accuracy,
but files opened with O_TMPFILE are known its recorded path has no
meaning. So let them not to return any pathname.

After a discussion in ruby-core, just returning Qnil makes guessing the
root cause difficult. Instead, this patch makes the method to raise an
error.

Other consideration is calling fnctl(2) on rb_file_path, but it adds a
overhead, and it's difficult to determine O_TMPFILE status  after fd has
been closed.

[Feature #13568]

* io.c(rb_file_open_generic): Set Qnil to fptr->pathv when opening a
  file using O_TMPFILE

* file.c(rb_file_path): Raise IOError when fptr->pathv is Qnil

* file.c(rb_file_path): [DOC] Update for the new behavior

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59704 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-31 11:14:36 +00:00
nobu 4905a62f5b file.c: [DOC] File.mkfifo
* file.c (rb_file_s_mkfifo): enclose rdoc by ifdef so it will be
  generated properly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59443 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-29 12:11:51 +00:00
nobu aac0b43ed5 file.c: realpath in OS path encoding
* dir.c (rb_dir_getwd_ospath): return cwd path in the OS path
  encoding.

* file.c (rb_realpath_internal): work in the OS path encoding

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-08 01:58:44 +00:00
nobu a75bc36dd2 file.c: preserve encoding
* file.c (path_check_0): preserve encoding of path name in warning
  message.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-03 14:40:05 +00:00
nobu 1e1964b8f2 file.c: preserve encoding
* file.c (rb_find_file_safe): preserve encoding of path in
  SecurityError messages.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58996 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-02 03:54:19 +00:00
nobu b9f5cab23a load.c: convert by rb_get_path_check
* load.c (rb_require_internal): convert to path name with the
  given safe level, without setting global safe level.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58987 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-01 13:05:54 +00:00
nobu 31e6dfee6c file.c: rb_check_funcall_default for fallback value
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-01 12:58:02 +00:00
watson1978 d0015e4ac6 Improve performance of implicit type conversion
To convert the object implicitly, it has had two parts in convert_type() which are
  1. lookink up the method's id
  2. calling the method

Seems that strncmp() and strcmp() in convert_type() are slightly heavy to look up
the method's id for type conversion.

This patch will add and use internal APIs (rb_convert_type_with_id, rb_check_convert_type_with_id)
to call the method without looking up the method's id when convert the object.

Array#flatten -> 19 % up
Array#+       ->  3 % up

[ruby-dev:50024] [Bug #13341] [Fix GH-1537]

### Before
       Array#flatten    104.119k (± 1.1%) i/s -    525.690k in   5.049517s
             Array#+      1.993M (± 1.8%) i/s -     10.010M in   5.024258s

### After
       Array#flatten    124.005k (± 1.0%) i/s -    624.240k in   5.034477s
             Array#+      2.058M (± 4.8%) i/s -     10.302M in   5.019328s

### Test Code
require 'benchmark/ips'

class Foo
  def to_ary
    [1,2,3]
  end
end

Benchmark.ips do |x|

  ary = []
  100.times { |i| ary << i }
  array = [ary]

  x.report "Array#flatten" do |i|
    i.times { array.flatten }
  end

  x.report "Array#+" do |i|
    obj = Foo.new
    i.times { array + obj }
  end

end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58978 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-31 12:30:57 +00:00
sorah efd36678e6 [DOC] File#path result can be inaccurate
* file.c(rb_file_path): [DOC] Note that the pathname returned by this
  method can be inaccurate, for instance file gets moved, renamed,
  deleted or is created with File::TMPFILE option.

  Relates to [Feature #13568]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58734 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-15 12:18:55 +00:00
normal 312ac7f0a1 deduplicate File::NULL string
"/dev/null" is a common sight for pre-1.9.3-compatible code
targeting *nix systems, so deduplicate it here, as well.

* file.c (Init_File): use fstring for File::NULL

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57996 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-17 00:55:50 +00:00
normal 05404cba6e deduplicate "/", ":" and "\n" strings
"/" and ":" are always statically registered in symbol.c (Init_op_tbl),
and "\n" is a commonly seen in source code.

* file.c (Init_File): fstring on File::SEPARATOR and File::PATH_SEPARATOR
* io.c (Init_IO): fstring on rb_default_rs ("\n")

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57995 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-17 00:55:45 +00:00
nobu b75f68ab8d file.c: join with /
* file.c (rb_file_join): join using "/" always, not a constant.
  and fix the document.  [ruby-core:79579] [Bug #13223]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57960 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-13 09:29:19 +00:00
nobu 803621f6d7 file.c: refine message
* file.c (rb_get_path_check_convert): refine the error message
  when the path name contains null byte.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57336 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-16 02:43:55 +00:00
nobu 7eb8d74f34 file.c: cygwin behavior
* file.c: recent cygwin hides NTFS specific features.
  [ruby-core:78497] [Bug #13008]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57009 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-07 02:19:29 +00:00
nobu 1f97dd562c file.c: isADS
* file.c (isADS): add macro to tell if Alternate Data Stream
  separator, to distinguish from drive letter.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56996 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-06 07:21:55 +00:00
nobu 6b88dd2698 file.c: home directory from system
* file.c (rb_default_home_dir): resolve home directory from the
  system database when HOME is not set.  [Feature #12695]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56902 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-26 11:37:01 +00:00
naruse 54a6cd84df * file.c (rb_home_dir_of): convert given username into filesystem
encoding. [ruby-core:76682] [Bug #12652]
  patched by Dāvis Mosāns

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56600 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05 15:00:37 +00:00
nobu 6c7024f6f4 file.c: include sys/sysmacros.h
* file.c: include sys/sysmacros.h for ArchLinux which deprecated
  use of major() and minor() in sys/types.h.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56549 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-03 06:02:16 +00:00
nobu 91fbf2b24b file.c: use DEVT2NUM
* file.c (rb_stat_dev_major, rb_stat_dev_minor): use DEVT2NUM as
  well as rdev_major and rdev_minor.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56547 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-03 05:46:55 +00:00
nobu 9e75488ac8 internal.h: RB_OBJ_BUILTIN_TYPE
* internal.h (RB_OBJ_BUILTIN_TYPE): special-const safe
  BUILTIN_TYPE.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56510 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-10-28 06:58:19 +00:00
akr 577de1e93d replace fixnum by integer in documents.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56102 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-08 04:57:49 +00:00
nobu 797f2eda58 file.c: normalize cwd
* file.c (append_fspath): normalize directory name to be appended
  on OS X.  [ruby-core:75957] [Ruby trunk Bug#12483]
  https://github.com/rails/rails/issues/25303#issuecomment-224834804

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55385 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-12 00:24:36 +00:00
nobu f0355ae707 file.c: home dir fall back
* file.c (rb_home_dir_of): return the default home path if the
  user name is the current user name, on platforms where struct
  pwd is not supported.  a temporary measure against
  [Bug #12226].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54947 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-08 09:51:34 +00:00
usa 3e5dc499a8 * win32/win32.c, include/ruby/win32.h (rb_w32_utruncate): implements new
truncate alternative which accepts UTF-8 path.

* file.c (truncate): use above function.
  [Bug #12340]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54889 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-02 14:05:19 +00:00
hsbt 48d22f8360 * file.c, win32/file.c: Removed obsoleted safe level checks.
[fix GH-1327] Patch by @cremno

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54668 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-22 01:43:31 +00:00
nobu 096137e84f file.c: File.empty?
* file.c (Init_File): add alias File.empty? to File.zero?.
  [Feature #9969]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54559 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-13 05:47:49 +00:00
nobu e9bb167bfb file.c: prefer rb_check_arity
* file.c (rb_file_s_expand_path, rb_file_s_absolute_path): use
  rb_check_arity instead of rb_scan_args for a simple optional
  argument.

* file.c (rb_file_s_realpath, rb_file_s_realdirpath): ditto.

* file.c (rb_file_s_basename): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-10 21:59:02 +00:00
nobu e19df562a8 file.c: apply2files returns Fixnum
* file.c (apply2files): return Fixnum so that callers can just
  return it.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54532 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-10 21:59:01 +00:00
nobu 03bf343a9f file.c: apply to argv
* file.c (apply2files): apply to a VALUE vector instead of a
  temporary array.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54530 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-10 21:54:41 +00:00
nobu 3cd3c9d74c no argument conversions in rb_realpath_internal
* file.c (rb_realpath_internal): no argument conversions since
  this internal function does not need to_path and encoding
  conversions, not to be affected by the default internal
  encoding.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-10 08:47:44 +00:00
nobu b14ed1bb5d file.c: simplify rb_file_s_split
* file.c (rb_file_s_split): use rb_file_dirname instead of
  rb_file_s_dirname with unused Qnil.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54171 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-18 06:59:10 +00:00
nobu a4e6f7d707 ruby.c: reduce fstat
* file.c (ruby_is_fd_loadable): now return -1 if loadable but
  may block.
* ruby.c (open_load_file): wait to read by the result of
  ruby_is_fd_loadable, without fstat.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-14 07:03:01 +00:00
headius 4bb6f3fd3b file.c: fix documentation
* file.c: mode is optional, defaults to 0666.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-19 18:42:36 +00:00
nobu f4166e2dd7 prefer rb_syserr_fail
* file.c, io.c, util.c: prefer rb_syserr_fail with saved errno
  over setting errno then call rb_sys_fail, not to be clobbered
  potentially and to reduce thread local errno accesses.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53264 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-23 08:57:48 +00:00
ko1 2f5b8f0529 * *.c (*_memsize): do not check ptr.
NULL checking is finished Before call of memsize functions.
  See r52979.




git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-09 00:38:32 +00:00
nobu 46df9c425e file.c: call get_stat only once
* file.c (rb_stat_wr, rb_stat_ww): call get_stat only once and
  reduce checking struct.  patch by Yuki Kurihara in
  [ruby-core:71949].  [Misc #11789]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52970 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-08 15:52:40 +00:00
nobu 13a935b0ba Drop support for BeOS
* beos: Drop support for BeOS now that Haiku is stable.
  [Fix GH-1112]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52731 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-24 00:17:11 +00:00
nobu e99cc601e0 Add missing punctuation to File docs [ci skip]
* file.c: [DOC] add a missing period to File docs, to terminate
  the sentence and separate from the next sentence.  [Fix GH-1111]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52729 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-24 00:04:36 +00:00
nobu e29c109d2a Haiku now best effort support
* configure.in: remove obsolete workarounds for Haiku.
* dln.c, file.c, io.c: remove obsolete Haiku workarounds.
* thread_pthread.c: add stack bounds detection for Haiku.
* signal.c: get stack pointer from signal context on Haiku.
  [ruby-core:67923] [Bug #10811] [Fix GH-1109]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52721 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-23 03:54:42 +00:00
glass 1a98b567af * file.c: Add O_TMPFILE.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-08 06:26:44 +00:00
hsbt 5fdee2f829 * file.c: fix indent style. [fix GH-977]
* test/ruby/test_string.rb: indent. [fix GH-975]
[ci skip] These patches are contributed from @yui-knk

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-23 07:03:34 +00:00
nobu a3ac9d0bb6 file.c: fix typos
* file.c (rb_file_expand_path_internal): fix typos.
  [ruby-core:71111] [Bug #11601]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-19 12:10:14 +00:00
usa a01dfd479f * file.c (rb_file_identical_p): not necessary to compare the paths after
comparing the file indexes on Windows.  designate by kosaki.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-18 16:29:07 +00:00
nobu 3d7a535440 file.c: fix compile error
* file.c (rb_file_s_rename): remove unmatched endif not removed at
  r52161.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52164 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-18 01:30:47 +00:00
kosaki a857b11ded * file.c (rb_file_identical_p): simplify ifdefs
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52163 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-18 01:19:13 +00:00
kosaki 4ad2057f27 * ChangeLog: Good-bye OS/2.
* common.mk: ditto.
* configure.in: ditto.
* dln_find.c: ditto.
* ext/Setup.emx: ditto.
* ext/extmk.rb: ditto.
* ext/socket/extconf.rb: ditto.
* ext/zlib/extconf.rb: ditto.
* file.c: ditto.
* include/ruby/defines.h: ditto.
* io.c: ditto.
* lib/mkmf.rb: ditto.
* missing/os2.c: ditto.
* process.c: ditto.
* ruby.c: ditto.
* NEWS: announce OS/2 is no longer supported.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52161 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-18 01:18:34 +00:00
kosaki 21704f2269 * file.c (ruby_is_fd_loadable): this should be fail if st_mode is
not regular file nor FIFO.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-18 00:33:44 +00:00
nobu d6379666ca file.c: set errno
* file.c (ruby_is_fd_loadable): set proper errno.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52154 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-17 23:41:14 +00:00
kosaki bc8687acd6 * ruby.c (open_load_file): reset O_NONBLOCK after open.
Even if S_ISREG() is true, the file may be file on FUSE filesystem
  or something. We can't assume O_NONBLOCK is safe.
  Moreover, we should wait if the path is point to FIFO. That's
  FIFO semantics. GVL should be transparent from ruby script.
  Thus, just reopen without O_NONBLOCK for filling the requirements.
  [Bug #11060][Bug #11559]
* ruby.c (loadopen_func): new for the above.
* file.c (ruby_is_fd_loadable): new. for checks loadable file type
  of not.
* file.c (rb_file_load_ok): use ruby_is_fd_loadble()
* internal.h: add ruby_is_fd_loadble()
* common.mk: now, ruby.o depend on thread.h.
* test/ruby/test_require.rb
(TestRequire#test_loading_fifo_threading_success): new test.
  This test successful case that loading from FIFO.
* test/ruby/test_require.rb
(TestRequire#test_loading_fifo_threading_raise): rename from
  test_loading_fifo_threading. You souldn't rescue an exception
  if you test raise or not.
  Moreover, this case should be caught IOError because load(FIFO)
  should be blocked until given any input.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52151 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-17 21:09:10 +00:00
nobu 78baa98e69 string.c: rb_str_cat_conv_enc_opts
* file.c (rb_file_expand_path_internal): concatenate converted
  string to the result instead of making converted string and
  append it.
* string.c (rb_str_cat_conv_enc_opts): from rb_str_conv_enc_opts,
  separate function to concatenate with transcoding.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52147 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-17 04:55:47 +00:00
nobu c72ddc4467 file.c: prefer encoding index as possible
* file.c (rb_str_encode_ospath): prefer encoding index as possible
  until rb_encoding is needed.

* file.c (rb_file_expand_path_internal): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52146 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-17 04:31:43 +00:00
nobu abf832f435 file.c: non-blocking open
* file.c (rb_file_load_ok): open in non-blocking mode withoout
  releasing GVL.  don't care about others than regular files and
  directories.  [ruby-dev:49272] [Bug #11559]
* ruby.c (load_file_internal): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52139 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-16 06:54:38 +00:00
nobu 5f0bb43434 file.c: get rid of intermediate objects
* file.c (rb_str_normalize_ospath): place normalized strings to
  the result string directly, to get rid of intermediate objects
  and copying.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52015 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-04 02:32:08 +00:00