summaryrefslogtreecommitdiff
path: root/io.c
AgeCommit message (Collapse)Author
2017-11-23io.c: read BOM only for readingnobu
* io.c (io_strip_bom): just abandon detecting UTF encoding by BOM unless opened for reading. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60884 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-02io.c: improve docs for the chomp optionstomar
* io.c: [DOC] improve the description for the chomp option and add examples to IO.readlines and IO#readlines; other small fixes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60624 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-29io.c: improve docsstomar
* io.c: [DOC] fix rdoc for some cross references; fix grammar. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-29io.c: docs for IO#writestomar
* io.c: [DOC] fix example and language in IO#write docs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60571 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-29io.c: honor buffered modenobu
* io.c (io_writev): honor buffered mode to get rid of broken pipe error when stdout is redirected to a pipeline. [ruby-core:83578] [Feature #14042] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60535 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-29io.c: convert to string at writevnobu
* io.c (io_fwritev): needs conversion to string before accessing the content, as well as single argument case, not to segfault. [Feature #9323] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-28Add note to close_{read,write} tookazu
when call on closed stream [ci skip] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60530 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-27io.c: fix IO.copy_stream on O_APPEND destination on Linuxnormal
Linux copy_file_range(2) fails with EBADF if the destination FD has O_APPEND set. Preserve existing (Ruby <= 2.4) behavior by falling back to alternative copy mechanisms if this is the case (instead of raising Errno::EBADF). * io.c (nogvl_copy_file_range): do not raise on O_APPEND dst * test/ruby/test_io.rb (test_copy_stream_append): new test [Feature #13867] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60490 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-26common conversion functionsnobu
* array.c (rb_to_array_type): make public to share common code internally. * hash.c (rb_to_hash_type): make public to share common code internally. * symbol.c (rb_to_symbol_type): make public to share common code internally. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-25io.c: let rb_p use writevnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60425 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-25io.c: warn old writenobu
* io.c (rb_io_puts): warn if write method accepts just one argument. [ruby-core:83529] [Feature #14042] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-25io.c: write a newline togethernobu
* io.c (rb_io_puts): write a newline together at once for each argument. based on the patch by rohitpaulk (Rohit Kuruvilla) at [ruby-core:83508]. [Feature #14042] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60417 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-24Update call-seq of ARGF.read_nonblockkazu
ARGF.read_nonblock supports `exception: false' like IO#read_nonblock since 2.3.0. [Feature #11358] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60401 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-23Drop to support NaCl platform.hsbt
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-23io.c: fix infinite retrynobu
* io.c (io_binwritev): fix infinite retry when flushing buffered data. [Feature #9323] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-23io.c: fix buffered outputnobu
* io.c (io_binwritev): append to buffered data, not overwriting. [Feature #9323] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-23io.c: fix totalnobu
* io.c (io_writev): total may be a bignum. [Feature #9323] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60371 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-23io.c: no restrictionnobu
* io.c (io_write_m): remove argc restriction upto IOV_MAX-1. [Feature #9323] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60370 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-22Fix indent and comment [ci skip]kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60352 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-22io.c: fix local variablesnobu
* io.c (io_writev): fix local variable declarations, when writev(2) is not available. [Feature #9323] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60351 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-22Make IO#write accept multiple argumentsglass
io.c: make IO#write accept multiple arguments. it uses writev(2) if possible. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21Add documentation for `chomp` option.hsbt
https://github.com/ruby/ruby/pull/1717 Patch by @ksss [fix GH-1717] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60308 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21Clarify the behavior of IO.write without offset in write mode.hsbt
https://github.com/ruby/ruby/pull/1571 Patch by @takanabe [fix GH-1571] [Bug #11638][ruby-core:71277] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60294 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21io.c: introduce copy offload to IO.copy_streamglass
io.c (rb_io_s_copy_stream): add copy offload feature (by using copy_file_range(2) if available) to IO.copy_stream git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60284 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21[DOC] describe methods used for src and dst argument.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60233 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-18Get rid of shadowing local variablesnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-10io.c: encoding of ARGF.inplace_modenobu
* io.c (argf_next_argv): encode inplace mode suffix to the path encoding. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-10io.c: path name conversion at ARGFnobu
* io.c (argf_next_argv): the standard conversion to path name should take place. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60154 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-05io.c: [DOC] about buffering [ci skip]nobu
* io.c (rb_file_initialize): [DOC] stated that non-tty file is buffered by the default, and added links to related methods. [ruby-core:83081] [Bug #13965] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60121 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-02io.c: check null charnobu
* io.c (ruby_set_inplace_mode): check if null is contained. based on the patch by tommy (Masahiro Tomita) in [ruby-dev:50272]. [Bug #13960] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60097 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-28io.c: fix segfault with closing socket on Windowsshirosaki
* io.c (fptr_finalize_flush): add an argument to keep GVL. * io.c (fptr_finalize): adjust for above change. * io.c (io_close_fptr): closing without GVL causes another exception while raising exception in another thread. This causes segfault on Windows. Keep GVL while closing when another thread raises. [Bug #13856] [ruby-core:82602] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60055 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-31File#path: Raise IOError when a file is O_TMPFILEsorah
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-31io.c: shrink read buffernobu
* io.c (io_setstrbuf): return true if the buffer is newly created. * io.c (io_set_read_length): shrink the read buffer if it is a new object and is too large. [ruby-core:81370] [Bug #13597] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59701 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-14io.c: textmode if newline decoratornobu
* io.c (validate_enc_binmode): newline decorator implies text mode now. [ruby-core:80270] [Bug #13350] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59336 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-23Revert "Allow IO#reopen to take a block"glass
This reverts r59142. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59150 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-22Allow IO#reopen to take a blockglass
* io.c (rb_io_reopen): take a block and ensure the IO closed [Feature #2631] * test/ruby/test_io.rb: add a test * NEWS: add an entry for this change git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-31Improve performance of implicit type conversionwatson1978
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-10adjust styles [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-07io.c (do_fcntl): update max FD for F_DUPFD_CLOEXEC, toonormal
Somebody may pass 1030 (the value of F_DUPFD_CLOEXEC) to IO#fcntl because they copied code from somewhere else. Ensure we know about FDs created that way. * io.c (do_fcntl): update max FD for F_DUPFD_CLOEXEC, too git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58590 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-02nogvl_wait_for_single_fd must wait as its namekosaki
poll(fds, n, 0) mean no timeout and immediately return. If you want to wait something, you need to use -1 instead. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-01Fix typo in documentation [ci skip]kazu
[Fix GH-1599] Author: Liam Sean Brady <liamseanbrady@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-09io.c: ARGF.file returns $stdin instead of STDIN [ci skip]kazu
For example: `ruby -e '$stdin=open(IO::NULL);p [STDIN,$stdin,ARGF.file]'` prints `[#<IO:<STDIN>>, #<File:/dev/null>, #<File:/dev/null>]` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58288 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-03Fix arguments order of IO#pwritekazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58241 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-03Add IO#pread and IO#pwrite methodsnobu
These methods are useful for safe/concurrent file I/O in multi-thread/process environments and also fairly standard nowadays especially in systems supporting pthreads. Based on patches by Avseyev <sergey.avseyev@gmail.com> at [ruby-core:79290]. [Feature #4532] * configure.in: check for pwrite(2). pread() is already used internally for IO.copy_stream. * io.c: implement wrappers for pread(2) and pwrite(2) and expose them in IO. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58240 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-22io.c: [DOC] expand docs for IO#putsstomar
[ruby-core:80081] [Bug #13306] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58062 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-17io.c: improve docsstomar
* io.c: [DOC] improve and harmonize docs for IO#read and ARGF#read; fix invalid example code for IO#read to make it syntax highlighted. * io.c: [DOC] various improvements for docs of IO, ARGF, and Kernel: fix indent to ensure correct code block detection; sync "outbuf" paragraph for {IO,ARGF}#read, {IO,ARGF}#readpartial, and IO#sysread; fix formatting of call-seq's; improve Kernel#open example to use nil?; fix RDoc markup and typos. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-17deduplicate "/", ":" and "\n" stringsnormal
"/" 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-15io.c: [DOC] add missing `$`kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-12io.c: [DOC] IO#puts uses IO#writenaruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57944 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-06io.c: [DOC] open mode can be an integer; fix rdoc syntaxstomar
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57790 b2dd03c8-39d4-4d8f-98ff-823fe69b080e