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

686 Коммитов

Автор SHA1 Сообщение Дата
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