mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
merge revision(s) r45399,r45400,r46036,r46037: [Backport #416]
vm.c: merge code * vm.c (m_core_hash_from_ary, m_core_hash_merge_ary): merge duplicated code. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@46628 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
370e83b789
commit
09cf452926
3 changed files with 72 additions and 21 deletions
|
@ -214,4 +214,31 @@ class TestBacktrace < Test::Unit::TestCase
|
|||
q << true
|
||||
end
|
||||
end
|
||||
|
||||
def test_core_backtrace_alias
|
||||
obj = BasicObject.new
|
||||
e = assert_raise(NameError) do
|
||||
class << obj
|
||||
alias foo bar
|
||||
end
|
||||
end
|
||||
assert_not_match(/\Acore#/, e.backtrace_locations[0].base_label)
|
||||
end
|
||||
|
||||
def test_core_backtrace_undef
|
||||
obj = BasicObject.new
|
||||
e = assert_raise(NameError) do
|
||||
class << obj
|
||||
undef foo
|
||||
end
|
||||
end
|
||||
assert_not_match(/\Acore#/, e.backtrace_locations[0].base_label)
|
||||
end
|
||||
|
||||
def test_core_backtrace_hash_merge
|
||||
e = assert_raise(TypeError) do
|
||||
{**nil}
|
||||
end
|
||||
assert_not_match(/\Acore#/, e.backtrace_locations[0].base_label)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#define RUBY_VERSION "2.1.2"
|
||||
#define RUBY_RELEASE_DATE "2014-06-30"
|
||||
#define RUBY_PATCHLEVEL 157
|
||||
#define RUBY_RELEASE_DATE "2014-07-01"
|
||||
#define RUBY_PATCHLEVEL 158
|
||||
|
||||
#define RUBY_RELEASE_YEAR 2014
|
||||
#define RUBY_RELEASE_MONTH 6
|
||||
#define RUBY_RELEASE_DAY 30
|
||||
#define RUBY_RELEASE_MONTH 7
|
||||
#define RUBY_RELEASE_DAY 1
|
||||
|
||||
#include "ruby/version.h"
|
||||
|
||||
|
|
58
vm.c
58
vm.c
|
@ -2262,46 +2262,62 @@ m_core_set_postexe(VALUE self)
|
|||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE core_hash_merge_ary(VALUE hash, VALUE ary);
|
||||
static VALUE core_hash_from_ary(VALUE ary);
|
||||
static VALUE core_hash_merge_kwd(int argc, VALUE *argv);
|
||||
|
||||
static VALUE
|
||||
core_hash_merge(VALUE hash, long argc, const VALUE *argv)
|
||||
{
|
||||
long i;
|
||||
|
||||
assert(argc % 2 == 0);
|
||||
for (i=0; i<argc; i+=2) {
|
||||
rb_hash_aset(hash, argv[i], argv[i+1]);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
m_core_hash_from_ary(VALUE self, VALUE ary)
|
||||
{
|
||||
VALUE hash;
|
||||
REWIND_CFP(hash = core_hash_from_ary(ary));
|
||||
return hash;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
core_hash_from_ary(VALUE ary)
|
||||
{
|
||||
VALUE hash = rb_hash_new();
|
||||
int i;
|
||||
|
||||
if (RUBY_DTRACE_HASH_CREATE_ENABLED()) {
|
||||
RUBY_DTRACE_HASH_CREATE(RARRAY_LEN(ary), rb_sourcefile(), rb_sourceline());
|
||||
}
|
||||
|
||||
assert(RARRAY_LEN(ary) % 2 == 0);
|
||||
for (i=0; i<RARRAY_LEN(ary); i+=2) {
|
||||
rb_hash_aset(hash, RARRAY_AREF(ary, i), RARRAY_AREF(ary, i+1));
|
||||
}
|
||||
|
||||
return hash;
|
||||
return core_hash_merge_ary(hash, ary);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
m_core_hash_merge_ary(VALUE self, VALUE hash, VALUE ary)
|
||||
{
|
||||
int i;
|
||||
|
||||
assert(RARRAY_LEN(ary) % 2 == 0);
|
||||
for (i=0; i<RARRAY_LEN(ary); i+=2) {
|
||||
rb_hash_aset(hash, RARRAY_AREF(ary, i), RARRAY_AREF(ary, i+1));
|
||||
}
|
||||
REWIND_CFP(core_hash_merge_ary(hash, ary));
|
||||
return hash;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
core_hash_merge_ary(VALUE hash, VALUE ary)
|
||||
{
|
||||
core_hash_merge(hash, RARRAY_LEN(ary), RARRAY_CONST_PTR(ary));
|
||||
return hash;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
m_core_hash_merge_ptr(int argc, VALUE *argv, VALUE recv)
|
||||
{
|
||||
int i;
|
||||
VALUE hash = argv[0];
|
||||
|
||||
for (i=1; i<argc; i+=2) {
|
||||
rb_hash_aset(hash, argv[i], argv[i+1]);
|
||||
}
|
||||
REWIND_CFP(core_hash_merge(hash, argc-1, argv+1));
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
@ -2333,6 +2349,14 @@ kwcheck_i(VALUE key, VALUE value, VALUE hash)
|
|||
|
||||
static VALUE
|
||||
m_core_hash_merge_kwd(int argc, VALUE *argv, VALUE recv)
|
||||
{
|
||||
VALUE hash;
|
||||
REWIND_CFP(hash = core_hash_merge_kwd(argc, argv));
|
||||
return hash;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
core_hash_merge_kwd(int argc, VALUE *argv)
|
||||
{
|
||||
VALUE hash, kw;
|
||||
rb_check_arity(argc, 1, 2);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue