merge revision(s) 46416: [Backport #9942]

	* array.c (rb_ary_permutation): `p` is the array of size `r`, as
	  commented at permute0().  since `n >= r` here, buffer overflow
	  never happened, just reduce unnecessary allocation though.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47331 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
merge revision(s) 46417,46418: [Backport #9939]

	* array.c (yield_indexed_values): extract from permute0(),
	  rpermute0(), and rcombinate0().

	* array.c (rb_ary_combination): iterate on a shared copy, and use
	  array of indexes instead of array of chosen objects.
	  [ruby-core:63149] [Bug #9939]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47332 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
merge revision(s) 46368,46371: [Backport #9913]

	* ext/digest/digest.c (rb_digest_instance_equal):
	  fix #== for non-string arguments. [ruby-core:62967] [Bug #9913]

	* test/digest/test_digest.rb: add test for above.

	* ext/digest/digest.c (rb_digest_instance_equal): no need to call
	  `to_s` twice.  [Bug #9913]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47333 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
merge revision(s) 46344: [Backport #9902]

	* re.c (match_aref): should not ignore name after NUL byte.
	  [ruby-dev:48275] [Bug #9902]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47334 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
merge revision(s) 45144: [Backport #9544]

	* lib/resolv.rb (bind_random_port): Rescue EPERM for FreeBSD which
	  security.mac.portacl.port_high is changed.
	  See mac_portacl(4) for details.
	  Reported by Jakub Szafranski.  [ruby-core:60917] [Bug #9544]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47335 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
merge revision(s) 45720: [Backport #9571]

	* lib/fileutils.rb (rmdir): rescue Errno::EEXIST in addition to
	  ENOTEMPTY (and ENOENT), because SUSv3 describes that "If the
	  directory is not an empty directory, rmdir() shall fail and set
	  errno to [EEXIST] or [ENOTEMPTY]" and Solaris uses EEXIST.
	  [Bug #9571] [ruby-dev:48017]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47336 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
merge revision(s) 45827: [Backport #9618]

	* ext/pathname/lib/pathname.rb (cleanpath_aggressive): make all
	  separators File::SEPARATOR from File::ALT_SEPARATOR.
	  Reported by Daniel Rikowski.
	  Fixed by Nobuyoshi Nakada.  [Bug #9618]

	* ext/pathname/lib/pathname.rb (cleanpath_conservative): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
merge revision(s) 45953,45961: [Backport #9767]

	* lib/test/unit/parallel.rb: fix test-all parallel failure if a test
	  is skipped after raise.
	  DL::TestFunc#test_sinf is skipped after raise on mingw ruby.
	  But it causes Mashal.load failure due to undefined class/module
	  DL::DLError when doing test-all parallel and test-all doesn't
	  complete. We create new MiniTest::Skip object to avoid Mashal.load
	  failure.
	  [ruby-core:62133] [Bug #9767]

	* test/testunit/test_parallel.rb (TestParallel): add a test.

	* test/testunit/tests_for_parallel/ptest_forth.rb: ditto.
	  But it causes Marshal.load failure due to undefined class/module
	  complete. We create new MiniTest::Skip object to avoid Marshal.load


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47338 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
merge revision(s) 46463: [Backport #9957]

	* vm_core.h: add VM_FRAME_MAGIC_RESCUE to recognize normal block or
	  rescue clause.

	* vm.c (vm_exec): use VM_FRAME_MAGIC_RESCUE on at rescue/ensure.

	* test/ruby/test_settracefunc.rb: should not invoke b_return at rescue
	  clause.
	  [Bug #9957]

	* vm_dump.c (control_frame_dump): check VM_FRAME_MAGIC_RESCUE.

	* vm_dump.c (vm_stack_dump_each): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47339 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
merge revision(s) 46471: [Backport #9964]

	* compile.c (rb_iseq_compile_node): put start label of block after
	  trace (b_call).
	  [Bug #9964]

	* test/ruby/test_settracefunc.rb: add a test.
	  added assert_consistent_call_return() method check call/return
	  consistency.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
merge revision(s) 46465,46469,46484: [Backport #9961]

	* vm.c (rb_vm_rewind_cfp): add new function to rewind specified cfp
	  with invoking RUBY_EVENT_C_RETURN.
	  [Bug #9961]

	* vm_core.h: ditto.

	* eval.c (rb_protect): use it.

	* eval.c (rb_rescue2): ditto.

	* vm_eval.c (rb_iterate): ditto.

	* test/ruby/test_settracefunc.rb: add a test.

	* vm_core.h (rb_name_err_mesg_new): 

	* vm_eval.c (rb_catch_protect): fix same problem of [Bug #9961].

	* vm_eval.c (rb_iterate): ditto.

	* vm_core.h (rb_vm_rewind_cfp): add the prototype declaration.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47342 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
merge revision(s) 42251,46345,46346: [Backport #9903]

	* sprintf.c (ruby__sfvextra): add QUOTE flag to escape unprintable
	  characters.

	* sprintf.c (ruby__sfvextra): add QUOTE flag to escape unprintable
	  characters.

	* re.c (match_aref, rb_reg_regsub): consider encoding of captured
	  names, encoding-incompatible should not match.
	  [ruby-dev:48278] [Bug #9903]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
merge revision(s) 46550,46557,46565,46570,46585,46595,46822: [Backport #9977] [Backport #9978] [Backport #9983]

	* hash.c (ruby_setenv): fix memory leak on Windows, free
	  environment strings block after check for the size.
	  [ruby-dev:48323] [Bug #9977]

	* hash.c (env_select): fix memory leak and crash on Windows, make
	  keys array first instead of iterating on envrion directly.
	  [ruby-dev:48325] [Bug #9978]
	  keys array first instead of iterating on environ directly.

	* hash.c (env_shift): fix memory leak on Windows, free environment
	  strings block always.  [ruby-dev:48332] [Bug #9983]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47365 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
merge revision(s) 45676,45677: [Backport #9769]

	stringio.c: move GC guard

	* ext/stringio/stringio.c (strio_write): move GC guard after the
  last using position.
	* ext/stringio/stringio.c (strio_write): use rb_str_append to
	  reuse coderange bits other than ASCII-8BIT, and keep
	  taintedness.  [ruby-dev:48118] [Bug #9769]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47366 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
merge revision(s) 46382,46384,46913: [Backport #9914]

	* io.c (rb_io_advise): AIX currently does not support a 32-bit call to
	  posix_fadvise() if _LARGE_FILES is defined. Patch by Rei Odaira.
	  [ruby-core:62968] [Bug #9914]

	* configure.in (posix_fadvise): disable use of posix_fadvise
	  itself on 32-bit AIX.  [ruby-core:62968] [Bug #9914]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47367 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
merge revision(s) 46151,46165: [Backport #9865]

	* io.c (rb_io_fileno, rb_io_inspect): non-modification does not
	  error on frozen IO.  [ruby-dev:48241] [Bug #9865]

	* io.c (rb_io_autoclose_p): Don't raise on frozen IO.

	* test/lib/minitest/unit.rb: IO#autoclose? may raise IOError.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47368 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
merge revision(s) 46241: [Backport #9875]

	* lib/erb.rb (result): [DOC] no longer accepts a Proc, as
	  Kernel.eval does not.  [fix GH-619]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47369 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
merge revision(s) 46408,46410,46413,46414,46424,46436,46437: [Backport #9934]

	string.c: shrink too big buffer

	* string.c (rb_str_resize): shrink the buffer even if new length
  is same but it is enough smaller than the capacity.
	* file.c (expand_path): shrink expanded path which no longer needs
	  rooms to append.  [ruby-core:63114] [Bug #9934]

	* string.c (rb_str_resize): should consider the capacity instead
	  of the old length, as pointed out by nagachika.

	* string.c (rb_str_resize): update capa only when buffer get
	  reallocated.
	  http://d.hatena.ne.jp/nagachika/20140613/ruby_trunk_changes_46413_46420#r46413


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47399 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
merge r46831 partially.  these changes are from:
https://github.com/k-takata/Onigmo/commit/7abd7b29481f98eb92be786e3d33611fc7d000a0
[Bug #8716]

* include/ruby/oniguruma.h (ONIG_MAX_CAPTURE_GROUP_NUM,
  ONIGERR_TOO_MANY_CAPTURE_GROUPS): add cheking the number of capture
  groups.

* regerror.c (onig_error_code_to_format): ditto.

* regparse.c (scan_env_add_mem_entry): ditto.

* regexec.c (onig_region_copy, match_at): fix: segmation fault occurs
  when many groups are used.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
merge revision(s) 46896-46898: [Backport #10078]

	* string.c (rb_str_count): fix wrong single-byte optimization.
	  7bit ascii can be a trailing byte in Shift_JIS.
	  [ruby-dev:48442] [Bug #10078]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@47401 b2dd03c8-39d4-4d8f-98ff-823fe69b080e