Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 59c7334d0187
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 315e3bf75099
Choose a head ref
  • 3 commits
  • 6 files changed
  • 2 contributors

Commits on Jun 10, 2015

  1. Correct rb_ary_entry declaration

    Closes #3431.
    tamird committed Jun 10, 2015
    Copy the full SHA
    f603bd2 View commit details
  2. Add some capi hash functions

    tamird committed Jun 10, 2015
    Copy the full SHA
    57203b5 View commit details
  3. Merge pull request #3432 from tamird/fix-problems

    Some CAPI fixes
    jemc committed Jun 10, 2015
    Copy the full SHA
    315e3bf View commit details
Showing with 53 additions and 2 deletions.
  1. +20 −0 spec/ruby/optional/capi/ext/hash_spec.c
  2. +2 −0 spec/ruby/optional/capi/ext/rubyspec.h
  3. +15 −0 spec/ruby/optional/capi/hash_spec.rb
  4. +1 −1 vm/capi/array.cpp
  5. +8 −0 vm/capi/hash.cpp
  6. +7 −1 vm/include/capi/ruby/ruby.h
20 changes: 20 additions & 0 deletions spec/ruby/optional/capi/ext/hash_spec.c
Original file line number Diff line number Diff line change
@@ -11,6 +11,18 @@ VALUE hash_spec_rb_hash(VALUE self, VALUE hash) {
}
#endif

#ifdef HAVE_RB_HASH_DUP
VALUE hash_spec_rb_hash_dup(VALUE self, VALUE hash) {
return rb_hash_dup(hash);
}
#endif

#ifdef HAVE_RB_HASH_FREEZE
VALUE hash_spec_rb_hash_freeze(VALUE self, VALUE hash) {
return rb_hash_freeze(hash);
}
#endif

#ifdef HAVE_RB_HASH_AREF
VALUE hash_spec_rb_hash_aref(VALUE self, VALUE hash, VALUE key) {
return rb_hash_aref(hash, key);
@@ -119,6 +131,14 @@ void Init_hash_spec() {
rb_define_method(cls, "rb_hash", hash_spec_rb_hash, 1);
#endif

#ifdef HAVE_RB_HASH_DUP
rb_define_method(cls, "rb_hash_dup", hash_spec_rb_hash_dup, 1);
#endif

#ifdef HAVE_RB_HASH_FREEZE
rb_define_method(cls, "rb_hash_freeze", hash_spec_rb_hash_freeze, 1);
#endif

#ifdef HAVE_RB_HASH_AREF
rb_define_method(cls, "rb_hash_aref", hash_spec_rb_hash_aref, 2);
rb_define_method(cls, "rb_hash_aref_nil", hash_spec_rb_hash_aref_nil, 2);
2 changes: 2 additions & 0 deletions spec/ruby/optional/capi/ext/rubyspec.h
Original file line number Diff line number Diff line change
@@ -318,6 +318,8 @@

/* Hash */
#define HAVE_RB_HASH 1
#define HAVE_RB_HASH_DUP 1
#define HAVE_RB_HASH_FREEZE 1
#define HAVE_RB_HASH_AREF 1
#define HAVE_RB_HASH_ASET 1
#define HAVE_RB_HASH_DELETE 1
15 changes: 15 additions & 0 deletions spec/ruby/optional/capi/hash_spec.rb
Original file line number Diff line number Diff line change
@@ -49,6 +49,21 @@
end
end

describe "rb_hash_dup" do
it "returns a copy of the hash" do
hsh = {}
dup = @s.rb_hash_dup(hsh)
dup.should == hsh
dup.should_not equal(hsh)
end
end

describe "rb_hash_freeze" do
it "freezes the hash" do
@s.rb_hash_freeze({}).frozen?.should be_true
end
end

describe "rb_hash_aref" do
it "returns the value associated with the key" do
hsh = {:chunky => 'bacon'}
2 changes: 1 addition & 1 deletion vm/capi/array.cpp
Original file line number Diff line number Diff line change
@@ -216,7 +216,7 @@ extern "C" {
}

/* @todo Check 64-bit? */
VALUE rb_ary_entry(VALUE self, int index) {
VALUE rb_ary_entry(VALUE self, long index) {
NativeMethodEnvironment* env = NativeMethodEnvironment::get();

Array* array = capi_get_array(env, self);
8 changes: 8 additions & 0 deletions vm/capi/hash.cpp
Original file line number Diff line number Diff line change
@@ -10,6 +10,14 @@ extern "C" {
return capi_fast_call(rb_cHash, rb_intern("new"), 0);
}

VALUE rb_hash_dup(VALUE self) {
return capi_fast_call(self, rb_intern("dup"), 0);
}

VALUE rb_hash_freeze(VALUE self) {
return capi_fast_call(self, rb_intern("freeze"), 0);
}

VALUE rb_hash_aref(VALUE self, VALUE key) {
return capi_fast_call(self, rb_intern("[]"), 1, key);
}
8 changes: 7 additions & 1 deletion vm/include/capi/ruby/ruby.h
Original file line number Diff line number Diff line change
@@ -988,7 +988,7 @@ struct RTypedData {
VALUE rb_ary_dup(VALUE self);

/** Return object at index. Out-of-bounds access returns Qnil. */
VALUE rb_ary_entry(VALUE self, int index);
VALUE rb_ary_entry(VALUE self, long index);

/** Return Qtrue if the array includes the item. */
VALUE rb_ary_includes(VALUE self, VALUE obj);
@@ -1434,6 +1434,12 @@ struct RTypedData {
/** Create a new Hash object */
VALUE rb_hash_new();

/** Duplicate the Hash object */
VALUE rb_hash_dup(VALUE self);

/** Freeze the Hash object */
VALUE rb_hash_freeze(VALUE self);

/** Return the value associated with the key, including default values. */
VALUE rb_hash_aref(VALUE self, VALUE key);