aboutsummaryrefslogtreecommitdiffstats
path: root/file.c
Commit message (Collapse)AuthorAgeFilesLines
* file.c: release GVL around lstat(2)normal2017-10-031-6/+27
| | | | | | | | | | | | | | | | | | | | 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
* file.c: release GVL in File.{setuid?,setgid?,sticky?}normal2017-10-031-3/+1
| | | | | | * 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
* use `ra` instead of new variables.ko12017-10-021-5/+3
| | | | | | | | * 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
* catch up r60088 for DOSISH.ko12017-10-021-0/+2
| | | | | | | * 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
* File#rename releases GVLnormal2017-10-011-4/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | 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
* file.c: remove unnecessary volatile usenormal2017-10-011-4/+6
| | | | | | | | | | | | | | | 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
* Release gvl while doing (f)statnobu2017-09-261-2/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* file.c: rb_check_realpathnobu2017-09-211-18/+59
| | | | | | | | * 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
* file.c: [DOC] separators at dirname and basenamenobu2017-09-161-4/+6
| | | | | | | | * 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
* File#path: Raise IOError when a file is O_TMPFILEsorah2017-08-311-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* file.c: [DOC] File.mkfifonobu2017-07-291-1/+1
| | | | | | | * 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
* file.c: realpath in OS path encodingnobu2017-06-081-10/+24
| | | | | | | | | * 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
* file.c: preserve encodingnobu2017-06-031-3/+3
| | | | | | | * 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
* file.c: preserve encodingnobu2017-06-021-3/+3
| | | | | | | * 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
* load.c: convert by rb_get_path_checknobu2017-06-011-1/+1
| | | | | | | * 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
* file.c: rb_check_funcall_default for fallback valuenobu2017-06-011-4/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Improve performance of implicit type conversionwatson19782017-05-311-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [DOC] File#path result can be inaccuratesorah2017-05-151-0/+3
| | | | | | | | | | * 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
* deduplicate File::NULL stringnormal2017-03-171-1/+1
| | | | | | | | | "/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
* deduplicate "/", ":" and "\n" stringsnormal2017-03-171-2/+2
| | | | | | | | | | "/" 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
* file.c: join with /nobu2017-03-131-23/+13
| | | | | | | * 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
* file.c: refine messagenobu2017-01-161-1/+3
| | | | | | | * 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
* file.c: cygwin behaviornobu2016-12-071-1/+1
| | | | | | | * 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
* file.c: isADSnobu2016-12-061-7/+23
| | | | | | | * 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
* file.c: home directory from systemnobu2016-11-261-1/+21
| | | | | | | * 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
* * file.c (rb_home_dir_of): convert given username into filesystemnaruse2016-11-051-2/+16
| | | | | | | 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
* file.c: include sys/sysmacros.hnobu2016-11-031-0/+4
| | | | | | | * 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
* file.c: use DEVT2NUMnobu2016-11-031-2/+2
| | | | | | | * 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
* internal.h: RB_OBJ_BUILTIN_TYPEnobu2016-10-281-1/+1
| | | | | | | * 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
* replace fixnum by integer in documents.akr2016-09-081-16/+16
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56102 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* file.c: normalize cwdnobu2016-06-121-2/+20
| | | | | | | | * 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
* file.c: home dir fall backnobu2016-05-081-5/+13
| | | | | | | | | * 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
* * win32/win32.c, include/ruby/win32.h (rb_w32_utruncate): implements newusa2016-05-021-0/+2
| | | | | | | | | | 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
* * file.c, win32/file.c: Removed obsoleted safe level checks.hsbt2016-04-221-1/+1
| | | | | | [fix GH-1327] Patch by @cremno git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54668 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* file.c: File.empty?nobu2016-04-131-0/+1
| | | | | | | * 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
* file.c: prefer rb_check_aritynobu2016-04-101-21/+12
| | | | | | | | | | | | * 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
* file.c: apply2files returns Fixnumnobu2016-04-101-21/+9
| | | | | | | * 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
* file.c: apply to argvnobu2016-04-101-31/+28
| | | | | | | * 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
* no argument conversions in rb_realpath_internalnobu2016-04-101-1/+2
| | | | | | | | | * 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
* file.c: simplify rb_file_s_splitnobu2016-03-181-1/+1
| | | | | | | * 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
* ruby.c: reduce fstatnobu2016-03-141-1/+2
| | | | | | | | | * 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
* file.c: fix documentationheadius2016-01-191-1/+1
| | | | | | * 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
* prefer rb_syserr_failnobu2015-12-231-19/+28
| | | | | | | | * 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
* * *.c (*_memsize): do not check ptr.ko12015-12-091-1/+1
| | | | | | | | | | 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
* file.c: call get_stat only oncenobu2015-12-081-4/+6
| | | | | | | | * 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
* Drop support for BeOSnobu2015-11-241-27/+0
| | | | | | | * 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
* Add missing punctuation to File docs [ci skip]nobu2015-11-241-1/+1
| | | | | | | * 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
* Haiku now best effort supportnobu2015-11-231-2/+2
| | | | | | | | | | * 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
* * file.c: Add O_TMPFILE.glass2015-11-081-0/+4
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * file.c: fix indent style. [fix GH-977]hsbt2015-10-231-1/+1
| | | | | | | * 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