summaryrefslogtreecommitdiff
path: root/lib/tempfile.rb
AgeCommit message (Collapse)Author
2019-11-18Warn on access/modify of $SAFE, and remove effects of modifying $SAFEJeremy Evans
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. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-09-25Make rb_scan_args handle keywords more similar to Ruby methods (#2460)Jeremy Evans
Cfuncs that use rb_scan_args with the : entry suffer similar keyword argument separation issues that Ruby methods suffer if the cfuncs accept optional or variable arguments. This makes the following changes to : handling. * Treats as **kw, prompting keyword argument separation warnings if called with a positional hash. * Do not look for an option hash if empty keywords are provided. For backwards compatibility, treat an empty keyword splat as a empty mandatory positional hash argument, but emit a a warning, as this behavior will be removed in Ruby 3. The argument number check needs to be moved lower so it can correctly handle an empty positional argument being added. * If the last argument is nil and it is necessary to treat it as an option hash in order to make sure all arguments are processed, continue to treat the last argument as the option hash. Emit a warning in this case, as this behavior will be removed in Ruby 3. * If splitting the keyword hash into two hashes, issue a warning, as we will not be splitting hashes in Ruby 3. * If the keyword argument is required to fill a mandatory positional argument, continue to do so, but emit a warning as this behavior will be going away in Ruby 3. * If keyword arguments are provided and the last argument is not a hash, that indicates something wrong. This can happen if a cfunc is calling rb_scan_args multiple times, and providing arguments that were not passed to it from Ruby. Callers need to switch to the new rb_scan_args_kw function, which allows passing of whether keywords were provided. This commit fixes all warnings caused by the changes above. It switches some function calls to *_kw versions with appropriate kw_splat flags. If delegating arguments, RB_PASS_CALLED_KEYWORDS is used. If creating new arguments, RB_PASS_KEYWORDS is used if the last argument is a hash to be treated as keywords. In open_key_args in io.c, use rb_scan_args_kw. In this case, the arguments provided come from another C function, not Ruby. The last argument may or may not be a hash, so we can't set keyword argument mode. However, if it is a hash, we don't want to warn when treating it as keywords. In Ruby files, make sure to appropriately use keyword splats or literal keywords when calling Cfuncs that now issue keyword argument separation warnings through rb_scan_args. Also, make sure not to pass nil in place of an option hash. Work around Kernel#warn warnings due to problems in the Rubygems override of the method. There is an open pull request to fix these issues in Rubygems, but part of the Rubygems tests for their override fail on ruby-head due to rb_scan_args not recognizing empty keyword splats, which this commit fixes. Implementation wise, adding rb_scan_args_kw is kind of a pain, because rb_scan_args takes a variable number of arguments. In order to not duplicate all the code, the function internals need to be split into two functions taking a va_list, and to avoid passing in a ton of arguments, a single struct argument is used to handle the variables previously local to the function. Notes: Merged-By: jeremyevans <code@jeremyevans.net>
2019-09-06Fix Tempfile.open to correctly pass keywords to Tempfile.newJeremy Evans
Notes: Merged: https://github.com/ruby/ruby/pull/2432
2019-08-30Fix keyword argument separation issues in libJeremy Evans
Mostly requires adding ** in either calls or method definitions. Notes: Merged: https://github.com/ruby/ruby/pull/2395
2019-07-03Try to avoid `not delagated` errorKazuhiro NISHIYAMA
``` .../ruby/lib/delegate.rb:405:in `__getobj__': not delegated (ArgumentError) ``` https://rubyci.org/logs/rubyci.s3.amazonaws.com/debian9/ruby-master/log/20190703T063006Z.fail.html.gz
2018-12-16Enhance Tempfile docs [ci skip]nobu
[ruby-core:90525] [Bug #15411] From: zverok (Victor Shepelev) <zverok.offline@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66415 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-14No document of Tempfile::Remover [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66395 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-12Add uplevel keyword to Kernel#warn and use itshyouhei
If uplevel keyword is given, the warning message is prepended with caller file and line information and the string "warning: ". The use of the uplevel keyword makes Kernel#warn format output similar to how rb_warn formats output. This patch modifies net/ftp and net/imap to use Kernel#warn instead of $stderr.puts or $stderr.printf, since they are used for printing warnings. This makes lib/cgi/core and tempfile use $stderr.puts instead of warn for debug logging, since they are used for debug printing and not for warning. This does not modify bundler, rubygems, or rdoc, as those are maintained outside of ruby and probably wish to remain backwards compatible with older ruby versions. rb_warn_m code is originally from nobu, but I've changed it so that it only includes the path and lineno from uplevel (not the method), and also prepends the string "warning: ", to make it more similar to rb_warn. From: Jeremy Evans code@jeremyevans.net Signed-off-by: Urabe Shyouhei shyouhei@ruby-lang.org git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-17tempfile.rb: [DOC] all arguments [ci skip]nobu
* lib/tempfile.rb (Tempfile.create): mention the other arguments too. [ruby-core:83321] [Misc #14019] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60203 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-16Layout fixes in rdoc of lib/tempfile.rb [ci skip]nobu
RDoc doesn't understand an asterisk inside the plus markers. Moving them out of the markers looks better. [Fix GH-1716] From: Herwin Weststrate <herwinw@herwinw.nl> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60193 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-19tempfile.rb: do not call File.identical? on closed streamnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58794 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-19tempfile.rb: remove in Tempfile.createnobu
* lib/tempfile.rb (Tempfile.create): should not fail even if the temporary file has been removed in the block, just ignore. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58791 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-14Fix bug of Tempfile#size if nothing is written [Bug #13198]glass
* lib/tempfile.rb (Tempfile#size): Fix its behavior when nothing is written. Tempfile#size should return 0 in this case. The patch is from nobu <nobu@ruby-lang.org>. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57972 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-21lib/tempfile.rb: Specify frozen_string_literal: true.kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57389 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-21lib/*: remove closed checksnormal
Follow r56795. Since Ruby 2.2, calling #close on a closed socket no longer raises exceptions. * lib/cgi/session.rb (update): remove closed? check * lib/net/http.rb (finish, transport_request): ditto * lib/net/imap.rb (disconnect): ditto * lib/net/pop.rb (do_start, do_finish): ditto * lib/net/smtp.rb (do_start, do_finish): ditto * lib/open3.rb (popen_run, pipeline_run): ditto * lib/pstore.rb (transaction): ditto * lib/shell/process-controller.rb (sfork): * lib/tempfile (_close, call, Tempfile.create): ditto * lib/webrick/httpauth/htdigest.rb (flush): ditto * lib/webrick/httpauth/htpasswd.rb (flush): ditto * lib/webrick/server.rb (start_thread, cleanup_shutdown_pipe): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-26* lib/tempfile.rb: provide default basename parametersonots
for Tempfile.create. [Feature #11965] Patch by Yuki Kurihara * test/test_tempfile.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56251 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-27Fix doc with default value with GH-523nobu
* lib/tempfile.rb (Tempfile#initialize): [DOC] the first parameter `basename` is optional and defaulted to an empty string since [GH-523]. [Fix GH-1225] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53668 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-16Add frozen_string_literal: false for all filesnaruse
When you change this to true, you may need to add more tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-13* lib/tempfile.rb: Fix typo. [fix GH-933] Patch by @Zorbashhsbt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-30* lib/tempfile.rb (Remover#call): fixed wrong condition introduced atusa
r50682. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50686 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-30* lib/tempfile.rb (Tempfile#initialize): initialize @unlinked to fixusa
test failures introduced at r50682. I hope that check the results of tests before committing, at least the tests about the changed feature. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50684 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-30* lib/tempfile.rb: refactoring.glass
* use warn instead of STDERR.print * remove @tmpname and use @tmpfile.path * introduce @unlinked flag * Remover takes only @tmpfile * mode will be modified just before file reopen git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-04* lib/tempfile.rb: provide default basename parameter.hsbt
[fix GH-523] Patch by @dissolved * test/test_tempfile.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49129 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-21tempfile.rb: fix r47655nobu
* lib/tempfile.rb (Tempfile#initialize, Tempfile.create): get rid of shadowing local variables. * lib/tmpdir.rb (Dir::Tmpname#make_tmpname): simlify argument splitting. * test/test_tempfile.rb: need thread library for ConditionVariable. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47656 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-20* lib/tempfile.rb: define parameters appropriately and someglass
refactoring. * lib/tmpdir.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47655 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-27* lib/tempfile.rb: remove "require 'thread'". its features are noglass
longer used. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47301 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-11lib/tempfile.rb: include doc of Tempfile.opennobu
* lib/tempfile.rb: start rdoc parsing inside singleton class definition to include the document there. [ruby-core:64157] [Bug #10105] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-23* lib/tempfile.rb: split executable code into sample directory.hsbt
* sample/tempfile.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46920 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-27* lib/tempfile.rb (Tempfile#inspect): Show "(closed)" if the tempfileakr
is closed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46191 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-21tempfile.rb: get rid of warningsnobu
* lib/tempfile.rb (Tempfile#initialize): use class method to get rid of warnings when $VERBOSE. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-01tempfile.rb: undefine finalizer on unlinknobu
* lib/tempfile.rb (Tempfile#unlink): finalizer is no longer needed after unlinking. patched by by normalperson (Eric Wong) at [ruby-core:56521] [Bug #8768] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43110 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-19* lib/tempfile.rb: nodoc Tempfile#inspectzzak
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40844 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-20* lib/tempfile.rb (Tempfile.create): Close when the block exits.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40399 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-20* lib/tempfile.rb (Tempfile.create): New method.akr
The method name is proposed by Shugo Maeda. [ruby-dev:47220] [ruby-core:41478] [Feature #5707] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-06* lib/tempfile.rb: fix confusing inspect.glass
previous Tempfile#inspect says it is a File, but actually it is not a File. t = Tempfile.new("foo") #=> #<File:/tmp/foo20121106-31970-1ffbum0> t.is_a? File #=> false now Tempfile#inspect returns like: t = Tempfile.new("foo") #=> #<Tempfile:/tmp/foo20121106-31970-1ffbum0> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-02-01* lib/tempfile.rb (Tempfile#unlink, Tempfile::Remover#call): Justknu
call File.unlink and ignore ENOENT because existence check before unlinking does not help in terms of race condition. * lib/tempfile.rb (Tempfile#unlink, Tempfile::Remover#call): My comment about thread safeness is obsolete. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34413 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-01-09* lib/tempfile.rb (Tempfile#_close): clear @tempfile and @data[1] evennagachika
when an exception is raised at @tempfile.close. [ruby-dev:45113] * lib/tempfile.rb (Tempfile#unlink): fix a typo. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34252 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-12-23* lib/tempfile.rb (Tempfile#initialize): warn if a block is given.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34111 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-12-04* lib/tempfile.rb: don't use lock directory. [ruby-dev:39197]akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-12-04fix a typo.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33942 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-12-04* lib/tempfile.rb (Tempfile::MAX_TRY): remove unused constant.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33941 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-08-26* ext/pathname/lib/pathname.rb: Fix typos and grammar mistakes. Patchdrbrain
by Luke Gruber. [#5203] * ext/pty/lib/expect.rb: ditto * lib/mathn.rb: ditto * lib/net/http.rb: ditto * lib/open-uri.rb: ditto * lib/ostruct.rb: ditto * lib/tempfile.rb: ditto * lib/thread.rb: ditto * lib/weakref.rb: ditto * sample/webrick/httpproxy.rb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33086 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-24* lib/tempfile.rb (Tempfile.{mkdir,rmdir}): revert for backwardnobu
compatibility. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31723 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-24* lib/tempfile.rb (Tempfile.{lock,unlock}_tempfile): refactor.nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31721 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-24* lib/tempfile.rb (Tempfile.{mkdir,rmdir}): internal methods to be ↵nobu
overridden in subclasses. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-19* lib: revert r31635-r31638 and untabify with expand(1).nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31641 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-18 * lib: Convert tabs to spaces for ruby files perdrbrain
http://redmine.ruby-lang.org/projects/ruby/wiki/DeveloperHowto#coding-style Patch by Steve Klabnik [Ruby 1.9 - Bug #4730] Patch by Jason Dew [Ruby 1.9 - Feature #4718] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31635 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-18 * lib/tempfile.rb: Document Dir.mkdir and Dir.rmdir. Patch by Clintondrbrain
Nixon. [Ruby 1.9 - Bug #4728] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31633 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-03-07cancel subversion backfire. sorrymatz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31046 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-03-07* gc.c (rb_gc_set_params): allow GC parameter configuration bymatz
environment variables. based on a patch from funny-falcon at https://gist.github.com/856296, but honors safe level. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e